ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 08 Feb 2016 06:48:10 -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".
ndMon, 08 Feb 2016 06:48:10 -0600http://ask.sagemath.org/question/32493/Creating an array of variableshttp://ask.sagemath.org/question/8390/creating-an-array-of-variables/Here is a very very basic question.
I want to create a polynomial, say
a_0*x^0 + a_1*x + a_2*x^2+ \cdots + a_{20} x^{20}.
I could define these a_i one at a time, but it would be much better to have a way to create an array A of length 20 where A[i] is the coefficient a_i. The idea is that I want to do some operations and solve for these coefficients, which will end up being rational numbers.
There must be some very basic command that I don't know, but I can't find it in the documentation.NathanMon, 17 Oct 2011 05:16:43 -0500http://ask.sagemath.org/question/8390/