buc030
buc030

Reputation: 434

Polynomial with modular coefficients library in python

does someone knows a simple library to do
calculations on Polynomial with modular coefficients?

I've seen numpy, but this one seems like it does not support modular coefficients...

Thanks, Shai.

Upvotes: 1

Views: 1571

Answers (2)

Rexcirus
Rexcirus

Reputation: 2927

You can use Sympy: https://docs.sympy.org/latest/modules/polys/index.html, in particular https://docs.sympy.org/latest/modules/polys/domainsref.html#gf-p

from sympy import Poly, Symbol
x = Symbol('x')
p2 = Poly(x**2 + 1, modulus=2)

Upvotes: 0

Ed.B
Ed.B

Reputation: 495

It suffices to lift coefficients to integers. For example if you want to compute (1+2x+3x^2)(3+2x+x^2) in Z/5[x], simply you compute (1+2x+3x^2)(3+2x+x^2) in Z[x] and reduce it to Z/5[x].

Thus

>>> import numpy.polynomial.polynomial
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> numpy.fmod(numpy.polynomial.polynomial.polymul(c1,c2),5)
>>> numpy.fmod(numpy.polynomial.polynomial.polymul(c1,c2),5)

gives

array([ 3.,  3.,  4.,  3.,  3.])

Upvotes: 0

Related Questions