From f30ec8f93f47974cda4775ebc3e7665b36296fb1 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 2 May 2023 08:44:01 +0100 Subject: [PATCH] feat: filter out zero-coefficient terms in `Expression` multiplication --- acir/src/native_types/expression/operators.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/acir/src/native_types/expression/operators.rs b/acir/src/native_types/expression/operators.rs index 9db5c88fa..6636efdb1 100644 --- a/acir/src/native_types/expression/operators.rs +++ b/acir/src/native_types/expression/operators.rs @@ -195,12 +195,18 @@ impl Mul<&Expression> for &Expression { } while i1 < self.linear_combinations.len() { let (a_c, a_w) = self.linear_combinations[i1]; - output.linear_combinations.push((rhs.q_c * a_c, a_w)); + let coeff = rhs.q_c * a_c; + if !coeff.is_zero() { + output.linear_combinations.push((a_c, a_w)); + } i1 += 1; } while i2 < rhs.linear_combinations.len() { let (b_c, b_w) = rhs.linear_combinations[i2]; - output.linear_combinations.push((self.q_c * b_c, b_w)); + let coeff = self.q_c * b_c; + if !coeff.is_zero() { + output.linear_combinations.push((coeff, b_w)); + } i2 += 1; }