# changing a variable in the ring of polynomials

In the ring $\mathbb{Z}[x,y]$ , I want to add the new variable z:=xy, and show it in the polynomial $p=(ex+y)^2$ so that $p=(ex)^2+2ez+y^2$. My attempt is to define the rings and the polynomial $p$

S.<e>=ZZ['e'];
R.<x,y,z>=S['x, y, z'];
p=(e*x+y)^2


and to set $xy=z$, we define the ideal $I=(xy-z)R$ and the quotient $Q=R/I$

I=(x*y-z)*R; Q=R.quo(I)


to reduce the polynomial $p$ modulo the ideal $I$ we use

q=Q(p)


So far, I have a problem such that sagemath outputs an error ' Can only reduce polynomials over fields.' I want to know where is the problem ?? and solve it.

edit retag close merge delete

Sort by ยป oldest newest most voted

$\mathbb{Z}[e]$ is not a field : $\exists x,y\in\mathbb{Z}[e] ,\,\displaystyle{\frac{x}{y}}\not\in\mathbb{Z}[e]$. Use its fraction field instead :

sage: S=FractionField(ZZ['e'])
sage: R.<x,y,z>=S['x, y, z'];
sage: p=(e*x+y)^2
sage: I=(x*y-z)*R; Q=R.quo(I)
sage: q=Q(p)
sage: q
e^2*xbar^2 + ybar^2 + 2*e*zbar


whuch is, up to a lift :

sage: q.parent()
Quotient of Multivariate Polynomial Ring in x, y, z over Fraction Field of Univariate Polynomial Ring in e over Integer Ring by the ideal (x*y - z)


the result you sought.

Alternative, using symbolic variables (and Sympy's subs, which is recursive) :

sage: reset()
sage: var("x, y, z, e")
(x, y, z, e)
sage: import sympy
sage: ((e*x+y)^2)._sympy_().expand().subs(sympy.sympify({x*y:z}))._sage_()
e^2*x^2 + y^2 + 2*e*z


HTH,

more