diff --git a/baby-stark/src/polynomial.rs b/baby-stark/src/polynomial.rs index e616732..e69d222 100644 --- a/baby-stark/src/polynomial.rs +++ b/baby-stark/src/polynomial.rs @@ -211,6 +211,28 @@ impl Polynomial { return value; } + + pub fn interpolate_domain(domain : Vec,values : Vec) ->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()]);