From db1ef913e03b3e3ccf1f478e4666b296fde1ba20 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Tue, 8 Jun 2021 10:08:17 -0700 Subject: [PATCH] Remove quartic_quartic --- src/field/extension_field/mod.rs | 1 - src/field/extension_field/quartic.rs | 7 +- src/field/extension_field/quartic_quartic.rs | 259 ------------------- src/gadgets/polynomial.rs | 2 - src/gates/interpolation.rs | 10 - 5 files changed, 1 insertion(+), 278 deletions(-) delete mode 100644 src/field/extension_field/quartic_quartic.rs diff --git a/src/field/extension_field/mod.rs b/src/field/extension_field/mod.rs index c5510ea1..60d2b2e1 100644 --- a/src/field/extension_field/mod.rs +++ b/src/field/extension_field/mod.rs @@ -3,7 +3,6 @@ use crate::field::field::Field; pub mod algebra; pub mod quadratic; pub mod quartic; -mod quartic_quartic; pub mod target; /// Optimal extension field trait. diff --git a/src/field/extension_field/quartic.rs b/src/field/extension_field/quartic.rs index 6bd8ac55..2acac183 100644 --- a/src/field/extension_field/quartic.rs +++ b/src/field/extension_field/quartic.rs @@ -6,8 +6,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssi use rand::Rng; use crate::field::crandall_field::CrandallField; -use crate::field::extension_field::quartic_quartic::QuarticQuarticCrandallField; -use crate::field::extension_field::{Extendable, FieldExtension, OEF}; +use crate::field::extension_field::{FieldExtension, OEF}; use crate::field::field::Field; /// A quartic extension of `CrandallField`. @@ -239,10 +238,6 @@ impl DivAssign for QuarticCrandallField { } } -impl Extendable<4> for QuarticCrandallField { - type Extension = QuarticQuarticCrandallField; -} - #[cfg(test)] mod tests { use crate::field::extension_field::quartic::QuarticCrandallField; diff --git a/src/field/extension_field/quartic_quartic.rs b/src/field/extension_field/quartic_quartic.rs deleted file mode 100644 index 62fad962..00000000 --- a/src/field/extension_field/quartic_quartic.rs +++ /dev/null @@ -1,259 +0,0 @@ -use crate::field::crandall_field::CrandallField; -use crate::field::extension_field::quartic::QuarticCrandallField; -use crate::field::extension_field::{FieldExtension, OEF}; -use crate::field::field::Field; -use rand::Rng; -use std::fmt::{Debug, Display, Formatter}; -use std::hash::Hash; -use std::iter::{Product, Sum}; -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; - -/// A quartic extension of `QuarticCrandallField`. -#[derive(Copy, Clone, Eq, PartialEq, Hash)] -pub struct QuarticQuarticCrandallField(pub(crate) [QuarticCrandallField; 4]); - -impl OEF<4> for QuarticQuarticCrandallField { - // Verifiable in Sage with - // p = 2^64 - 9 * 2^28 + 1 - // F = GF(p) - // PR_F. = PolynomialRing(F) - // assert (x^4 - 3).is_irreducible() - // F4. = F.extension(x^4 - 3) - // PR_F4. = PolynomialRing(F4) - // assert (x^4 - y).is_irreducible() - // F44. = F4.extension(x^4 - y) - const W: QuarticCrandallField = QuarticCrandallField([ - CrandallField(0), - CrandallField(1), - CrandallField(0), - CrandallField(0), - ]); -} - -impl FieldExtension<4> for QuarticQuarticCrandallField { - type BaseField = QuarticCrandallField; - - fn to_basefield_array(&self) -> [Self::BaseField; 4] { - self.0 - } - - fn from_basefield_array(arr: [Self::BaseField; 4]) -> Self { - Self(arr) - } - - fn from_basefield(x: Self::BaseField) -> Self { - x.into() - } -} - -impl From<>::BaseField> for QuarticQuarticCrandallField { - fn from(x: >::BaseField) -> Self { - Self([ - x, - >::BaseField::ZERO, - >::BaseField::ZERO, - >::BaseField::ZERO, - ]) - } -} - -impl Field for QuarticQuarticCrandallField { - const ZERO: Self = Self([QuarticCrandallField::ZERO; 4]); - const ONE: Self = Self([ - QuarticCrandallField::ONE, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - ]); - const TWO: Self = Self([ - QuarticCrandallField::TWO, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - ]); - const NEG_ONE: Self = Self([ - QuarticCrandallField::NEG_ONE, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - ]); - - // Does not fit in 64-bits. - const ORDER: u64 = 0; - const TWO_ADICITY: usize = 32; - const MULTIPLICATIVE_GROUP_GENERATOR: Self = Self([ - QuarticCrandallField([ - CrandallField(7562951059982399618), - CrandallField(16734862117167184487), - CrandallField(8532193866847630013), - CrandallField(15462716295551021898), - ]), - QuarticCrandallField([ - CrandallField(16143979237658148445), - CrandallField(12004617499933809221), - CrandallField(11826153143854535879), - CrandallField(14780824604953232397), - ]), - QuarticCrandallField([ - CrandallField(12779077039546101185), - CrandallField(15745975127331074164), - CrandallField(4297791107105154033), - CrandallField(5966855376644799108), - ]), - QuarticCrandallField([ - CrandallField(1942992936904935291), - CrandallField(6041097781717465159), - CrandallField(16875726992388585780), - CrandallField(17742746479895474446), - ]), - ]); - const POWER_OF_TWO_GENERATOR: Self = Self([ - QuarticCrandallField::ZERO, - QuarticCrandallField([ - CrandallField::ZERO, - CrandallField::ZERO, - CrandallField::ZERO, - CrandallField(6809469153480715254), - ]), - QuarticCrandallField::ZERO, - QuarticCrandallField::ZERO, - ]); - - fn try_inverse(&self) -> Option { - todo!() - } - - fn to_canonical_u64(&self) -> u64 { - panic!("Doesn't fit!") - } - - fn from_canonical_u64(n: u64) -> Self { - >::BaseField::from_canonical_u64(n).into() - } - - fn rand_from_rng(rng: &mut R) -> Self { - Self([ - >::BaseField::rand_from_rng(rng), - >::BaseField::rand_from_rng(rng), - >::BaseField::rand_from_rng(rng), - >::BaseField::rand_from_rng(rng), - ]) - } -} - -impl Display for QuarticQuarticCrandallField { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "({}) + ({})*b + ({})*b^2 + ({})*b^3", - self.0[0], self.0[1], self.0[2], self.0[3] - ) - } -} - -impl Debug for QuarticQuarticCrandallField { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(self, f) - } -} - -impl Neg for QuarticQuarticCrandallField { - type Output = Self; - - #[inline] - fn neg(self) -> Self { - Self([-self.0[0], -self.0[1], -self.0[2], -self.0[3]]) - } -} - -impl Add for QuarticQuarticCrandallField { - type Output = Self; - - #[inline] - fn add(self, rhs: Self) -> Self { - Self([ - self.0[0] + rhs.0[0], - self.0[1] + rhs.0[1], - self.0[2] + rhs.0[2], - self.0[3] + rhs.0[3], - ]) - } -} - -impl AddAssign for QuarticQuarticCrandallField { - fn add_assign(&mut self, rhs: Self) { - *self = *self + rhs; - } -} - -impl Sum for QuarticQuarticCrandallField { - fn sum>(iter: I) -> Self { - iter.fold(Self::ZERO, |acc, x| acc + x) - } -} - -impl Sub for QuarticQuarticCrandallField { - type Output = Self; - - #[inline] - fn sub(self, rhs: Self) -> Self { - Self([ - self.0[0] - rhs.0[0], - self.0[1] - rhs.0[1], - self.0[2] - rhs.0[2], - self.0[3] - rhs.0[3], - ]) - } -} - -impl SubAssign for QuarticQuarticCrandallField { - #[inline] - fn sub_assign(&mut self, rhs: Self) { - *self = *self - rhs; - } -} - -impl Mul for QuarticQuarticCrandallField { - type Output = Self; - - #[inline] - fn mul(self, rhs: Self) -> Self { - let Self([a0, a1, a2, a3]) = self; - let Self([b0, b1, b2, b3]) = rhs; - - let c0 = a0 * b0 + >::W * (a1 * b3 + a2 * b2 + a3 * b1); - let c1 = a0 * b1 + a1 * b0 + >::W * (a2 * b3 + a3 * b2); - let c2 = a0 * b2 + a1 * b1 + a2 * b0 + >::W * a3 * b3; - let c3 = a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - - Self([c0, c1, c2, c3]) - } -} - -impl MulAssign for QuarticQuarticCrandallField { - #[inline] - fn mul_assign(&mut self, rhs: Self) { - *self = *self * rhs; - } -} - -impl Product for QuarticQuarticCrandallField { - fn product>(iter: I) -> Self { - iter.fold(Self::ONE, |acc, x| acc * x) - } -} - -impl Div for QuarticQuarticCrandallField { - type Output = Self; - - #[allow(clippy::suspicious_arithmetic_impl)] - fn div(self, rhs: Self) -> Self::Output { - self * rhs.inverse() - } -} - -impl DivAssign for QuarticQuarticCrandallField { - fn div_assign(&mut self, rhs: Self) { - *self = *self / rhs; - } -} diff --git a/src/gadgets/polynomial.rs b/src/gadgets/polynomial.rs index 1723a9bf..543be834 100644 --- a/src/gadgets/polynomial.rs +++ b/src/gadgets/polynomial.rs @@ -43,7 +43,6 @@ impl PolynomialCoeffsExtAlgebraTarget { ) -> ExtensionAlgebraTarget where F: Extendable, - F::Extension: Extendable, { let mut acc = builder.zero_ext_algebra(); for &c in self.0.iter().rev() { @@ -60,7 +59,6 @@ impl PolynomialCoeffsExtAlgebraTarget { ) -> ExtensionAlgebraTarget where F: Extendable, - F::Extension: Extendable, { let mut acc = builder.zero_ext_algebra(); for &c in self.0.iter().rev() { diff --git a/src/gates/interpolation.rs b/src/gates/interpolation.rs index 3f3ed8d7..d2412967 100644 --- a/src/gates/interpolation.rs +++ b/src/gates/interpolation.rs @@ -22,16 +22,12 @@ use crate::witness::PartialWitness; /// given point. #[derive(Clone, Debug)] pub(crate) struct InterpolationGate, const D: usize> -where - F::Extension: Extendable, { num_points: usize, _phantom: PhantomData, } impl, const D: usize> InterpolationGate -where - F::Extension: Extendable, { pub fn new(num_points: usize) -> GateRef { let gate = Self { @@ -100,8 +96,6 @@ where } impl, const D: usize> Gate for InterpolationGate -where - F::Extension: Extendable, { fn id(&self) -> String { format!("{:?}", self, D) @@ -200,8 +194,6 @@ where } struct InterpolationGenerator, const D: usize> -where - F::Extension: Extendable, { gate_index: usize, gate: InterpolationGate, @@ -209,8 +201,6 @@ where } impl, const D: usize> SimpleGenerator for InterpolationGenerator -where - F::Extension: Extendable, { fn dependencies(&self) -> Vec { let local_target = |input| {