mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 17:53:06 +00:00
Optimize coset in compute_evaluation
This commit is contained in:
parent
d27dd92af9
commit
417e6055ae
@ -40,14 +40,23 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let coset_start = self.mul(start, x);
|
||||
|
||||
// The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta.
|
||||
let points = g
|
||||
let g_powers = g
|
||||
.powers()
|
||||
.map(|y| {
|
||||
let yt = self.constant(y);
|
||||
self.mul(coset_start, yt)
|
||||
})
|
||||
.zip(evals)
|
||||
.take(arity)
|
||||
.map(|y| self.constant(y))
|
||||
.collect::<Vec<_>>();
|
||||
let mut coset = Vec::new();
|
||||
for i in 0..arity / 2 {
|
||||
let res = self.mul_two(
|
||||
coset_start,
|
||||
g_powers[2 * i],
|
||||
coset_start,
|
||||
g_powers[2 * i + 1],
|
||||
);
|
||||
coset.push(res.0);
|
||||
coset.push(res.1);
|
||||
}
|
||||
let points = coset.into_iter().zip(evals).collect::<Vec<_>>();
|
||||
|
||||
self.interpolate(&points, beta)
|
||||
}
|
||||
|
||||
@ -86,6 +86,16 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
self.arithmetic(F::ONE, x, y, F::ZERO, x)
|
||||
}
|
||||
|
||||
/// Computes `x * y`.
|
||||
pub fn mul_two(&mut self, a0: Target, b0: Target, a1: Target, b1: Target) -> (Target, Target) {
|
||||
let a0_ext = self.convert_to_ext(a0);
|
||||
let b0_ext = self.convert_to_ext(b0);
|
||||
let a1_ext = self.convert_to_ext(a1);
|
||||
let b1_ext = self.convert_to_ext(b1);
|
||||
let res = self.mul_two_extension(a0_ext, b0_ext, a1_ext, b1_ext);
|
||||
(res.0 .0[0], res.1 .0[0])
|
||||
}
|
||||
|
||||
/// Multiply `n` `Target`s with `ceil(n/2) + 1` `ArithmeticExtensionGate`s.
|
||||
pub fn mul_many(&mut self, terms: &[Target]) -> Target {
|
||||
let terms_ext = terms
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user