If I have a polynomial P, is there a way to calculate P^-1 modulo Q, being Q another polynomial? I know that the coefficients of both polynomials belongs to the field of integers modulo z, being z an integer.
I´m not sure if SymPy has already a function for that in its galoistools module.
This is essentially the same as finding polynomials S, T such that PS + QT = 1. Which is possible when gcd(P, Q) = 1, and can be done with
galoistools.gf_gcdex
. For example, let's invert3x^3+2x+4
modulox^2+2x+3
with the coefficient field Z/11Z:This prints
[8, 5]
- the inverse is8x+5
. Sanity check by hand: