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.Fri, 12 Feb 2016 04:28:39 -0600Variables in a polynomialhttp://ask.sagemath.org/question/32493/variables-in-a-polynomial/ I edited my question and put the answer I found, so this solves my problem!
My problem was: take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".
I want to produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:
A^2 = b0^2 + (2*r) * b0 * b1 + (r^2) * b1^2 + (2*r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2
and express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:
A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )
The solution was simply to define the number field as an extension of the ring of coefficients and the other way round! Good!
B=PolynomialRing(E,3,'b');
v=B.gens()
E.<r>=B.extension(x^3-2)
A^2=sum( [v[i] * r^i for i in range(3) ] )
gives me the solution:
(b1^2 + 2*b0*b2)*r^2 + (2*b0*b1 + 2*b2^2)*r + b0^2 + 4*b1*b2
result expressed in terms of powers of "r".
Mon, 08 Feb 2016 06:48:10 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/Answer by nd for <p>I edited my question and put the answer I found, so this solves my problem!</p>
<p>My problem was: take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".</p>
<p>I want to produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:</p>
<p>A^2 = b0^2 + (2<em>r) * b0 * b1 + (r^2) * b1^2 + (2</em>r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2</p>
<p>and express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:</p>
<p>A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )</p>
<p>The solution was simply to define the number field as an extension of the ring of coefficients and the other way round! Good!</p>
<p>B=PolynomialRing(E,3,'b');</p>
<p>v=B.gens()</p>
<p>E.<r>=B.extension(x^3-2)</p>
<p>A^2=sum( [v[i] * r^i for i in range(3) ] )</p>
<p>gives me the solution:</p>
<p>(b1^2 + 2<em>b0</em>b2)<em>r^2 + (2</em>b0<em>b1 + 2</em>b2^2)<em>r + b0^2 + 4</em>b1*b2</p>
<p>result expressed in terms of powers of "r".</p>
http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32548#post-id-32548I still have one concern 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!
Fri, 12 Feb 2016 04:28:39 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32548#post-id-32548Answer by nd for <p>I edited my question and put the answer I found, so this solves my problem!</p>
<p>My problem was: take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".</p>
<p>I want to produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:</p>
<p>A^2 = b0^2 + (2<em>r) * b0 * b1 + (r^2) * b1^2 + (2</em>r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2</p>
<p>and express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:</p>
<p>A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )</p>
<p>The solution was simply to define the number field as an extension of the ring of coefficients and the other way round! Good!</p>
<p>B=PolynomialRing(E,3,'b');</p>
<p>v=B.gens()</p>
<p>E.<r>=B.extension(x^3-2)</p>
<p>A^2=sum( [v[i] * r^i for i in range(3) ] )</p>
<p>gives me the solution:</p>
<p>(b1^2 + 2<em>b0</em>b2)<em>r^2 + (2</em>b0<em>b1 + 2</em>b2^2)<em>r + b0^2 + 4</em>b1*b2</p>
<p>result expressed in terms of powers of "r".</p>
http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32528#post-id-32528 Perhaps this example might be more understandable. Take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".
I produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:
A^2 = b0^2 + (2*r) * b0 * b1 + (r^2) * b1^2 + (2*r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2
Notice that "r" is in a number field. I want to express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:
A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )
I edit as I seem to have found a solution. I need to define the number field as an extension of the ring of coefficients and the other way round! Good.
B=PolynomialRing(E,3,'b');
v=B.gens()
E.<r>=B.extension(x^3-2)
A^2=sum( [v[i] * r^i for i in range(3) ] )
gives me the solution:
(b1^2 + 2*b0*b2)*r^2 + (2*b0*b1 + 2*b2^2)*r + b0^2 + 4*b1*b2
result expressed in terms of powers of "r".
Thu, 11 Feb 2016 09:12:25 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32528#post-id-32528Answer by nd for <p>I edited my question and put the answer I found, so this solves my problem!</p>
<p>My problem was: take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".</p>
<p>I want to produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:</p>
<p>A^2 = b0^2 + (2<em>r) * b0 * b1 + (r^2) * b1^2 + (2</em>r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2</p>
<p>and express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:</p>
<p>A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )</p>
<p>The solution was simply to define the number field as an extension of the ring of coefficients and the other way round! Good!</p>
<p>B=PolynomialRing(E,3,'b');</p>
<p>v=B.gens()</p>
<p>E.<r>=B.extension(x^3-2)</p>
<p>A^2=sum( [v[i] * r^i for i in range(3) ] )</p>
<p>gives me the solution:</p>
<p>(b1^2 + 2<em>b0</em>b2)<em>r^2 + (2</em>b0<em>b1 + 2</em>b2^2)<em>r + b0^2 + 4</em>b1*b2</p>
<p>result expressed in terms of powers of "r".</p>
http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32497#post-id-32497modified below
Mon, 08 Feb 2016 08:16:29 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32497#post-id-32497Comment by nd for <p>modified below</p>
http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?comment=32526#post-id-32526Perhaps this example might be more understandable. Take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".
I produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:
A^2 = b0^2 + (2*r) * b0 * b1 + (r^2) * b1^2 + (2*r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2
I want to express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:
A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )
I haven't found a method so far.
E.<r>=NumberField(x^3-2)
B=PolynomialRing(E,3,'b');v=B.gens()
A=sum( [v[i] * r^i for i in range(3) ] )Thu, 11 Feb 2016 03:44:44 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?comment=32526#post-id-32526Answer by vdelecroix for <p>I edited my question and put the answer I found, so this solves my problem!</p>
<p>My problem was: take a field " E " generated by " r " (here, "r" is a root of X^3 - 2 ) and 3 variables " b0 , b1 , b2 ".</p>
<p>I want to produce the element " A = b0 + r * b1 + r^2 * b2 " and it's square:</p>
<p>A^2 = b0^2 + (2<em>r) * b0 * b1 + (r^2) * b1^2 + (2</em>r^2) * b0 * b2 + 4 * b1 * b2 + (2*r) * b2^2</p>
<p>and express A and A^2 in terms of the basis "( 1 , r , r^2 )" so that the result becomes:</p>
<p>A^2 = r^2 ( b1^2 + 2 b0 * b2 ) + r ( 2 b0 * b1 + 2 b2^2 ) + ( b0^2 + b2^2 + b1 * b2 )</p>
<p>The solution was simply to define the number field as an extension of the ring of coefficients and the other way round! Good!</p>
<p>B=PolynomialRing(E,3,'b');</p>
<p>v=B.gens()</p>
<p>E.<r>=B.extension(x^3-2)</p>
<p>A^2=sum( [v[i] * r^i for i in range(3) ] )</p>
<p>gives me the solution:</p>
<p>(b1^2 + 2<em>b0</em>b2)<em>r^2 + (2</em>b0<em>b1 + 2</em>b2^2)<em>r + b0^2 + 4</em>b1*b2</p>
<p>result expressed in terms of powers of "r".</p>
http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32494#post-id-32494Here is a possibility to convert your polynomial P to the desired output
sage: R2 = QQ['x','y','z','t']['r']
sage: s = R2.zero()
sage: for c,m in zip(P.coefficients(),P.monomials()):
....: s += R2(c.polynomial('r')) * R2(m)
sage: print s
(y + 2*t)*r + x + 2*zMon, 08 Feb 2016 07:54:56 -0600http://ask.sagemath.org/question/32493/variables-in-a-polynomial/?answer=32494#post-id-32494