Skip to content

Commit

Permalink
After new pull requests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elielnfinic committed Mar 19, 2024
1 parent 67dafd7 commit a221547
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion baby-stark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use baby_stark_math_lib;
use crate::field::FieldElement;

mod field;
mod polynomial;
// mod polynomial;

fn main() {
println!("Hello, world!");
Expand Down
29 changes: 16 additions & 13 deletions baby-stark/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,58 +42,61 @@ impl Polynomial {
)
}

pub fn __add__(self, other : Polynomial) -> Polynomial{
pub fn __add__(self, other: Polynomial) -> Polynomial {
if self.degree() == -1 {
return other;
} else if other.degree() == -1 {
return self;
}
}
let field = self.coeficients.get(0).unwrap().field;

let zero_vec = [field.zero(); 10].to_vec();
let largest_vec = max(self.coeficients.len(), other.coeficients.len());
let coeffs = vector_scalar_multiplication(zero_vec, largest_vec as i128);

}

pub fn __sub__(self, other : Polynomial) -> Polynomial{
pub fn __sub__(self, other: Polynomial) -> Polynomial {
self.__add__(other.__neg__())
}

pub fn __mul__(self, other : Polynomial) -> Polynomial{
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]));
coeffs[i + j] =
coeffs[i + j].__add__(self.coeficients[i].__mul__(other.coeficients[j]));
}
}
Polynomial::from(coeffs)
}
pub fn __eq__(self, other : Polynomial) -> bool{
}

pub fn __eq__(self, other: Polynomial) -> bool {
if self.degree() != other.degree() {
return false;
}
if self.degree() == -1 {
return true;
}
self.coeficients.iter().zip(other.coeficients.iter()).all(|(a, b)| a == b)
self.coeficients
.iter()
.zip(other.coeficients.iter())
.all(|(a, b)| a == b)
}

pub fn __neq__(self, other : Polynomial) -> bool{
pub fn __neq__(self, other: Polynomial) -> bool {
!self.__eq__(other)
}

pub fn is_zero(self) -> bool{
pub fn is_zero(self) -> bool {
if self.degree() == -1 {
return true;
}
return false;
}

pub fn leading_coefficient(self){
pub fn leading_coefficient(self) {
self.coeficients[self.degree()]
}
}

0 comments on commit a221547

Please sign in to comment.