Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

From what program are you importing your expression? Many algebra systems have a function which lists the variables in an expression. You can use it to generate the necessary variables for you expression before evaluating it.

For example, in Maple:

a := 5*x-3*sin(y)+x*y^4+exp(z^2):
indets(a,name);
                                  {x, y, z}

You can give this output (without the braces) to sage's var and then evaluate the expression.

Also, if your expression is maxima compatible you can use maxima's command, which is listofvars, inside sage. Using sage_eval's cmds parameter you can order it to parse the expression in maxima and create the variables:

sage: a = "5*x-3*sin(y)+x*y^4+exp(z^2)"
sage: sage_eval(a,cmds="var(','.join(map(repr, maxima('listofvars(%s)'))))"%a)
x*y^4 + 5*x + e^(z^2) - 3*sin(y)

This is of course a workaround - autodeclaration would be awesome but is probably not very near (see also here).