-
Notifications
You must be signed in to change notification settings - Fork 10
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
Introduce non-prime finite fields in fp
#147
Conversation
@hoodmane do you want more time to review this or are we good to merge? |
I'm going to try to do a more detailed review. |
No worries, I know it's a substantial change |
One question I'm still pondering: it is better to implement arithmetic operations on the fields or the elements? On one hand, implementing them on fields means that the elements themselves can be very lightweight, since the field will be responsible for knowing how to handle them. However, we're now required to keep a copy of the field around, and always write, say, I'm thinking the second approach is better. It solves the problem of ergonomics, which will make it simpler to just treat elements as things that we can manipulate algebraically. It will require us to use something like It might seem drastic to keep a copy of the field for every single element, but |
I agree it's nice to be able to write FieldElement<FieldType> {
field: FieldType
data: FieldType::ElementData
} And then your point is for most of the fields we are calculating, |
Yeah that's the idea. Basically tagging every element with its field. So struct SmallFqElement<P> {
field: SmallFq<P>,
data: Option<u32>,
} which would double the memory usage. That would also mean that we would change struct FpElement<P> {
field: Fp<P>,
data: u32
} but as you say the extra I'm not sure if we want to change our |
Closing in favor of #159 |
This adds support for prime-power fields of order
<2^16
. We construct the multiplication table for the fieldF_(p^d)
by identifying it withF_p[a]/P
, whereP
is the appropriate Conway polynomial. Since there aren't that many fields of that order that aren't prime, I just hardcoded the Conway polynomials in a separate file.The
FqVectorP
struct (previouslyFpVectorP
) takes in a generic field instead of a prime, and all the managing of the internals of a limb is delegated to the underlying field.Note that right now we only have a monomorphized
FpVector
, where the field is prime. This allows us to useu32
s in our API. I suspect that the better move would be to have a dedicatedFpElement
struct that would be a wrapper around au32
, but would ensure that it belongs in the right range at compile time. I have started experimenting with this, but it gets really unwieldy to constantly create field elements instead of just passing regular numbers (in thealgebra
crate for example).Implementing larger fields would not be impossible, but it would require more mucking around with Conway polynomials (that are only known for finitely many
q
s), and switching to a different representation for storing field elements and multiplication tables.