mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-05 23:33:07 +00:00
Remove restriction to binary-only multiplicities (#1577)
This commit is contained in:
parent
d48ce9cf88
commit
ca362ee3d0
@ -9,7 +9,7 @@ use core::iter::repeat;
|
|||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use plonky2::field::batch_util::batch_add_inplace;
|
use plonky2::field::batch_util::{batch_add_inplace, batch_multiply_inplace};
|
||||||
use plonky2::field::extension::{Extendable, FieldExtension};
|
use plonky2::field::extension::{Extendable, FieldExtension};
|
||||||
use plonky2::field::packed::PackedField;
|
use plonky2::field::packed::PackedField;
|
||||||
use plonky2::field::polynomial::PolynomialValues;
|
use plonky2::field::polynomial::PolynomialValues;
|
||||||
@ -761,79 +761,35 @@ pub(crate) fn get_helper_cols<F: Field>(
|
|||||||
.len()
|
.len()
|
||||||
.div_ceil(constraint_degree.checked_sub(1).unwrap_or(1));
|
.div_ceil(constraint_degree.checked_sub(1).unwrap_or(1));
|
||||||
|
|
||||||
let mut helper_columns = Vec::with_capacity(num_helper_columns);
|
let chunks = columns_filters.chunks(constraint_degree.checked_sub(1).unwrap_or(1));
|
||||||
|
let helper_columns: Vec<_> = chunks
|
||||||
for mut cols_filts in &columns_filters
|
.filter_map(|cols_filts| {
|
||||||
.iter()
|
cols_filts
|
||||||
.chunks(constraint_degree.checked_sub(1).unwrap_or(1))
|
.iter()
|
||||||
{
|
.map(|(col, filter)| {
|
||||||
let (first_col, first_filter) = cols_filts.next().unwrap();
|
let combined = (0..degree)
|
||||||
|
.map(|d| {
|
||||||
let mut filter_col = Vec::with_capacity(degree);
|
let evals = col
|
||||||
let first_combined = (0..degree)
|
.iter()
|
||||||
.map(|d| {
|
.map(|c| c.eval_table(trace, d))
|
||||||
let f = {
|
.collect::<Vec<F>>();
|
||||||
let f = first_filter.eval_table(trace, d);
|
challenge.combine(&evals)
|
||||||
filter_col.push(f);
|
})
|
||||||
f
|
|
||||||
};
|
|
||||||
if f.is_one() {
|
|
||||||
let evals = first_col
|
|
||||||
.iter()
|
|
||||||
.map(|c| c.eval_table(trace, d))
|
|
||||||
.collect::<Vec<F>>();
|
.collect::<Vec<F>>();
|
||||||
challenge.combine(evals.iter())
|
|
||||||
} else {
|
|
||||||
assert_eq!(f, F::ZERO, "Non-binary filter?");
|
|
||||||
// Dummy value. Cannot be zero since it will be batch-inverted.
|
|
||||||
F::ONE
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<F>>();
|
|
||||||
|
|
||||||
let mut acc = F::batch_multiplicative_inverse(&first_combined);
|
let mut combined = F::batch_multiplicative_inverse(&combined);
|
||||||
for d in 0..degree {
|
let filter_col: Vec<_> =
|
||||||
if filter_col[d].is_zero() {
|
(0..degree).map(|d| filter.eval_table(trace, d)).collect();
|
||||||
acc[d] = F::ZERO;
|
batch_multiply_inplace(&mut combined, &filter_col);
|
||||||
}
|
combined
|
||||||
}
|
|
||||||
|
|
||||||
for (col, filt) in cols_filts {
|
|
||||||
let mut filter_col = Vec::with_capacity(degree);
|
|
||||||
let mut combined = (0..degree)
|
|
||||||
.map(|d| {
|
|
||||||
let f = {
|
|
||||||
let f = filt.eval_table(trace, d);
|
|
||||||
filter_col.push(f);
|
|
||||||
f
|
|
||||||
};
|
|
||||||
if f.is_one() {
|
|
||||||
let evals = col
|
|
||||||
.iter()
|
|
||||||
.map(|c| c.eval_table(trace, d))
|
|
||||||
.collect::<Vec<F>>();
|
|
||||||
challenge.combine(evals.iter())
|
|
||||||
} else {
|
|
||||||
assert_eq!(f, F::ZERO, "Non-binary filter?");
|
|
||||||
// Dummy value. Cannot be zero since it will be batch-inverted.
|
|
||||||
F::ONE
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<F>>();
|
.reduce(|mut acc, combined| {
|
||||||
|
batch_add_inplace(&mut acc, &combined);
|
||||||
combined = F::batch_multiplicative_inverse(&combined);
|
acc
|
||||||
|
})
|
||||||
for d in 0..degree {
|
.map(PolynomialValues::from)
|
||||||
if filter_col[d].is_zero() {
|
})
|
||||||
combined[d] = F::ZERO;
|
.collect();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
batch_add_inplace(&mut acc, &combined);
|
|
||||||
}
|
|
||||||
|
|
||||||
helper_columns.push(acc.into());
|
|
||||||
}
|
|
||||||
assert_eq!(helper_columns.len(), num_helper_columns);
|
assert_eq!(helper_columns.len(), num_helper_columns);
|
||||||
|
|
||||||
helper_columns
|
helper_columns
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user