# SymPy
The SymPy package is useful for symbolic algebra, much like the commercial software Mathematica.

We won't make much use of SymPy during the boot camp, but it is definitely useful to know about
for mathematics courses.


```python
import sympy as sp
sp.init_printing()
```

# Symbols and Expressions
We'll define `x` and `y` to be `sympy` symbols, then do some symbolic algebra.


```python
x, y = sp.symbols("x y")
```


```python
expression = (x+y)**4
```


```python
expression
```


```python
sp.expand(expression)
```


```python
expression = 8*x**2 + 26*x*y + 15*y**2
```


```python
expression
```


```python
sp.factor(expression)
```


```python
expression - 20 *x*y - 14*y**2
```


```python
sp.factor(expression - 20*x*y - 14*y**2)
```

# Lambdify: Making python functions from sympy expressions


```python
expression
```


```python
f = sp.lambdify((x,y), expression, 'numpy')
```


```python
f(3,4)
```


```python
8 * 3**2 + 26 * 3 * 4 + 15 * 4**2
```

# Calculus
You can use `sympy` to perform symbolic integration or differentiation.


```python
expression = 5*x**2 * sp.sin(3*x**3)
```


```python
expression
```


```python
expression.diff(x)
```


```python
expression = sp.cos(x)
```


```python
expression.integrate(x)
```


```python
expression.integrate((x, 0, sp.pi / 2))
```

You can also create unevalated integrals or derivatives. These can later be evaluated with their `doit` methods.


```python
deriv = sp.Derivative(expression)
```


```python
deriv
```


```python
deriv.doit()
```


```python
inte = sp.Integral(expression, (x, 0, sp.pi / 2))
```


```python
inte
```


```python
inte.doit()
```


```python

```

5b213d87f48f5062442b0930d5479d8a5e5f7ef2
ipynb
Jupyter Notebook
SymPyExample.ipynb
shumway/srt_bootcamp
c0b1cdc5f4fd57ac4f120e975842ea6bab2fa64b
MIT
2015-07-12T23:21:25.000Z
2015-07-15T04:51:37.000Z
SymPyExample.ipynb
shumway/srt_bootcamp
c0b1cdc5f4fd57ac4f120e975842ea6bab2fa64b
MIT
SymPyExample.ipynb
shumway/srt_bootcamp
c0b1cdc5f4fd57ac4f120e975842ea6bab2fa64b
MIT
Qwen/Qwen-72B
1. YES
2. YES