-
Notifications
You must be signed in to change notification settings - Fork 31
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
Issue with NTT and GF(2) (and other FieldArray) #542
Comments
Caveat: I don't have any practical experience with the NTT. So my knowledge may be limited.
It is my understanding that there is no NTT transform of a length-10 array over GF(2), since there isn't a primitive 10-th root in GF(2). I believe you have to "cast" (the mathematical term is not coming to mind) the GF(2) array into a larger field to compute the NTT. In your example, you need to "cast" to GF(11), or a larger field. I fear performing this promotion silently could be misleading / have unintended effects. For example, if the user provided an array over GF(p1), but the values were small and the array was short, can a smaller modulus p2 < p1 exist that would satisfy the criteria? If so, the function would choose p2 (which is different than the input of p1) and the NTT output would be different than if computed using p1. That seems like an unexpected result.
Another workaround is to pass a NumPy array or list, not FieldArray. So What are your thoughts? |
@mhostetter Let me think about it for a while, I'm also not that familiar with the NTT. As usual, you bring nice points, and I was just thinking about some specific use cases. |
Here's an example of how different (valid) moduli can affect the NTT output. import galois
x = galois.GF(2).Random(10)
print(x)
print(galois.ntt(x, modulus=11))
print(galois.ntt(x, modulus=31))
print(galois.ntt(x, modulus=71))
So if the initial array |
@iyanmv had any more thoughts about this? |
Sorry, I still didn't have time to check the theory in detail and see if it would make sense. But it is in my TODO list, hopefully soon |
Hi,
If the array passed to
ntt
is aGF(2)
array, then the defaultmodulus
will never satisfy the required criteria (unless the array has size 1). This is because the characteristic of the field is used, i.e.,p=2
, as modulus ingalois/src/galois/_ntt.py
Line 115 in 25baec4
which causes
_ntt
to never enter this loop to compute a validmodulus
galois/src/galois/_ntt.py
Lines 249 to 254 in 25baec4
This is documented in the docstring, though, so perhaps I'm not understanding something here:
I would expect that calling
ntt
should work correctly, by default, on any FieldArray. For example, I think this code should work:But at the moment it raises a
ValueError
that the user did not passed.A workaround, is to manually choose a valid modulus, e.g.
This also happens with other fields. For example,
Commenting the two lines from
ntt
solves the issue for me:galois/src/galois/_ntt.py
Lines 114 to 115 in 25baec4
The text was updated successfully, but these errors were encountered: