Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implement interpolate_domain function #20

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions baby-stark/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@ impl Polynomial {
return value;
}


pub fn interpolate_domain(domain : [FieldElement],values : [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();
FimboIsso marked this conversation as resolved.
Show resolved Hide resolved
let mut x = Polynomial {coefficients : vec![filed.zero(), field.one()]};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed : fix typo

let mut acc = Polynomial { coefficients : Vec::new() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mettre un Vec de FieldElement

for i in 0..domain.len(){
let mut prod = Polynomial {coefficients :vec![values[i].clone()]};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true

for j in 0..domain.len(){
if j == i{
continue;
}
//prod = prod * (x.clone() - Polynomial {coefficients : vec![domain[j].clone()]}) * Polynomial{ coefficients:vec![(domain[i] - domain[j]).inverse()]};
prod = prod.__mul_(x.clone().__sub__(Polynomial {coefficients : vec![domain[j].clone()]})).__mul_(Polynomial{coefficients : vec![domain[i].__sub__(domain[j]).inverse()]});
}
acc = acc + 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
Loading