# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.13.6
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# %% [markdown]
# ---
# # <center><font color=purple>[SymPy](https://www.sympy.org/en/index.html)</font> </center>
# ---
#
# + [Tutorial](https://docs.sympy.org/latest/tutorial/index.html)

# %%
import sympy
import numpy as np
import matplotlib.pyplot as plt

# %%
x = sympy.symbols('x')

# %%
f = (x**2+1)/(x-1)

# %%
f

# %%
f.subs(x,2)

# %%
sympy.sqrt(2)

# %%
sympy.N(sympy.sqrt(2))

# %%
f = sympy.sin(x)
f

# %%
fx = sympy.lambdify(x,f, modules=['numpy'])

# %%

xVals = np.linspace(-10,10,100)

# %%
plt.plot(xVals,fx(xVals))

# %%
sympy.Integral(sympy.sqrt(1/x)+sympy.exp(x),x )

# %%
f = sympy.sin(x)**2 + sympy.cos(x)**2
f

# %%
f.simplify()

# %%
f = (x**3 + x**2 -x -1)/(x**2 + 2*x + 1)
f

# %%
f.simplify()

# %%
f = (x+1)**2

# %%
f.expand()

# %%
sympy.factor(x**3 - x**2 + x - 1)

# %%
sympy.simplify(x**3 - x**2 + x - 1)

# %%
x, y, z = sympy.symbols('x y z')

# %%
f = x*y + x - 3 + 2*x**2 - z*x**2 + x**3

# %%
sympy.pprint(f)

# %%
sympy.collect(f, x)

# %%
f = (x**2 + 2*x+ 1)/(x**2 + x)

# %%
sympy.cancel(f)

# %%
sympy.simplify(f)

# %%
f = sympy.cos(x)

# %%
df = sympy.diff(f, x,2 )
df

# %%
f = x*y*z + 2*x*y**2 + 3*sympy.exp(y+z)

# %%
sympy.diff(f,x,y)

# %%
f = sympy.exp(-x)

# %%
sympy.integrate(f,(x,0,-sympy.oo))

# %%

# %%
sympy.solveset(sympy.Eq(x**2,1),x)

# %%
sympy.solveset(sympy.sin(x)-1,x)

# %%
sympy.solveset(sympy.exp(x),x)

# %%
sympy.solveset(sympy.cos(x)-x,x)

# %%
sympy.linsolve([x+y+z-1,x+y+2*z-3,2*x+y-z-10],(x,y,z))

# %%
f1 = x+y+z-1
f2 = x+y+2*z-3
f3 = 2*x+y-z-10

f1.subs(x,13).subs(y,-14).subs(z,2)

# %%
