First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 0 years ago

Max Alekseyev gravatar image

You have two different x in your code - one is a symbolic variable defined by x = var('x') and another is a polynomial variable (generator of R). For example, in (8.5*pi^4 + 0.166*pi^2*x^2)*x, the x inside the parentheses is symbolic, while the one outside is polynomial. When you convert a symbolic expression (even if it involves symbolic x) into R, Sage interprets it as a scalar and turns it into a polynomial of degree 0. Here is a simple example:

sage: x = var('x')
sage: R = PolynomialRing(SR, x)
sage: R(x+pi*x^2)
pi*x^2 + x
sage: _.dict()
{0: pi*x^2 + x}

If your goal is to recognize x inside a symbolic expression and turn it into a polynomial variable, then you can do via converting the expression into a string first:

sage: R(str(x+pi*x^2))
pi*x^2 + x
sage: _.dict()
{1: 1, 2: pi}
click to hide/show revision 2
No.2 Revision

You have two different x in your code - one is a symbolic variable defined by x = var('x') and another is a polynomial variable (generator of R). For example, in (8.5*pi^4 + 0.166*pi^2*x^2)*x, the x inside the parentheses is symbolic, while the one outside is polynomial. When you convert a symbolic expression (even if it involves symbolic x) into R, Sage interprets it as a scalar and turns it into a polynomial of degree 0. Here is a simple example:

sage: x = var('x')
sage: R = PolynomialRing(SR, x)
sage: R(x+pi*x^2)
pi*x^2 + x
sage: _.dict()
{0: pi*x^2 + x}

If your goal is to recognize x inside a symbolic expression and turn it into a polynomial variable, then you can do so via converting the expression into a string first:

sage: R(str(x+pi*x^2))
pi*x^2 + x
sage: _.dict()
{1: 1, 2: pi}