<hr>

### simple *sqrt*


```python
import math
import sympy 

math.sqrt(9)
math.sqrt(8)

sympy.sqrt(9)
sympy.sqrt(8)
sympy.sqrt(3)
```

### actual computation


```python
from sympy import *

x,t,z,nu = symbols('x t z nu')
init_printing(use_unicode=True)
```


```python
limit(sin(x)/x,x,0),
limit((3*x**2)/(x-3),x,3)
```


```python
diff(sin(x)),
diff(5*x**3,x),
diff(5*x**3,x,2)
```


```python
solve(x**2-10,x)
```

### *expand* / *factor*


```python
from sympy import symbols
from sympy import expand,factor

x,y = symbols('x y')
expr = x**2 + 2*y
```


```python
expr
expr + 1
expr - x
```


```python
expand(x*expr),
factor(x*expr)
```

### about *symbols*


```python
from sympy import *

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

x,y,z
```


```python
h = symbols('h')
expr = h ** 2

# a python variable 
h = 5

# the sympy symbol 'h'
expr * 2 
```


```python
x = symbols('x')
expr = x + 1

expr.subs(x,1)
expr
```


```python
# both '=' and '==' cannot be used in here!
Eq(1,1)
Eq(x**2+y**2,z**2)
Eq((x+1)**2,x**2+2*x+1)
```


```python
a = (x+1)**2
b = x**2 + 2*x + 1
c = x**2 - 2*x + 1

simplify(a-b)
simplify(a-c)
simplify(b-c)
```


```python
a = cos(x)**2 + sin(x)**2
b = a/a

a.equals(b)
a.equals(b+1)
```




    True






    False



### *type* thing


```python
type(1+1)
type(Integer(1)+1)

1+1 == Integer(1)+1
```




    int






    sympy.core.numbers.Integer






    True




```python
# Nah
1/3 , 1//3

# Oh yeah
1/Integer(3), 1//Integer(3)

Rational(1,3) == Integer(1)/3
```

<hr>

### basic opts

mostly subs


```python
from sympy import *
x,y,z = symbols('x y z')
```


```python
expr = cos(x) + 1

expr.subs(x,sin(0))
expr.subs(x,0)
expr.subs(x,expr.subs(x,0))
```


```python
expr = sin(2*x) + cos(2*x)

expand(expr)
expand_trig(expr)

expr.subs(sin(2*x),2*sin(x)*cos(x))
```


```python
expr = x**2 + y**2

expr.subs([(x,3),(y,4)])
expr.subs([(x,30),(y,40)])
```


```python
expr = x**4 - 4*x**3 + 4*x**2 - 2*x +3

# replace all inst of x that have an even power 
#     x**2 -> y**2
#     x**4 -> y**4 
replace_evenpow_as_y = [ (x**i,y**i) for i in range(5) if i %2 ==0 ]

expr
expr.subs(replace_evenpow_as_y)
```


```python
# do not confused with 'simplify' (down-below)
sympify("x**2+y**2")
sympify("x**2 + y**2").subs([(x,3),(y,4)])

simplify("(x+1)**2 + (x**2 + 2*x + 1)")
```

<hr>


```python
expr = sqrt(8)

expr
expr.evalf()
expr.evalf(20)
```


```python
expr = cos(2*x)

expr.evalf(subs={x:0})
expr.evalf(subs={x:pi/2})
expr.evalf(subs={x:pi/6})
```


```python
one = cos(x)**2

one.evalf(subs={x:pi/2})
one.evalf(subs={x:pi/2},chop=True)
```


```python
import numpy
a = numpy.arange(10)
```


```python
f = lambdify(x,sin(x))

f(-30)
f(30)
```


```python
f1 = lambdify(x,cos(x),"numpy")
f2 = lambdify(x,sin(x),"math")

f1(a)

f2(pi/6)
f2(pi/4)
f2(pi/3)
```

<hr>

### Printing


```python
from sympy import init_printing

# It'll enable the best printer available
init_printing(use_unicode=True)
```


```python
# Or you're in an interactive shell (ipython or qtconsole)
#   >> from sympy import init_session
#   >> init_session()
#   >> init_printing()

# See more at sympy.org
```

eef64102fd266f4f5304d8b3a56b69ca014b0650
ipynb
Jupyter Notebook
sympy-part01-intro.ipynb
codingEzio/code_python_learn_math
bd7869d05e1b4ec250cc5fa13470a960b299654e
Unlicense
sympy-part01-intro.ipynb
codingEzio/code_python_learn_math
bd7869d05e1b4ec250cc5fa13470a960b299654e
Unlicense
sympy-part01-intro.ipynb
codingEzio/code_python_learn_math
bd7869d05e1b4ec250cc5fa13470a960b299654e
Unlicense
Qwen/Qwen-72B
1. YES
2. YES