# Let's Do Some Algebra
In a Jupyter notebook, with sympy.


```python
# First we import sympy:
from sympy import *

# Init pretty printing
init_printing()
```


```python
# Then we define some symbols:
x, a, b, c, d = symbols('x, a, b, c, d')
```


```python
# Write some expressions with our symbols:
expr1 = a + x * c
d = (b - a)

# Do some substitution:
expr2 = expr1.subs(c, d)
```


```python
expr1 # Looks like:
```


```python
expr2 # Looks like:
```


```python
# Which looks familiar
# Not sure why -a + b rather than b - a, but that's easily fixed later

# As C code:
ccode(expr2)
```




    'a + x*(-a + b)'




```python
# Equation time!

u = symbols('u')
eq = Eq(u, expr2)

eq
```


```python
# Solve for x
sol = solve((eq),(x))

# Output
sol
```


```python
# As code
ccode(sol)
```




    '[(a - u)/(a - b)]'



The "inverse" of the linear interpolation formula!

Easy enough to do by hand, but for demonstration purposes...


This could be useful.

8d5f17f0ec3a52a32e742593a6ba572c7a7d46f1
ipynb
Jupyter Notebook
JupyterAlgebraTest.ipynb
ErnstHot/Jupyter
bcaf5dde1411e8024f41802bc78f1bf6f7cb73e5
MIT
JupyterAlgebraTest.ipynb
ErnstHot/Jupyter
bcaf5dde1411e8024f41802bc78f1bf6f7cb73e5
MIT
JupyterAlgebraTest.ipynb
ErnstHot/Jupyter
bcaf5dde1411e8024f41802bc78f1bf6f7cb73e5
MIT
Qwen/Qwen-72B
1. YES
2. YES