From 5453622d4a345913e57773fa5f7e88757be82495 Mon Sep 17 00:00:00 2001 From: WilfriedM01 Date: Mon, 18 Mar 2024 19:31:34 +0100 Subject: [PATCH 1/2] Add substraction function --- baby-stark/src/polynomial.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/baby-stark/src/polynomial.rs b/baby-stark/src/polynomial.rs index da6184f..ec197a2 100644 --- a/baby-stark/src/polynomial.rs +++ b/baby-stark/src/polynomial.rs @@ -56,5 +56,8 @@ impl Polynomial { } + pub fn __sub__(self, other : Polynomial) -> Polynomial{ + self.__add__(other.__neg__()) + } } From 2c53ece1353641ff41c4038ee6e3e51635989e36 Mon Sep 17 00:00:00 2001 From: WilfriedM01 Date: Mon, 18 Mar 2024 19:36:34 +0100 Subject: [PATCH 2/2] Add multiplication function --- baby-stark/src/polynomial.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/baby-stark/src/polynomial.rs b/baby-stark/src/polynomial.rs index ec197a2..35cf2d9 100644 --- a/baby-stark/src/polynomial.rs +++ b/baby-stark/src/polynomial.rs @@ -60,4 +60,16 @@ impl Polynomial { self.__add__(other.__neg__()) } + pub fn __mul__(self, other : Polynomial) -> Polynomial{ + let field = self.coeficients.get(0).unwrap().field; + let zero = field.zero(); + let mut coeffs = vec![zero; self.coeficients.len() + other.coeficients.len() - 1]; + for i in 0..self.coeficients.len() { + for j in 0..other.coeficients.len() { + coeffs[i+j] = coeffs[i+j].__add__(self.coeficients[i].__mul__(other.coeficients[j])); + } + } + Polynomial::from(coeffs) + } + }