Skip to content

Commit

Permalink
Merge pull request #20 from FimboIsso/main
Browse files Browse the repository at this point in the history
Add implement interpolate_domain function
  • Loading branch information
elielnfinic authored Mar 21, 2024
2 parents feb2d07 + 2768a77 commit dc7da4e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions baby-stark/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ impl Polynomial {
return value;
}


pub fn interpolate_domain(domain : Vec<FieldElement>,values : Vec<FieldElement>) ->Polynomial{
assert_eq!(domain.len() , values.len(),"number of elements in domain does not match number of values -- cannot interpolate");
assert!(!domain.is_empty(),"cannot interpolate between zero points");
let field = domain[0].clone().field;

let x = Polynomial::from (vec![field.zero(), field.one()]);
let mut acc = Polynomial::from( [].to_vec() );
for i in 0..domain.len(){
let mut prod = Polynomial::from( vec![values[i].clone()]);
for j in 0..domain.len(){
if j == i{
continue;
}
prod = prod.__mul__(x.clone().__sub__( Polynomial ::from( vec![domain[j].clone()])))
.__mul__(Polynomial::from( vec![(domain[i].__sub__(domain[j])).inverse()]));
}
acc = acc.__add__(prod);
}
return acc;
}

pub fn zerofier_domain(domain: &[FieldElement]) -> Polynomial {
let field = domain[0].field.clone();
let x = Polynomial::from(vec![field.zero(), field.one()]);
Expand Down

0 comments on commit dc7da4e

Please sign in to comment.