Skip to content

Commit bded134

Browse files
Optimize poly division (#985)
* reproduce issue * implement suggestion from issue * refactor --------- Co-authored-by: jotabulacios <[email protected]>
1 parent e3debf3 commit bded134

File tree

1 file changed

+6
-2
lines changed
  • crates/math/src/polynomial

1 file changed

+6
-2
lines changed

crates/math/src/polynomial/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,12 @@ impl<F: IsField> Polynomial<FieldElement<F>> {
248248
Polynomial::new(&[FieldElement::zero()])
249249
} else {
250250
for i in 0..=factor.degree() {
251-
for j in 0..=self.degree() {
252-
coefficients[i + j] += &factor.coefficients[i] * &self.coefficients[j];
251+
if factor.coefficients[i] != FieldElement::zero() {
252+
for j in 0..=self.degree() {
253+
if self.coefficients[j] != FieldElement::zero() {
254+
coefficients[i + j] += &factor.coefficients[i] * &self.coefficients[j];
255+
}
256+
}
253257
}
254258
}
255259
Polynomial::new(&coefficients)

0 commit comments

Comments
 (0)