Skip to content

Commit

Permalink
Fixing a problem with the use of integer division and ===, <== operat…
Browse files Browse the repository at this point in the history
…ors. If an integer division is involved in the expression of one of these operators, then we consider the expression as no quadratic.
  • Loading branch information
Miguel Isabel Márquez authored and Miguel Isabel Márquez committed Jan 16, 2023
1 parent 7015e32 commit 93fc176
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions circom_algebra/src/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,6 @@ impl<C: Default + Clone + Display + Hash + Eq> ArithmeticExpression<C> {
debug_assert!(ArithmeticExpression::valid_hashmap_for_expression(coefficients));
Result::Ok(())
}
fn idivide_coefficients_by_constant(
constant: &BigInt,
coefficients: &mut HashMap<C, BigInt>,
field: &BigInt,
) -> Result<(), ArithmeticError> {
debug_assert!(ArithmeticExpression::valid_hashmap_for_expression(coefficients));
for value in coefficients.values_mut() {
*value = modular_arithmetic::idiv(value, constant, field)?;
}
debug_assert!(ArithmeticExpression::valid_hashmap_for_expression(coefficients));
Result::Ok(())
}

pub fn add(
left: &ArithmeticExpression<C>,
Expand Down Expand Up @@ -519,39 +507,6 @@ impl<C: Default + Clone + Display + Hash + Eq> ArithmeticExpression<C> {
let value = modular_arithmetic::idiv(value_0, value_1, field)?;
Result::Ok(Number { value })
}
(Signal { symbol }, Number { value }) => {
let mut coefficients = HashMap::new();
ArithmeticExpression::initialize_hashmap_for_expression(&mut coefficients);
ArithmeticExpression::add_symbol_to_coefficients(
symbol,
&BigInt::from(1),
&mut coefficients,
field,
);
ArithmeticExpression::idivide_coefficients_by_constant(
value,
&mut coefficients,
field,
)?;
Result::Ok(Linear { coefficients })
}
(Linear { coefficients }, Number { value }) => {
let mut coefficients = coefficients.clone();
ArithmeticExpression::idivide_coefficients_by_constant(
value,
&mut coefficients,
field,
)?;
Result::Ok(Linear { coefficients })
}
(Quadratic { a, b, c }, Number { value }) => {
let mut a = a.clone();
let b = b.clone();
let mut c = c.clone();
ArithmeticExpression::idivide_coefficients_by_constant(value, &mut a, field)?;
ArithmeticExpression::idivide_coefficients_by_constant(value, &mut c, field)?;
Result::Ok(Quadratic { a, b, c })
}
_ => Result::Ok(NonQuadratic),
}
}
Expand Down

0 comments on commit 93fc176

Please sign in to comment.