Ask Your Question

Revision history [back]

I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :

sage: R.<x,a,b> = PolynomialRing(QQ)
sage: R
Multivariate Polynomial Ring in x, a, b over Rational Field
sage: P = R((x - a)*(x - b))
sage: P
x^2 - x*a - x*b + a*b
sage: P.mod(a+b)
x^2 - b^2

sage: R.<x,a,b,c> = PolynomialRing(QQ)
sage: P = R((x - a)*(x - b)*(x-c))
sage: P.mod(a+b+c)
x^3 - x*b^2 - x*b*c + b^2*c - x*c^2 + b*c^2
sage: P.mod(a*b*c-2)
x^3 - x^2*a - x^2*b + x*a*b - x^2*c + x*a*c + x*b*c - 2

Does this help ?

I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :

sage: R.<x,a,b> = PolynomialRing(QQ)
sage: R
Multivariate Polynomial Ring in x, a, b over Rational Field
sage: P = R((x - a)*(x - b))
sage: P
x^2 - x*a - x*b + a*b
sage: P.mod(a+b)
x^2 - b^2

sage: R.<x,a,b,c> = PolynomialRing(QQ)
sage: P = R((x - a)*(x - b)*(x-c))
sage: P.mod(a+b+c)
x^3 - x*b^2 - x*b*c + b^2*c - x*c^2 + b*c^2
sage: P.mod(a*b*c-2)
x^3 - x^2*a - x^2*b + x*a*b - x^2*c + x*a*c + x*b*c - 2

Does this help ?

EDIT Regarding your answer, you should notice that, when a+b=0 (equivelently b=-a), you have x^2 - b^2 = x^2 + a*b since, you have -b^2 = -b*b = -b*(-a) = a*b !!! So i guess my answer still applies. You can check it as follows:

sage: R.<x,a,b> = PolynomialRing(QQ)
sage: I = R.ideal(a+b)
sage: I
Ideal (a + b) of Multivariate Polynomial Ring in x, a, b over Rational Field
sage: P = R((x - a)*(x - b))
sage: P.mod(I)
x^2 - b^2
sage: P.mod(I) == (x^2+a*b).mod(I)
True

Or, you can work directly in the quotient ring:

sage: Q = R.quotient(I)
sage: Q
Quotient of Multivariate Polynomial Ring in x, a, b over Rational Field by the ideal (a + b)
sage: Q(P)
xbar^2 - bbar^2
sage: Q(P) == Q(x^2+a*b)
True
sage: