Skip to content

Commit

Permalink
PIL LogUp implementation: Generate multiplicity column (#2042)
Browse files Browse the repository at this point in the history
No need to have the user create the multiplicity column anymore.
  • Loading branch information
georgwiese authored Nov 6, 2024
1 parent 4a2ca27 commit b8cfbca
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion executor/src/witgen/machines/fixed_lookup_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<T: FieldElement> IndexedColumns<T> {
}
}

const MULTIPLICITY_LOOKUP_COLUMN: &str = "m_logup_multiplicity";
const MULTIPLICITY_LOOKUP_COLUMN: &str = "multiplicities";

/// Machine to perform a lookup in fixed columns only.
pub struct FixedLookup<'a, T: FieldElement> {
Expand Down
4 changes: 3 additions & 1 deletion executor/src/witgen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ impl<'a, 'b, T: FieldElement> WitnessGenerator<'a, 'b, T> {
.filter(|(symbol, _)| symbol.stage.unwrap_or_default() <= self.stage.into())
.flat_map(|(p, _)| p.array_elements())
.map(|(name, _id)| {
let column = columns.remove(&name).unwrap();
let column = columns
.remove(&name)
.unwrap_or_else(|| panic!("No machine generated witness for column: {name}"));
assert!(!column.is_empty());
(name, column)
})
Expand Down
2 changes: 1 addition & 1 deletion pipeline/tests/powdr_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn lookup_via_challenges() {
}

#[test]
#[should_panic = "Failed to merge the first and last row of the VM 'Main Machine'"]
#[should_panic = "No machine generated witness for column: main::multiplicities"]
fn lookup_via_challenges_range_constraint() {
// This test currently fails, because witness generation for the multiplicity column
// does not yet work for range constraints, so the lookup constraints are not satisfied.
Expand Down
8 changes: 3 additions & 5 deletions std/protocols/lookup.asm
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ let compute_next_z: Fp2<expr>, Fp2<expr>, Fp2<expr>, Constr, expr -> fe[] = quer
/// Use this function if the backend does not support lookup constraints natively.
/// WARNING: This function can currently not be used multiple times since
/// the used challenges would overlap.
/// TODO: Implement this for an array of constraints.
/// Arguments:
/// - lookup_constraint: The lookup constraint
/// - multiplicities: A multiplicities column which shows how many times each row of the RHS value appears in the LHS
let lookup: Constr, expr -> () = constr |lookup_constraint, multiplicities| {
/// TODO: Implement this for an array of constraints.
let lookup: Constr -> () = constr |lookup_constraint| {
std::check::assert(required_extension_size() <= 2, || "Invalid extension size");
// Alpha is used to compress the LHS and RHS arrays.
let alpha = fp2_from_array(array::new(required_extension_size(), |i| challenge(0, i + 1)));
Expand All @@ -75,6 +72,7 @@ let lookup: Constr, expr -> () = constr |lookup_constraint, multiplicities| {

let lhs_denom = sub_ext(beta, fingerprint(lhs, alpha));
let rhs_denom = sub_ext(beta, fingerprint(rhs, alpha));
let multiplicities;
let m_ext = from_base(multiplicities);

let acc = array::new(required_extension_size(), |i| std::prover::new_witness_col_at_stage("acc", 1));
Expand Down
10 changes: 1 addition & 9 deletions test_data/std/lookup_via_challenges.asm
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,5 @@ machine Main with degree: 8 {
col fixed INC_X = [1, 2, 3, 4, 5, 6, 7, 8];
col fixed INC_Y = [2, 3, 4, 5, 6, 7, 8, 9];

// Machine extractor currently accepts the multiplicity column with exact the name of "m_logup_multiplicity"
col witness m_logup_multiplicity;

// This would be the correct multiplicity values that would satisfy the constraints:
//col fixed m_logup_multiplicity = [1, 2, 1, 1, 1, 2, 0, 0];

let lookup_constraint = [x, y] in [INC_X, INC_Y];

lookup(lookup_constraint, m_logup_multiplicity);
lookup([x, y] in [INC_X, INC_Y]);
}
5 changes: 2 additions & 3 deletions test_data/std/lookup_via_challenges_range_constraint.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ machine Main with degree: 8 {

col fixed BIT3 = [0, 1, 2, 3, 4, 5, 6, 7];

col witness m_low, m_high;
lookup([x_low] in [BIT3], m_low);
lookup([x_high] in [BIT3], m_high);
lookup([x_low] in [BIT3]);
lookup([x_high] in [BIT3]);

x = x_low + 8 * x_high;
}

0 comments on commit b8cfbca

Please sign in to comment.