mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 17:23:08 +00:00
Use only one gate for div
This commit is contained in:
parent
ff68b66bbb
commit
8e6c30dc70
@ -550,8 +550,19 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
x: ExtensionTarget<D>,
|
||||
y: ExtensionTarget<D>,
|
||||
) -> ExtensionTarget<D> {
|
||||
let y_inv = self.inverse_extension(y);
|
||||
self.mul_extension(x, y_inv)
|
||||
let inv = self.add_virtual_extension_target();
|
||||
let one = self.one_extension();
|
||||
self.add_generator(QuotientGeneratorExtension {
|
||||
numerator: one,
|
||||
denominator: y,
|
||||
quotient: inv,
|
||||
});
|
||||
|
||||
// Enforce that x times its purported inverse equals 1.
|
||||
let (y_inv, res) = self.mul_two_extension(y, inv, x, inv);
|
||||
self.assert_equal_extension(y_inv, one);
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
/// Computes `q = x / y` by witnessing `q` and requiring that `q * y = x`. This can be unsafe in
|
||||
|
||||
@ -16,8 +16,17 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
// b0 -> b1
|
||||
// x -> a1 + (x-a0)*(b1-a1)/(b0-a0)
|
||||
|
||||
let x_m_a0 = self.sub_extension(evaluation_point, interpolation_points[0].0);
|
||||
let b1_m_a1 = self.sub_extension(interpolation_points[1].1, interpolation_points[0].1);
|
||||
let one = self.one_extension();
|
||||
let (x_m_a0, b1_m_a1) = self.double_arithmetic_extension(
|
||||
F::ONE,
|
||||
F::NEG_ONE,
|
||||
one,
|
||||
evaluation_point,
|
||||
interpolation_points[0].0,
|
||||
one,
|
||||
interpolation_points[1].1,
|
||||
interpolation_points[0].1,
|
||||
);
|
||||
let b0_m_a0 = self.sub_extension(interpolation_points[1].0, interpolation_points[0].0);
|
||||
let quotient = self.div_extension(b1_m_a1, b0_m_a0);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user