ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 13 Feb 2016 05:56:43 -0600Constraints on polynomial coefficientshttp://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/ Given a polynomial P=(X-a)*(X-b)*(X-c) over Q[a,b,c][X] , how can I force the coefficients to fullfill constraints such as elementary symetric function a+b+c=0 or a*b*c=2, some polynomial constraint on coefficients.
It is a bit like using coefficients on a number field with the constraint of a minimal polynomial but with different constraints here.
A simple example: if P = ( X - a ) ( X - b ) and a + b = 0 then I want to find P = X^2 - ab Tue, 09 Feb 2016 12:24:49 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/Answer by nd for <p>Given a polynomial P=(X-a)<em>(X-b)</em>(X-c) over Q[a,b,c][X] , how can I force the coefficients to fullfill constraints such as elementary symetric function a+b+c=0 or a<em>b</em>c=2, some polynomial constraint on coefficients.</p>
<p>It is a bit like using coefficients on a number field with the constraint of a minimal polynomial but with different constraints here.</p>
<p>A simple example: if P = ( X - a ) ( X - b ) and a + b = 0 then I want to find P = X^2 - ab </p>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32559#post-id-32559When I use several ideals, I don't have commutativity. Is this normal?
R.<X,a,b>=QQ[]
P1=(X-a)*(X-b)
I=R.ideal(a+b)
J=R.ideal(a*b)
A=P.mod(I).mod(J)
=> X^2 - b^2
B=P.mod(J).mod(I)
=> X^2
A==B;
=> False Sat, 13 Feb 2016 05:56:43 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32559#post-id-32559Answer by nd for <p>Given a polynomial P=(X-a)<em>(X-b)</em>(X-c) over Q[a,b,c][X] , how can I force the coefficients to fullfill constraints such as elementary symetric function a+b+c=0 or a<em>b</em>c=2, some polynomial constraint on coefficients.</p>
<p>It is a bit like using coefficients on a number field with the constraint of a minimal polynomial but with different constraints here.</p>
<p>A simple example: if P = ( X - a ) ( X - b ) and a + b = 0 then I want to find P = X^2 - ab </p>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32549#post-id-32549I still have 2 concerns if you can help!
Q.<X,a>=QQ[];
P = 5 * X^2 + 3 * a^2 * X + 5 - a^2
If:
I=Q.ideal(a^2-5)
=> 5*X^2 + 15*X # OK
However, this doesn't work modulo any integer:
P.mod(n) = 0 whatever n.
Merci!
Secondly, when I use several ideals, I don't have commutativity. Is this normal?
R.<X,a,b>=QQ[]
P1=(X-a)*(X-b)
I=R.ideal(a+b)
J=R.ideal(a*b)
A=P.mod(I).mod(J)
=> X^2 - b^2
B=P.mod(J).mod(I)
=> X^2
A==B;
=> False
Fri, 12 Feb 2016 04:30:13 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32549#post-id-32549Comment by nd for <p>I still have 2 concerns if you can help!</p>
<p>Q.<x,a>=QQ[];</p>
<p>P = 5 * X^2 + 3 * a^2 * X + 5 - a^2</p>
<p>If:
I=Q.ideal(a^2-5)</p>
<p>=> 5<em>X^2 + 15</em>X # OK</p>
<p>However, this doesn't work modulo any integer:</p>
<p>P.mod(n) = 0 whatever n.</p>
<p>Merci!</p>
<p>Secondly, when I use several ideals, I don't have commutativity. Is this normal?</p>
<p>R.<x,a,b>=QQ[]</p>
<p>P1=(X-a)*(X-b)</p>
<p>I=R.ideal(a+b)</p>
<p>J=R.ideal(a*b)</p>
<p>A=P.mod(I).mod(J)
=> X^2 - b^2</p>
<p>B=P.mod(J).mod(I)
=> X^2</p>
<p>A==B;
=> False</p>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32557#post-id-32557When I use several ideals, I don't have commutativity. Is this normal?
R.<X,a,b>=QQ[]
P1=(X-a)*(X-b)
I=R.ideal(a+b)
J=R.ideal(a*b)
A=P.mod(I).mod(J)
=> X^2 - b^2
B=P.mod(J).mod(I)
=> X^2
A==B;
=> FalseSat, 13 Feb 2016 05:41:44 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32557#post-id-32557Answer by tmonteil for <p>Given a polynomial P=(X-a)<em>(X-b)</em>(X-c) over Q[a,b,c][X] , how can I force the coefficients to fullfill constraints such as elementary symetric function a+b+c=0 or a<em>b</em>c=2, some polynomial constraint on coefficients.</p>
<p>It is a bit like using coefficients on a number field with the constraint of a minimal polynomial but with different constraints here.</p>
<p>A simple example: if P = ( X - a ) ( X - b ) and a + b = 0 then I want to find P = X^2 - ab </p>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32515#post-id-32515I 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:
Tue, 09 Feb 2016 16:14:53 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?answer=32515#post-id-32515Comment by nd for <p>I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :</p>
<pre><code>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
</code></pre>
<p>Does this help ?</p>
<p><strong>EDIT</strong> Regarding your answer, you should notice that, when <code>a+b=0</code> (equivelently <code>b=-a</code>), you have <code>x^2 - b^2 = x^2 + a*b</code> since, you have <code>-b^2 = -b*b = -b*(-a) = a*b</code> !!! So i guess my answer still applies. You can check it as follows:</p>
<pre><code>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
</code></pre>
<p>Or, you can work directly in the quotient ring:</p>
<pre><code>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:
</code></pre>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32523#post-id-32523Observe that the result is " X^2 - b^2 " while in case of " a+b=0", you should obtain " X^2 - a*b ".
Am still trying !Wed, 10 Feb 2016 14:29:23 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32523#post-id-32523Comment by nd for <p>I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :</p>
<pre><code>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
</code></pre>
<p>Does this help ?</p>
<p><strong>EDIT</strong> Regarding your answer, you should notice that, when <code>a+b=0</code> (equivelently <code>b=-a</code>), you have <code>x^2 - b^2 = x^2 + a*b</code> since, you have <code>-b^2 = -b*b = -b*(-a) = a*b</code> !!! So i guess my answer still applies. You can check it as follows:</p>
<pre><code>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
</code></pre>
<p>Or, you can work directly in the quotient ring:</p>
<pre><code>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:
</code></pre>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32525#post-id-32525Perhaps I wasn't clear at all.
I have a polynomial where the coefficients are parameters. I take the example of
P = ( X - a0) * (X -a1) = X^2 + (-a0 - a1)*X + a0 * a1
I want to impose an equation on the parameters who belong to a field ("QQ" here), say "a0 + a1 = 0".
The result must be:
P = X^2 + a0 * a1
A=PolynomialRing(QQ,2,'a')
v=B.gens()
R.<X>=PolynomialRing(A)
P=R( ( X - v[0] ) * ( X - v[1] ) ) ; # P = ( X - a0) * (X -a1)Thu, 11 Feb 2016 02:24:16 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32525#post-id-32525Comment by tmonteil for <p>I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :</p>
<pre><code>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
</code></pre>
<p>Does this help ?</p>
<p><strong>EDIT</strong> Regarding your answer, you should notice that, when <code>a+b=0</code> (equivelently <code>b=-a</code>), you have <code>x^2 - b^2 = x^2 + a*b</code> since, you have <code>-b^2 = -b*b = -b*(-a) = a*b</code> !!! So i guess my answer still applies. You can check it as follows:</p>
<pre><code>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
</code></pre>
<p>Or, you can work directly in the quotient ring:</p>
<pre><code>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:
</code></pre>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32533#post-id-32533I edited my answer to explain why `x^2 - b^2` is as valid as `x^2 + a*b`.Thu, 11 Feb 2016 10:39:53 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32533#post-id-32533Comment by nd for <p>I am not sure to understand your question completely, but usually constraints can be expressed as working modulo some ideal :</p>
<pre><code>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
</code></pre>
<p>Does this help ?</p>
<p><strong>EDIT</strong> Regarding your answer, you should notice that, when <code>a+b=0</code> (equivelently <code>b=-a</code>), you have <code>x^2 - b^2 = x^2 + a*b</code> since, you have <code>-b^2 = -b*b = -b*(-a) = a*b</code> !!! So i guess my answer still applies. You can check it as follows:</p>
<pre><code>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
</code></pre>
<p>Or, you can work directly in the quotient ring:</p>
<pre><code>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:
</code></pre>
http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32535#post-id-32535Yes, you are perfectly right. I answered this because I was using coefficients defined on a number field, and the "mod" didn't work because I firstly defined the number field and then the ring. I discovered that if instead you define the ring and then the number field as an extension, the method works, at least for what I tried so far. I didn't have time to explain more my comment in between, and I thank you for your help.Thu, 11 Feb 2016 12:07:04 -0600http://ask.sagemath.org/question/32511/constraints-on-polynomial-coefficients/?comment=32535#post-id-32535