Lagrange interpolation over elements in finite field? #952
Replies: 2 comments
-
I've not fully figured this out, but have improved my understanding a bit, so I'll partially answer myself in case it could be of any help to anyone else. I think I now understand the resolving comment in #921. In the context of my code example above:
I know that I'm still missing something, because when I evaluate the interpolated polynomial at the 4th roots of unity (I assumed the ordering 1, 4, 16, 13 based on the ordering of the analogous 4th roots of unity over the complex numbers 1, i, -1, -i) I get two of the four coefficients of the polynomial slightly incorrect:
But, things make more sense than before, which is good! |
Beta Was this translation helpful? Give feedback.
-
Ok, back again to answer my own question a bit more in case it can help others to avoid making the same mistakes I did! A silly mistake I made was the choice of generator for the finite field I defined. Somehow I mistook this as being generation of the field elements using the additive binary operator rather than the multiplicative binary operator in the field 🤦, and this mistake resulted in all four 4th roots of unity being calculated as 1. So, all four evaluations I gave were being interpreted as being at the same 4th root of unity 1, and this obviously messes with the interpolation being done to get the polynomial coefficients. The only other issue I came across after that was that the roots of unity in the evaluation domain were ordered as going clockwise around the unit circle as opposed to my previous assumption of the ordering being counter-clockwise. Ie, the ordering of the roots of unity was 1, 13, 16, 4 (analogous to 1, -i, -1, i if thinking about the field being the complex numbers). This was checked by looking at what The small program I ended up with to accomplish what I wanted is the following in case it's of use to anyone else: https://github.com/yousefmoazzam/circuits/blob/master/polynomial_playground/src/bin/simple_interpolation.rs. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks!
Firstly, many thanks to the contributors to the arkworks ecosystem, I've been playing with some of the crates in the project and it's been a fun experience 🙂
I've been working through this online book on zero knowledge programming where the code examples are in python, and I've been trying to test my understanding by doing analagous things in rust, using crates in the arkworks ecosystem when it seemed relevant.
I had a question about Lagrange interpolation of finite field elements to get the coefficients of a polynomial, and I was wondering if the community would be able to help me out a bit?
In the post in the online book on Lagrange interpolation, there's a small code snippet that I believe is doing something like:
For reference, the python code snippet in the post I'm referring to is the following:
Trying to follow the docs here, my best naive attempt so far at doing an analogous thing in rust using crates in the arkworks ecosystem was the following:
However, I get an assertion error:
and if I print the result of the evaluations I see that I get some values I didn't expect for the evaluation of the interpolated polynomial:
After browsing some of the issues, I know that part of why my code is incorrect is because I'm making the same error as in #921, but I admittedly don't understand the resolving comment for that issue. (I did start taking a look at how an IFFT can be used to compute the coefficients of a polynomial, but soon wondered if understanding that was overkill for what I'm wanting to get done, so decided to seek some help before going too far down that rabbit hole).
So, one part of this post was to ask if I could possibly get a bit more info on how that answer resolved the issue. Would I need to provide different values to evaluate the interpolated polynomial at to get what I want, rather than passing in the values in my
x_values
vector?However, I did also want to step back and ask if I'm using the arkworks crates correctly to do Lagrange interpolation, am I using the right things to accomplish what I want? Or am I using the wrong tools fore the job? I did see the
evaluate_all_lagrange_coefficients
method which sort of sounds like what I'm looking for, but I didn't understand how to use it: I was expecting to be able to give it a vector of points/elements or something (like in the python example), so I was thrown-off when I saw that the method takes only one element as a parameter I think?I hope my questions make some sense, please do let me know if I can clarify anything, and thanks in advance for any help! 🙂
Beta Was this translation helpful? Give feedback.
All reactions