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)
Here's an example showing how to coerce elements of $\mathbb{Q}$ into $\mathbb{Z}/n\mathbb{Z}$.
So $3$ is the multiplicative inverse of $7$ mod $20$.
Okay, here's a more detailed answer to your question.
For me, this outputs $2x+1$.