diff --git a/crypto/math/src/polynomial.rs b/crypto/math/src/polynomial.rs index b7aeba73..ac220408 100644 --- a/crypto/math/src/polynomial.rs +++ b/crypto/math/src/polynomial.rs @@ -250,55 +250,6 @@ impl ops::Neg for Polynomial> { } } -// impl Sub -impl ops::Sub<&Polynomial>> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, substrahend: &Polynomial>) -> Polynomial> { - self + (-substrahend) - } -} - -impl ops::Sub>> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, substrahend: Polynomial>) -> Polynomial> { - &self - &substrahend - } -} - -impl ops::Sub<&Polynomial>> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, substrahend: &Polynomial>) -> Polynomial> { - &self - substrahend - } -} - -impl ops::Sub>> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, substrahend: Polynomial>) -> Polynomial> { - self - &substrahend - } -} - impl ops::Mul<&Polynomial>> for &Polynomial> { type Output = Polynomial>; fn mul(self, factor: &Polynomial>) -> Polynomial> { @@ -327,210 +278,6 @@ impl ops::Mul<&Polynomial>> for Polynomial ops::Mul> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: FieldElement) -> Polynomial> { - let new_coefficients = self - .coefficients - .iter() - .map(|value| &multiplicand * value) - .collect(); - Polynomial { - coefficients: new_coefficients, - } - } -} - -impl ops::Mul<&FieldElement> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: &FieldElement) -> Polynomial> { - self.clone() * multiplicand.clone() - } -} - -impl ops::Mul> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: FieldElement) -> Polynomial> { - self * &multiplicand - } -} - -impl ops::Mul<&FieldElement> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: &FieldElement) -> Polynomial> { - &self * multiplicand - } -} - -/* Multiplication field element at right */ -impl ops::Mul<&Polynomial>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: &Polynomial>) -> Polynomial> { - multiplicand * self - } -} - -impl ops::Mul>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: Polynomial>) -> Polynomial> { - &multiplicand * self - } -} - -impl ops::Mul<&Polynomial>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: &Polynomial>) -> Polynomial> { - multiplicand * self - } -} - -impl ops::Mul>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn mul(self, multiplicand: Polynomial>) -> Polynomial> { - &multiplicand * &self - } -} - -/* Addition field element at left */ -impl ops::Add<&FieldElement> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: &FieldElement) -> Polynomial> { - Polynomial::new_monomial(other.clone(), 0) + self - } -} - -impl ops::Add> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: FieldElement) -> Polynomial> { - &self + &other - } -} - -impl ops::Add> for &Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: FieldElement) -> Polynomial> { - self + &other - } -} - -impl ops::Add<&FieldElement> for Polynomial> -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: &FieldElement) -> Polynomial> { - &self + other - } -} - -/* Addition field element at right */ -impl ops::Add<&Polynomial>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: &Polynomial>) -> Polynomial> { - Polynomial::new_monomial(self.clone(), 0) + other - } -} - -impl ops::Add>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: Polynomial>) -> Polynomial> { - &self + &other - } -} - -impl ops::Add>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: Polynomial>) -> Polynomial> { - self + &other - } -} - -impl ops::Add<&Polynomial>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn add(self, other: &Polynomial>) -> Polynomial> { - &self + other - } -} - /* Substraction field element at left */ impl ops::Sub<&FieldElement> for &Polynomial> where @@ -580,55 +327,6 @@ where } } -/* Substraction field element at right */ -impl ops::Sub<&Polynomial>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, other: &Polynomial>) -> Polynomial> { - Polynomial::new_monomial(self.clone(), 0) - other - } -} - -impl ops::Sub>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, other: Polynomial>) -> Polynomial> { - &self - &other - } -} - -impl ops::Sub>> for &FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, other: Polynomial>) -> Polynomial> { - self - &other - } -} - -impl ops::Sub<&Polynomial>> for FieldElement -where - L: IsField, - F: IsSubFieldOf, -{ - type Output = Polynomial>; - - fn sub(self, other: &Polynomial>) -> Polynomial> { - &self - other - } -} - #[derive(Debug)] pub enum InterpolateError { UnequalLengths(usize, usize), diff --git a/crypto/math/src/tests/polynomial_tests.rs b/crypto/math/src/tests/polynomial_tests.rs index ca1bfde2..06e667b9 100644 --- a/crypto/math/src/tests/polynomial_tests.rs +++ b/crypto/math/src/tests/polynomial_tests.rs @@ -116,10 +116,6 @@ mod tests { Polynomial::new(&[FE::new(4), FE::new(6), FE::new(8)]) } - fn polynomial_b_minus_a() -> Polynomial { - Polynomial::new(&[FE::new(2), FE::new(2), FE::new(2)]) - } - #[test] fn adding_a_and_b_equals_a_plus_b() { assert_eq!(polynomial_a() + polynomial_b(), polynomial_a_plus_b()); @@ -160,19 +156,6 @@ mod tests { assert_ne!(-polynomial_a(), polynomial_a()); } - #[test] - fn substracting_5_5_gives_0() { - let p1 = Polynomial::new(&[FE::new(5)]); - let p2 = Polynomial::new(&[FE::new(5)]); - let p3 = Polynomial::new(&[FE::new(0)]); - assert_eq!(p1 - p2, p3); - } - - #[test] - fn substracting_b_and_a_equals_b_minus_a() { - assert_eq!(polynomial_b() - polynomial_a(), polynomial_b_minus_a()); - } - #[test] fn constructor_removes_zeros_at_the_end_of_polynomial() { let p1 = Polynomial::new(&[FE::new(3), FE::new(4), FE::new(0)]);