Skip to content

Commit

Permalink
Enforce that a field value is on the rhs of a multiplication/addition
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Jan 3, 2024
1 parent a1733e2 commit 4021408
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bberg/src/relation_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,21 @@ fn craft_expression<T: FieldElement>(

let degree = std::cmp::max(ld, rd);
match op {
AlgebraicBinaryOperator::Add => (degree, format!("({} + {})", lhs, rhs)),
AlgebraicBinaryOperator::Add => match lhe.as_ref() {
// BBerg hack, we do not want a field on the lhs of an expression
Expression::Number(_) => (degree, format!("({} + {})", rhs, lhs)),
_ => (degree, format!("({} + {})", lhs, rhs)),
},
AlgebraicBinaryOperator::Sub => match lhe.as_ref() {
// BBerg hack, we do not want a field on the lhs of an expression
Expression::Number(_) => (degree, format!("(-{} + {})", rhs, lhs)),
_ => (degree, format!("({} - {})", lhs, rhs)),
},

AlgebraicBinaryOperator::Mul => (ld + rd, format!("({} * {})", lhs, rhs)),
AlgebraicBinaryOperator::Mul => match lhe.as_ref() {
// BBerg hack, we do not want a field on the lhs of an expression
Expression::Number(_) => (ld + rd, format!("({} * {})", rhs, lhs)),
_ => (ld + rd, format!("({} * {})", lhs, rhs)),
},
_ => unimplemented!("{:?}", expr),
}
}
Expand Down

0 comments on commit 4021408

Please sign in to comment.