1 | initial version |
$\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,