Ask Your Question

Revision history [back]

To convert a string to an expression in Sage's symbolic ring, use `SR(expression)'.

Here is how it would work with your example.

sage: x1, x2, x3 = SR.var('x1 x2 x3')
sage: expression = "x1^2*x2*x3*4" 
sage: ex = SR(expression)
sage: ex
4*x1^2*x2*x3

To convert a string expression to an any parent X in Sage, you could do X(expression).

Thus, to convert the expression in to Sage's symbolic ring, use `SR(expression)'.SR(expression).

Here is how it would work with your example.

sage: x1, x2, x3 = SR.var('x1 x2 x3')
sage: expression = "x1^2*x2*x3*4" 
sage: ex = SR(expression)
sage: ex
4*x1^2*x2*x3

If you prefer to work with a polynomial ring:

sage: P.<x1, x2, x3> = QQ[]
sage: f = P(expression)
sage: f
4*x1^2*x2*x3