SymPy is a pure Python package for symbolic mathematics.

In [ ]:

```
from sympy import *
init_printing()
```

To deal with symbolic variables, we need to declare them.

In [ ]:

```
var('x y')
```

In [ ]:

```
x, y = symbols('x y')
```

We can create mathematical expressions with these symbols.

In [ ]:

```
expr1 = (x + 1)**2
expr2 = x**2 + 2*x + 1
```

Are these expressions equal?

In [ ]:

```
expr1 == expr2
```

In [ ]:

```
simplify(expr1-expr2)
```

In [ ]:

```
expr1.subs(x, expr1)
```

In [ ]:

```
expr1.subs(x, pi)
```

In [ ]:

```
expr1.subs(x, S(1)/2)
```

Exactly-represented numbers can be evaluated numerically with evalf:

In [ ]:

```
_.evalf()
```

*symbolic* function into an actual Python function that can be evaluated on NumPy arrays, using the `lambdify`

function.

In [ ]:

```
f = lambdify(x, expr1)
```

In [ ]:

```
import numpy as np
f(np.linspace(-2., 2., 5))
```

You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).

IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).