@@ -502,6 +502,53 @@ cdef class fmpq_poly(flint_poly):
502502 fmpq_poly_pow(res.val, self .val, < ulong> exp)
503503 return res
504504
505+ def mul_low (self , other , slong n ):
506+ r """
507+ Returns the lowest ``n`` coefficients of the multiplication of ``self`` with ``other``
508+
509+ Equivalent to computing `f( x) \c dot g( x) \m od x^ n`
510+
511+ >>> f = fmpq_poly( [2,3,5,7,11 ])
512+ >>> g = fmpq_poly( [1,2,4,8,16 ])
513+ >>> f. mul_low( g, 5)
514+ 101* x^ 4 + 45* x^ 3 + 19* x^ 2 + 7* x + 2
515+ >>> f. mul_low( g, 3)
516+ 19* x^ 2 + 7* x + 2
517+ >>> f. mul_low( g, 1)
518+ 2
519+ """
520+ # Only allow multiplication with other fmpq_poly
521+ if not typecheck(other, fmpq_poly):
522+ raise TypeError (" other polynomial must be of type fmpq_poly" )
523+
524+ cdef fmpq_poly res
525+ res = fmpq_poly.__new__ (fmpq_poly)
526+ fmpq_poly_mullow(res.val, self .val, (< fmpq_poly> other).val, n)
527+ return res
528+
529+ def pow_trunc (self , slong e , slong n ):
530+ r """
531+ Returns ``self`` raised to the power ``e`` modulo `x^ n`:
532+ :math:`f^ e \m od x^ n`/
533+
534+ Note: For exponents larger that 2^ 63 ( which do not fit inside a slong) use the
535+ method :meth:`~. pow_mod` with the explicit modulus `x^ n`.
536+
537+ >>> f = fmpq_poly( [1, 2, 3 ])
538+ >>> x = fmpq_poly( [0, 1 ])
539+ >>> f. pow_trunc( 2** 20, 4)
540+ 1537230871828889600* x^ 3 + 2199024304128* x^ 2 + 2097152* x + 1
541+ >>> f. pow_trunc( 5** 25, 3)
542+ 177635683940025046765804290771484375* x^ 2 + 596046447753906250* x + 1
543+ """
544+ if e < 0 :
545+ raise ValueError (" Exponent must be non-negative" )
546+
547+ cdef fmpq_poly res
548+ res = fmpq_poly.__new__ (fmpq_poly)
549+ fmpq_poly_pow_trunc(res.val, self .val, e, n)
550+ return res
551+
505552 def gcd (self , other ):
506553 """
507554 Returns the greatest common divisor of *self* and *other*.
0 commit comments