# Constructor for symbolic expressions#

sage.calculus.expr.symbolic_expression(x)[source]#

Create a symbolic expression or vector of symbolic expressions from x.

INPUT:

• `x` - an object

OUTPUT:

• a symbolic expression.

EXAMPLES:

```sage: a = symbolic_expression(3/2); a
3/2
sage: type(a)
<class 'sage.symbolic.expression.Expression'>
sage: R.<x> = QQ[]; type(x)
<class 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>
sage: a = symbolic_expression(2*x^2 + 3); a
2*x^2 + 3
sage: type(a)
<class 'sage.symbolic.expression.Expression'>
sage: from sage.structure.element import Expression
sage: isinstance(a, Expression)
True
sage: a in SR
True
sage: a.parent()
Symbolic Ring
```
```>>> from sage.all import *
>>> a = symbolic_expression(Integer(3)/Integer(2)); a
3/2
>>> type(a)
<class 'sage.symbolic.expression.Expression'>
>>> R = QQ['x']; (x,) = R._first_ngens(1); type(x)
<class 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>
>>> a = symbolic_expression(Integer(2)*x**Integer(2) + Integer(3)); a
2*x^2 + 3
>>> type(a)
<class 'sage.symbolic.expression.Expression'>
>>> from sage.structure.element import Expression
>>> isinstance(a, Expression)
True
>>> a in SR
True
>>> a.parent()
Symbolic Ring
```

Note that equations exist in the symbolic ring:

```sage: # needs sage.schemes
sage: E = EllipticCurve('15a'); E
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
sage: symbolic_expression(E)
x*y + y^2 + y == x^3 + x^2 - 10*x - 10
sage: symbolic_expression(E) in SR
True
```
```>>> from sage.all import *
>>> # needs sage.schemes
>>> E = EllipticCurve('15a'); E
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
>>> symbolic_expression(E)
x*y + y^2 + y == x^3 + x^2 - 10*x - 10
>>> symbolic_expression(E) in SR
True
```

If `x` is a list or tuple, create a vector of symbolic expressions:

```sage: v = symbolic_expression([x,1]); v
(x, 1)
sage: v.base_ring()
Symbolic Ring
sage: v = symbolic_expression((x,1)); v
(x, 1)
sage: v.base_ring()
Symbolic Ring
sage: v = symbolic_expression((3,1)); v
(3, 1)
sage: v.base_ring()
Symbolic Ring
sage: E = EllipticCurve('15a'); E
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
sage: v = symbolic_expression([E,E]); v
(x*y + y^2 + y == x^3 + x^2 - 10*x - 10, x*y + y^2 + y == x^3 + x^2 - 10*x - 10)
sage: v.base_ring()
Symbolic Ring
```
```>>> from sage.all import *
>>> v = symbolic_expression([x,Integer(1)]); v
(x, 1)
>>> v.base_ring()
Symbolic Ring
>>> v = symbolic_expression((x,Integer(1))); v
(x, 1)
>>> v.base_ring()
Symbolic Ring
>>> v = symbolic_expression((Integer(3),Integer(1))); v
(3, 1)
>>> v.base_ring()
Symbolic Ring
>>> E = EllipticCurve('15a'); E
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
>>> v = symbolic_expression([E,E]); v
(x*y + y^2 + y == x^3 + x^2 - 10*x - 10, x*y + y^2 + y == x^3 + x^2 - 10*x - 10)
>>> v.base_ring()
Symbolic Ring
```

Likewise, if `x` is a vector, create a vector of symbolic expressions:

```sage: u = vector([1, 2, 3])
sage: v = symbolic_expression(u); v
(1, 2, 3)
sage: v.parent()
Vector space of dimension 3 over Symbolic Ring
```
```>>> from sage.all import *
>>> u = vector([Integer(1), Integer(2), Integer(3)])
>>> v = symbolic_expression(u); v
(1, 2, 3)
>>> v.parent()
Vector space of dimension 3 over Symbolic Ring
```

If `x` is a list or tuple of lists/tuples/vectors, create a matrix of symbolic expressions:

```sage: M = symbolic_expression([[1, x, x^2], (x, x^2, x^3), vector([x^2, x^3, x^4])]); M
[  1   x x^2]
[  x x^2 x^3]
[x^2 x^3 x^4]
sage: M.parent()
Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring
```
```>>> from sage.all import *
>>> M = symbolic_expression([[Integer(1), x, x**Integer(2)], (x, x**Integer(2), x**Integer(3)), vector([x**Integer(2), x**Integer(3), x**Integer(4)])]); M
[  1   x x^2]
[  x x^2 x^3]
[x^2 x^3 x^4]
>>> M.parent()
Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring
```

If `x` is a matrix, create a matrix of symbolic expressions:

```sage: A = matrix([[1, 2, 3], [4, 5, 6]])
sage: B = symbolic_expression(A); B
[1 2 3]
[4 5 6]
sage: B.parent()
Full MatrixSpace of 2 by 3 dense matrices over Symbolic Ring
```
```>>> from sage.all import *
>>> A = matrix([[Integer(1), Integer(2), Integer(3)], [Integer(4), Integer(5), Integer(6)]])
>>> B = symbolic_expression(A); B
[1 2 3]
[4 5 6]
>>> B.parent()
Full MatrixSpace of 2 by 3 dense matrices over Symbolic Ring
```

If `x` is a function, for example defined by a `lambda` expression, create a symbolic function:

```sage: f = symbolic_expression(lambda z: z^2 + 1); f
z |--> z^2 + 1
sage: f.parent()
Callable function ring with argument z
sage: f(7)
50
```
```>>> from sage.all import *
>>> f = symbolic_expression(lambda z: z**Integer(2) + Integer(1)); f
z |--> z^2 + 1
>>> f.parent()
Callable function ring with argument z
>>> f(Integer(7))
50
```

If `x` is a list or tuple of functions, or if `x` is a function that returns a list or tuple, create a callable symbolic vector:

```sage: symbolic_expression([lambda mu, nu: mu^2 + nu^2, lambda mu, nu: mu^2 - nu^2])
(mu, nu) |--> (mu^2 + nu^2, mu^2 - nu^2)
sage: f = symbolic_expression(lambda uwu: [1, uwu, uwu^2]); f
uwu |--> (1, uwu, uwu^2)
sage: f.parent()
Vector space of dimension 3 over Callable function ring with argument uwu
sage: f(5)
(1, 5, 25)
sage: f(5).parent()
Vector space of dimension 3 over Symbolic Ring
```
```>>> from sage.all import *
>>> symbolic_expression([lambda mu, nu: mu**Integer(2) + nu**Integer(2), lambda mu, nu: mu**Integer(2) - nu**Integer(2)])
(mu, nu) |--> (mu^2 + nu^2, mu^2 - nu^2)
>>> f = symbolic_expression(lambda uwu: [Integer(1), uwu, uwu**Integer(2)]); f
uwu |--> (1, uwu, uwu^2)
>>> f.parent()
Vector space of dimension 3 over Callable function ring with argument uwu
>>> f(Integer(5))
(1, 5, 25)
>>> f(Integer(5)).parent()
Vector space of dimension 3 over Symbolic Ring
```