-
Notifications
You must be signed in to change notification settings - Fork 33
Extend mul_low and pow_trunc methods to fmpz_poly, fmpq_poly, nmod_poly #322
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
Conversation
Looks like arb_poly and acb_poly have mullow but not pow_trunc. If at least all the exact poly types have these methods now then they can be added to this typing protocol: python-flint/src/flint/typing.py Lines 139 to 145 in d5c40a4
|
src/flint/types/nmod_poly.pyx
Outdated
:math:`f^e \mod x^n`/ | ||
|
||
Note: For exponents larger that 2^63 (which do not fit inside a slong) use the | ||
method :meth:`~.pow_mod` with the explicit modulus `x^n`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the code here could test for overflow and call pow_mod.
ba37169
to
49e35dd
Compare
New proposal :
The proposal is to not use modular pow (which is not defined for fmpz/fmpq) and implement "manually" large exponents using a loop (it works even for fmpz/fmpq and it is 2x-3x faster than powmod). I hope it is not overkill (I'm not sure there is a lot of use for large powers of |
49e35dd
to
eebd8c2
Compare
I'm not sure either but it is good to have an implementation that does not have an arbitrary upper limit on the exponent as long as higher powers are computable. It took me a while to parse the code used for this but it looks good: def pow(x, e):
ebytes = e.to_bytes((e.bit_length() + 15) // 16 * 2, "nig")
p = x ** (ebytes[0] * 256 + ebytes[1])
for i in range(2, len(ebytes), 2):
p = p ** (1 << 16)
p = p * x ** (ebytes[i] * 256 + ebytes[i + 1])
return p I guess that is going to reduce the overhead a little compared to working through The series types can also be used for this but they also have the overflow problem so I guess the same approach could be used there: In [1]: import flint
In [2]: f = flint.fmpz_series([1, 2, 3], prec=3)
In [3]: f
Out[3]: 1 + 2*x + 3*x^2 + O(x^3)
In [4]: f ** (5 ** 25)
Out[4]: 1 + 596046447753906250*x + 177635683940025046765804290771484375*x^2 + O(x^3)
In [5]: f ** (5 ** 30)
---------------------------------------------------------------------------
OverflowError |
Looks good to me. Thanks |
These methods already exist on fmpz_mod_poly and fq_default_poly.
Additionally, the existing docstrings and doctests are updated to assume the upper bound of slong is 2^63. Let me know if this is not fine (current all configured Github runners are 64-bit platforms). I am unsure whether 64-bit specific tests are fine.