Skip to content

Commit 20ca153

Browse files
authored
perf: use horner's method in eval dense polynomial (#171)
1 parent db578c6 commit 20ca153

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/poly/polynomial/univariate/dense.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ impl<F: PrimeField> DensePolynomialVar<F> {
2626
/// the result. Caution for use in holographic lincheck: The output has
2727
/// 2 entries in one matrix
2828
pub fn evaluate(&self, point: &FpVar<F>) -> Result<FpVar<F>, SynthesisError> {
29-
let mut result: FpVar<F> = FpVar::zero();
30-
// current power of point
31-
let mut curr_pow_x: FpVar<F> = FpVar::one();
32-
for i in 0..self.coeffs.len() {
33-
let term = &curr_pow_x * &self.coeffs[i];
34-
result += &term;
35-
curr_pow_x *= point;
36-
}
37-
38-
Ok(result)
29+
// Horner's Method
30+
Ok(self
31+
.coeffs
32+
.iter()
33+
.rfold(FpVar::zero(), move |acc, coeff| acc * point + coeff))
3934
}
4035
}
4136

0 commit comments

Comments
 (0)