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 + (2r) * b0 * b1 + (r^2) * b1^2 + (2r^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 + 2b0b2)r^2 + (2b0b1 + 2b2^2)r + b0^2 + 4b1*b2

result expressed in terms of powers of "r".

edit retag close merge delete

Sort by » oldest newest most voted

Here 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*z
more