1+ cimport cython
2+
13from cpython.list cimport PyList_GET_SIZE
24from flint.flint_base.flint_base cimport flint_poly
35from flint.utils.typecheck cimport typecheck
@@ -18,9 +20,10 @@ from flint.utils.flint_exceptions import DomainError
1820cdef dict _nmod_poly_ctx_cache = {}
1921
2022
23+ @cython.no_gc
2124cdef class nmod_poly_ctx:
2225 """
23- Context object for creating :class:`~.nmod_poly` initalised
26+ Context object for creating :class:`~.nmod_poly` initalised
2427 with modulus :math:`N`.
2528
2629 >>> nmod_poly_ctx.new(17)
@@ -170,6 +173,7 @@ cdef class nmod_poly_ctx:
170173 return nmod_poly(arg, self )
171174
172175
176+ @cython.no_gc
173177cdef class nmod_poly(flint_poly):
174178 """
175179 The nmod_poly type represents dense univariate polynomials
@@ -337,7 +341,7 @@ cdef class nmod_poly(flint_poly):
337341 """
338342 cdef nmod_poly res
339343 cdef slong d
340-
344+
341345 if degree is not None :
342346 d = degree
343347 if d != degree or d < 0 :
@@ -387,7 +391,7 @@ cdef class nmod_poly(flint_poly):
387391 """
388392 if n <= 0 :
389393 raise ValueError (f" {n = } must be positive" )
390-
394+
391395 if nmod_poly_get_coeff_ui(self .val, 0 ) == 0 :
392396 raise ZeroDivisionError (f" nmod_poly inverse_series_trunc: leading coefficient is zero" )
393397
@@ -402,7 +406,7 @@ cdef class nmod_poly(flint_poly):
402406 """
403407 Returns the composition of two polynomials
404408
405- To be precise about the order of composition, given ``self``, and ``other``
409+ To be precise about the order of composition, given ``self``, and ``other``
406410 by `f(x)`, `g(x)`, returns `f(g(x))`.
407411
408412 >>> f = nmod_poly([1,2,3], 163)
@@ -417,15 +421,15 @@ cdef class nmod_poly(flint_poly):
417421 if other is NotImplemented :
418422 raise TypeError (" cannot convert input to nmod_poly" )
419423 res = self .ctx.new_nmod_poly()
420- nmod_poly_compose(res.val, self .val, (< nmod_poly> other).val)
421- return res
424+ nmod_poly_compose(res.val, self .val, (< nmod_poly> other).val)
425+ return res
422426
423427 def compose_mod (self , other , modulus ):
424428 """
425429 Returns the composition of two polynomials modulo a third.
426430
427- To be precise about the order of composition, given ``self``, and ``other``
428- and ``modulus`` by `f(x)`, `g(x)` and `h(x)`, returns `f(g(x)) \mod h(x)`.
431+ To be precise about the order of composition, given ``self``, and ``other``
432+ and ``modulus`` by `f(x)`, `g(x)` and `h(x)`, returns `f(g(x)) \mod h(x)`.
429433 We require that `h(x)` is non-zero.
430434
431435 >>> f = nmod_poly([1,2,3,4,5], 163)
@@ -440,17 +444,17 @@ cdef class nmod_poly(flint_poly):
440444 g = self .ctx.any_as_nmod_poly(other)
441445 if g is NotImplemented :
442446 raise TypeError (f" cannot convert {other = } to nmod_poly" )
443-
447+
444448 h = self .ctx.any_as_nmod_poly(modulus)
445449 if h is NotImplemented :
446450 raise TypeError (f" cannot convert {modulus = } to nmod_poly" )
447-
451+
448452 if modulus.is_zero():
449453 raise ZeroDivisionError (" cannot reduce modulo zero" )
450454
451455 res = self .ctx.new_nmod_poly()
452- nmod_poly_compose_mod(res.val, self .val, (< nmod_poly> other).val, (< nmod_poly> modulus).val)
453- return res
456+ nmod_poly_compose_mod(res.val, self .val, (< nmod_poly> other).val, (< nmod_poly> modulus).val)
457+ return res
454458
455459 def __call__ (self , other ):
456460 cdef nmod_poly r
@@ -638,8 +642,7 @@ cdef class nmod_poly(flint_poly):
638642 >>> f = 30*x**6 + 104*x**5 + 76*x**4 + 33*x**3 + 70*x**2 + 44*x + 65
639643 >>> g = 43*x**6 + 91*x**5 + 77*x**4 + 113*x**3 + 71*x**2 + 132*x + 60
640644 >>> mod = x**4 + 93*x**3 + 78*x**2 + 72*x + 149
641- >>>
642- >>> f.pow_mod(123, mod)
645+ >>> f.pow_mod(123, mod)
643646 3*x^3 + 25*x^2 + 115*x + 161
644647 >>> f.pow_mod(2**64, mod)
645648 52*x^3 + 96*x^2 + 136*x + 9
@@ -663,7 +666,7 @@ cdef class nmod_poly(flint_poly):
663666
664667 # Output polynomial
665668 res = self .ctx.new_nmod_poly()
666-
669+
667670 # For small exponents, use a simple binary exponentiation method
668671 if e.bit_length() < 32 :
669672 nmod_poly_powmod_ui_binexp(
0 commit comments