Skip to content

Commit

Permalink
Update formatted expressions (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson authored Jan 7, 2025
1 parent 95def20 commit af5475c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
18 changes: 9 additions & 9 deletions crates/prover/src/constraint_framework/expr/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,23 @@ mod tests {
fn test_expr_evaluator() {
let test_struct = TestStruct {};
let eval = test_struct.evaluate(ExprEvaluator::new(16, false));
let expected = "let intermediate0 = (col_1_1[0]) * (col_1_2[0]);
let expected = "let intermediate0 = (trace_1_column_1_offset_0) * (trace_1_column_2_offset_0);
\
let intermediate1 = (TestRelation_alpha0) * (col_1_0[0]) \
+ (TestRelation_alpha1) * (col_1_1[0]) \
+ (TestRelation_alpha2) * (col_1_2[0]) \
let intermediate1 = (TestRelation_alpha0) * (trace_1_column_0_offset_0) \
+ (TestRelation_alpha1) * (trace_1_column_1_offset_0) \
+ (TestRelation_alpha2) * (trace_1_column_2_offset_0) \
- (TestRelation_z);
\
let constraint_0 = ((col_1_0[0]) * (intermediate0)) * (1 / (col_1_0[0] + col_1_1[0]));
let constraint_0 = ((trace_1_column_0_offset_0) * (intermediate0)) * (1 / (trace_1_column_0_offset_0 + trace_1_column_1_offset_0));
\
let constraint_1 = (SecureCol(col_2_3[0], col_2_4[0], col_2_5[0], col_2_6[0]) \
- (SecureCol(col_2_3[-1], col_2_4[-1], col_2_5[-1], col_2_6[-1]) \
- ((total_sum) * (preprocessed.is_first)))) \
let constraint_1 = (QM31Impl::from_partial_evals([trace_2_column_3_offset_0, trace_2_column_4_offset_0, trace_2_column_5_offset_0, trace_2_column_6_offset_0]) \
- (QM31Impl::from_partial_evals([trace_2_column_3_offset_neg_1, trace_2_column_4_offset_neg_1, trace_2_column_5_offset_neg_1, trace_2_column_6_offset_neg_1]) \
- ((total_sum) * (preprocessed_is_first)))) \
* (intermediate1) \
- (1);"
- (qm31(1, 0, 0, 0));"
.to_string();

assert_eq!(eval.format_constraints(), expected);
Expand Down
23 changes: 12 additions & 11 deletions crates/prover/src/constraint_framework/expr/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ impl BaseExpr {
offset,
}) => {
let offset_str = if *offset == CLAIMED_SUM_DUMMY_OFFSET as isize {
"claimed_sum_offset".to_string()
"claimed_sum".to_string()
} else {
offset.to_string()
let offset_abs = offset.abs();
if *offset >= 0 {
offset.to_string()
} else {
format!("neg_{offset_abs}")
}
};
format!("col_{interaction}_{idx}[{offset_str}]")
format!("trace_{interaction}_column_{idx}_offset_{offset_str}")
}
BaseExpr::Const(c) => c.to_string(),
BaseExpr::Const(c) => format!("m31({c}).into()"),
BaseExpr::Param(v) => v.to_string(),
BaseExpr::Add(a, b) => format!("{} + {}", a.format_expr(), b.format_expr()),
BaseExpr::Sub(a, b) => format!("{} - ({})", a.format_expr(), b.format_expr()),
Expand All @@ -38,7 +43,7 @@ impl ExtExpr {
a.format_expr()
} else {
format!(
"SecureCol({}, {}, {}, {})",
"QM31Impl::from_partial_evals([{}, {}, {}, {}])",
a.format_expr(),
b.format_expr(),
c.format_expr(),
Expand All @@ -47,12 +52,8 @@ impl ExtExpr {
}
}
ExtExpr::Const(c) => {
if c.0 .1.is_zero() && c.1 .0.is_zero() && c.1 .1.is_zero() {
// If the constant is in the base field, display it as such.
c.0 .0.to_string()
} else {
c.to_string()
}
let [v0, v1, v2, v3] = c.to_m31_array();
format!("qm31({v0}, {v1}, {v2}, {v3})")
}
ExtExpr::Param(v) => v.to_string(),
ExtExpr::Add(a, b) => format!("{} + {}", a.format_expr(), b.format_expr()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ pub enum PreprocessedColumn {
impl PreprocessedColumn {
pub const fn name(&self) -> &'static str {
match self {
PreprocessedColumn::IsFirst(_) => "preprocessed.is_first",
PreprocessedColumn::Plonk(_) => "preprocessed.plonk",
PreprocessedColumn::Seq(_) => "preprocessed.seq",
PreprocessedColumn::XorTable(..) => "preprocessed.xor_table",
PreprocessedColumn::IsFirst(_) => "preprocessed_is_first",
PreprocessedColumn::Plonk(_) => "preprocessed_plonk",
PreprocessedColumn::Seq(_) => "preprocessed_seq",
PreprocessedColumn::XorTable(..) => "preprocessed_xor_table",
}
}

Expand Down
28 changes: 14 additions & 14 deletions crates/prover/src/examples/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,28 +358,28 @@ mod tests {
);

let eval = component.evaluate(ExprEvaluator::new(log_n_rows, true));
let expected = "let intermediate0 = (StateMachineElements_alpha0) * (col_1_0[0]) \
+ (StateMachineElements_alpha1) * (col_1_1[0]) \
let expected = "let intermediate0 = (StateMachineElements_alpha0) * (trace_1_column_0_offset_0) \
+ (StateMachineElements_alpha1) * (trace_1_column_1_offset_0) \
- (StateMachineElements_z);
\
let intermediate1 = (StateMachineElements_alpha0) * (col_1_0[0] + 1) \
+ (StateMachineElements_alpha1) * (col_1_1[0]) \
let intermediate1 = (StateMachineElements_alpha0) * (trace_1_column_0_offset_0 + m31(1).into()) \
+ (StateMachineElements_alpha1) * (trace_1_column_1_offset_0) \
- (StateMachineElements_z);
\
let constraint_0 = (SecureCol(\
col_2_2[claimed_sum_offset], \
col_2_3[claimed_sum_offset], \
col_2_4[claimed_sum_offset], \
col_2_5[claimed_sum_offset]\
) - (claimed_sum)) \
* (preprocessed.is_first);
let constraint_0 = (QM31Impl::from_partial_evals([\
trace_2_column_2_offset_claimed_sum, \
trace_2_column_3_offset_claimed_sum, \
trace_2_column_4_offset_claimed_sum, \
trace_2_column_5_offset_claimed_sum\
]) - (claimed_sum)) \
* (preprocessed_is_first);
\
let constraint_1 = (SecureCol(col_2_2[0], col_2_3[0], col_2_4[0], col_2_5[0]) \
- (SecureCol(col_2_2[-1], col_2_3[-1], col_2_4[-1], col_2_5[-1]) \
- ((total_sum) * (preprocessed.is_first)))\
let constraint_1 = (QM31Impl::from_partial_evals([trace_2_column_2_offset_0, trace_2_column_3_offset_0, trace_2_column_4_offset_0, trace_2_column_5_offset_0]) \
- (QM31Impl::from_partial_evals([trace_2_column_2_offset_neg_1, trace_2_column_3_offset_neg_1, trace_2_column_4_offset_neg_1, trace_2_column_5_offset_neg_1]) \
- ((total_sum) * (preprocessed_is_first)))\
) \
* ((intermediate0) * (intermediate1)) \
- (intermediate1 - (intermediate0));"
Expand Down

0 comments on commit af5475c

Please sign in to comment.