Fraction modulo integer in sage

537 Views Asked by At

I'm working on a sage script right now, I have some polynomials coefficients that are rational, and I want to apply a congruence on these coefficientss, for example: $p = 1 + (7/2)x$ the function should give $p \mod 3 = 1 + 1/x$

I tried mod_ui(n) but it's no good cause it returns an int I have the code for the function in Python but I couldn't "translate it" in sage script, here is the python code:

def modPoly(c,k):
if(k==0):
    print "Error in modPoly(c,k). Integer k must be non-zero"
else:
    return map(lambda x: fracModulo.fracMod(x,k),c)
1

There are 1 best solutions below

1
On BEST ANSWER

Here's an example showing how to coerce elements of $\mathbb{Q}$ into $\mathbb{Z}/n\mathbb{Z}$.

sage: R = Integers(20)
sage: R(1/7)
3

So $3$ is the multiplicative inverse of $7$ mod $20$.

Okay, here's a more detailed answer to your question.

R.<x> = PolynomialRing(QQ)
p = 1 + (7/2)*x
Z3 = Integers(3)
Z3x.<x> = PolynomialRing(Z3)
Z3x(p)

For me, this outputs $2x+1$.