# Monomial with power modulo n

I need to implement the following formal structure $$ax^\gamma, \gamma \in \mathbb{Z}/n\mathbb{Z}, a \in \mathbb{R}$$ and $x$ is a formal variable.

I tried

 ZZ6 = Integers(6) x = var('x') x^ZZ6(9) + x^ZZ6(11) 

And get value x^8, whereas I need x^ZZ6(8).

How can I do this in sage?

edit retag close merge delete

Sort by » oldest newest most voted

You can make a polynomial quotient ring:

sage: R.<x> = RR[]
sage: R
Univariate Polynomial Ring in x over Real Field with 53 bits of precision
sage: S = R.quotient(x^6-1)
sage: S
Univariate Quotient Polynomial Ring in xbar over Real Field with 53 bits of precision with modulus x^6 - 1.00000000000000
sage: S.inject_variables()
Defining xbar


Then, you can do

sage: xbar^9 + xbar^11
xbar^5 + xbar^3
sage: xbar^9 * xbar^11
xbar^2


Also, if your coefficients turn out to be rational, i would sugest to define sage: R.<x> = QQ[]

more

This solution has the drawback of introducing an inexact ring in otherwise exact computations...

@emmanuel-charpentier : i used RR to stay close to @only1sale question, I then explained that QQ could be used otherwise, i do not get your point. another way

sage: R = Zmod(6)
sage: x = A.gens()
sage: 3*x+x**4
3*B + B
sage: _**4
120*B + 136*B

more