- var(...)
- File: sage/calculus/var.pyx (starting at line 4)
Create a symbolic variable with the name \emph{s}.
INPUT:
- ``s`` - a string, either a single variable name, or a space or
comma separated list of variable names.
.. note::
The new variable is both returned and automatically injected
into the global namespace. If you use var in library code, it
is better to use sage.calculus.calculus.var, since it won't
touch the global namespace.
EXAMPLES:
We define some symbolic variables::
sage: var('n xx yy zz')
(n, xx, yy, zz)
Then we make an algebraic expression out of them::
sage: f = xx^n + yy^n + zz^n; f
xx^n + yy^n + zz^n
We can substitute a new variable name for n::
sage: f(n = var('sigma'))
xx^sigma + yy^sigma + zz^sigma
If you make an important built-in variable into a symbolic variable,
you can get back the original value using restore::
sage: var('QQ RR')
(QQ, RR)
sage: QQ
QQ
sage: restore('QQ')
sage: QQ
Rational Field
We make two new variables separated by commas::
sage: var('theta, gamma')
(theta, gamma)
sage: theta^2 + gamma^3
gamma^3 + theta^2
The new variables are of type Expression, and belong
to the symbolic expression ring::
sage: type(theta)
<type 'sage.symbolic.expression.Expression'>
sage: parent(theta)
Symbolic Ring