Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Implement modular exponentiation in polynomial rings Flint.
Browse files Browse the repository at this point in the history
The old behaviour was that the modulus was ignored in the __pow__ function.
Now, the third argument is treated as modulus.
  • Loading branch information
shashwat1002 committed Jan 10, 2022
1 parent c5af195 commit ff56f10
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
Expand Up @@ -1121,6 +1121,16 @@ cdef class Polynomial_integer_dense_flint(Polynomial):
...
TypeError: no canonical coercion from Univariate Polynomial
Ring in R over Integer Ring to Rational Field
Test modular exponentiation(:trac: `#15867`)::
sage: x = polygen(ZZ, name="x")
sage: pow(x, 100, x+1)
1
sage: x = polygen(ZZ, name="x")
sage: pow(x, 3, x^2+1)
-x
"""
cdef long nn
cdef Polynomial_integer_dense_flint res
Expand Down Expand Up @@ -1151,16 +1161,25 @@ cdef class Polynomial_integer_dense_flint(Polynomial):
if nn < 0:
sig_on()
fmpz_poly_pow(res.__poly, self.__poly, -nn)

if ignored != None:
res = res.quo_rem(ignored)[1]
sig_off()
return ~res
else:
if self is self._parent.gen():
sig_on()
fmpz_poly_set_coeff_ui(res.__poly, nn, 1)

if ignored != None:
res = res.quo_rem(ignored)[1]
sig_off()
else:
sig_on()
fmpz_poly_pow(res.__poly, self.__poly, nn)

if ignored != None:
res = res.quo_rem(ignored)[1]
sig_off()
return res

Expand Down

0 comments on commit ff56f10

Please sign in to comment.