proof-systems icon indicating copy to clipboard operation
proof-systems copied to clipboard

factor our honer's polynomial evaluation

Open mimoo opened this issue 3 years ago • 6 comments

We use honer all over the place when we compute a polynomial

f(x) = c0 + x c1 + x^2 c2 + x^3 c3

as

x ( x (x (c3) + c2) + c1) + c0 

For example:

some_iterator.fold(F::zero(), |acc, x| joint_combiner.clone() * acc + x.clone())

it'd be good to factor this out as a helper in o1-utils like that:

fn evaluate_poly<F>(coefficients: Iter<Item=F>, zero: F, x: F) -> F where F: Add {
  coefficients.fold(zero, |acc, coeff| x * acc + coeff)
}

or

fn evaluate_poly<F>(polynomial: DensePolynomial, zero: F, x:F) -> F where F: Add {
  polynomial.coeffs.fold(zero, |acc, coeff| x * acc + coeff)
}

I'm not sure exactly where it is used in the codebase, but I've seen plenty of implementations written in different ways

mimoo avatar Mar 18 '22 22:03 mimoo

cc @Trivo25 that could be nice to add to the module you created :)

mimoo avatar Mar 18 '22 22:03 mimoo

will do! Was looking for some functions to add to the math lib already as well ;)

Trivo25 avatar Mar 18 '22 22:03 Trivo25

Stale issue message

github-actions[bot] avatar May 18 '22 07:05 github-actions[bot]

This issue should be about using this instead now:

DensePolynomial::<F>::from_coefficients_slice(&coeffs).evaluate(x);

mimoo avatar May 24 '22 21:05 mimoo

Stale issue message

github-actions[bot] avatar Jul 24 '22 07:07 github-actions[bot]

Stale issue message

github-actions[bot] avatar Sep 24 '22 07:09 github-actions[bot]

Stale issue message

github-actions[bot] avatar Nov 26 '22 07:11 github-actions[bot]

@mimoo @mrmr1993 Can you please check the PR #876 which I created for this issue? I could not find any other horner implementation in the repo, except for utils::DensePolynomial. All other evaluations in the repo are using either of DensePolynomial::from_coefficients_slice() or DensePolynomial::from_coefficients_vec() of arkworks::ark_poly crate.

duguorong009 avatar Nov 26 '22 16:11 duguorong009

thanks @duguorong009 !

mimoo avatar Nov 28 '22 18:11 mimoo