EXAMPLES:
This should be called when coercing or converting a NumPy float or complex to the Symbolic Ring:
sage: import numpy
sage: SR(numpy.float64('2.0')).pyobject().parent()
Real Double Field
Symbolic Ring, parent object for all symbolic expressions.
EXAMPLES:
sage: loads(dumps(SR)) == SR # indirect doctest
True
Return an element of the symbolic ring, which is used by the coercion model.
EXAMPLES:
sage: SR._an_element_()
some_variable
EXAMPLES:
sage: x,y=var('x,y')
sage: f = x+y
sage: f.variables()
(x, y)
sage: f()
x + y
sage: f(3)
doctest:...: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
y + 3
sage: f(x=3)
y + 3
sage: f(3,4)
7
sage: f(x=3,y=4)
7
sage: f(2,3,4)
...
ValueError: the number of arguments must be less than or equal to 2
sage: f(x=2,y=3,z=4)
5
sage: f({x:3})
y + 3
sage: f({x:3,y:4})
7
sage: f(x=3)
y + 3
sage: f(x=3,y=4)
7
sage: a = (2^(8/9))
sage: a(4)
...
ValueError: the number of arguments must be less than or equal to 0
Note that you make get unexpected results when calling symbolic expressions and not explicitly giving the variables:
sage: f = function('Gamma', var('z'), var('w')); f
Gamma(z, w)
sage: f(2)
Gamma(z, 2)
sage: f(2,5)
Gamma(5, 2)
Thus, it is better to be explicit:
sage: f(z=2)
Gamma(2, w)
EXAMPLES:
sage: SR.coerce(int(2))
2
sage: SR.coerce(pari(2/5))
2/5
sage: SR.coerce(-infinity)
-Infinity
sage: SR.has_coerce_map_from(ZZ['t'])
True
sage: SR.has_coerce_map_from(ZZ['t,u,v'])
True
sage: SR.has_coerce_map_from(Frac(ZZ['t,u,v']))
True
sage: SR.has_coerce_map_from(GF(5)['t'])
True
sage: SR.has_coerce_map_from(SR['t'])
False
sage: SR.has_coerce_map_from(Integers(8))
True
sage: SR.has_coerce_map_from(GF(9, 'a'))
True
Coerce into the symbolic expression ring SR.
EXAMPLES:
sage: a = SR(-3/4); a
-3/4
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
sage: a.parent()
Symbolic Ring
sage: K.<a> = QuadraticField(-3)
sage: a + sin(x)
I*sqrt(3) + sin(x)
sage: x=var('x'); y0,y1=PolynomialRing(ZZ,2,'y').gens()
sage: x+y0/y1
x + y0/y1
sage: x.subs(x=y0/y1)
y0/y1
sage: x + long(1)
x + 1
If is already in the symbolic expression ring, coercing returns
itself (not a copy):
sage: a = SR(-3/4); a
-3/4
sage: SR(a) is a
True
A Python complex number:
sage: SR(complex(2,-3))
2.00000000000000 - 3.00000000000000*I
TESTS:
sage: SR._coerce_(int(5))
5
sage: SR._coerce_(5)
5
sage: SR._coerce_(float(5))
5.00000000000000
sage: SR._coerce_(5.0)
5.00000000000000
An interval arithmetic number:
sage: SR._coerce_(RIF(pi))
3.141592653589794?
A number modulo 7:
sage: a = SR(Mod(3,7)); a
3
sage: a^2
2
sage: si = SR.coerce(I)
sage: si^2
-1
sage: bool(si == CC.0)
True
Return latex representation of the symbolic ring.
EXAMPLES:
sage: latex(SR)
ext{SR}
sage: M = MatrixSpace(SR, 2); latex(M)
\mathrm{Mat}_{2 imes 2}( ext{SR})
Returns the standard LaTeX version of the expression x.
EXAMPLES:
sage: latex(sin(x+2)) \sin\left(x + 2
Return a string representation of self.
EXAMPLES:
sage: repr(SR)
'Symbolic Ring'
Returns the string representation of the element x. This is used so that subclasses of the SymbolicRing (such the a CallableSymbolicExpressionRing) can provide their own implementations of how to print Expressions.
EXAMPLES:
sage: SR._repr_element_(x+2)
'x + 2'
Return the characteristic of the symbolic ring, which is 0.
OUTPUT:
EXAMPLES:
sage: c = SR.characteristic(); c
0
sage: type(c)
<type 'sage.rings.integer.Integer'>
Return False, because there are approximate elements in the symbolic ring.
EXAMPLES:
sage: SR.is_exact()
False
Here is an inexact element.
sage: SR(1.9393)
1.93930000000000
Returns True, since the symbolic expression ring is (for the most part) a field.
EXAMPLES:
sage: SR.is_field()
True
EXAMPLES:
sage: SR.pi() is pi
True
EXAMPLES:
sage: SR.symbol("asdfasdfasdf")
asdfasdfasdf
Return the symbolic variable defined by x as an element of the symbolic ring.
EXAMPLES:
sage: zz = SR.var('zz'); zz
zz
sage: type(zz)
<type 'sage.symbolic.expression.Expression'>
sage: t = SR.var('theta2'); t
theta2
Return the n-th wild-card for pattern matching and substitution.
INPUT:
OUTPUT:
EXAMPLES:
sage: x,y = var('x,y')
sage: w0 = SR.wild(0); w1 = SR.wild(1)
sage: pattern = sin(x)*w0*w1^2; pattern
$0*$1^2*sin(x)
sage: f = atan(sin(x)*3*x^2); f
arctan(3*x^2*sin(x))
sage: f.has(pattern)
True
sage: f.subs(pattern == x^2)
arctan(x^2)
EXAMPLES:
This should be called when coercing or converting a SymPy object to the Symbolic Ring:
sage: import sympy
sage: b = sympy.var('b')
sage: bool(SR(b) == SR(b._sage_()))
True
Returns True if R is the symbolic expression ring.
EXAMPLES:
sage: from sage.symbolic.ring import is_SymbolicExpressionRing
sage: is_SymbolicExpressionRing(ZZ)
False
sage: is_SymbolicExpressionRing(SR)
True
Returns True if x is a variable.
EXAMPLES:
sage: from sage.symbolic.ring import is_SymbolicVariable
sage: is_SymbolicVariable(x)
True
sage: is_SymbolicVariable(x+2)
False
Return the unique symbolic ring object.
(This is mainly used for unpickling.)
EXAMPLES:
sage: sage.symbolic.ring.the_SymbolicRing()
Symbolic Ring
sage: sage.symbolic.ring.the_SymbolicRing() is sage.symbolic.ring.the_SymbolicRing()
True
sage: sage.symbolic.ring.the_SymbolicRing() is SR
True
EXAMPLES:
sage: from sage.symbolic.ring import var
sage: var("x y z")
(x, y, z)
sage: var("x,y,z")
(x, y, z)
sage: var("x , y , z")
(x, y, z)
sage: var("z")
z