Skip to content

Commit

Permalink
Merge pull request #3 from WilfriedM01/add_polynomials_sub_mul
Browse files Browse the repository at this point in the history
Add polynomials sub mul
  • Loading branch information
elielnfinic authored Mar 19, 2024
2 parents bccce60 + aa4dd55 commit 67dafd7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions baby-stark/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ impl Polynomial {

}

pub fn __sub__(self, other : Polynomial) -> 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)
}

pub fn __eq__(self, other : Polynomial) -> bool{
if self.degree() != other.degree() {
return false;
Expand Down

0 comments on commit 67dafd7

Please sign in to comment.