```python
import sympy
```


```python
x = sympy.Symbol('x')
y = sympy.Symbol('y')
```


```python
print(type(x))
```

    <class 'sympy.core.symbol.Symbol'>



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

print(expr)
```

    x**2 + y + 1



```python
z = sympy.Symbol('ZZZZ')
```


```python
expr_z = z**2 + 3 * z

print(expr_z)
```

    ZZZZ**2 + 3*ZZZZ



```python
print(expr)
```

    x**2 + y + 1



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

    y + 2



```python
print(expr.subs(x, y))
```

    y**2 + y + 1



```python
print(expr.subs([(x, 1), (y, 2)]))
```

    4



```python
expr = (x + 1)**2
```


```python
print(expr)
```

    (x + 1)**2



```python
expr_ex = sympy.expand(expr)
```


```python
print(expr_ex)
```

    x**2 + 2*x + 1



```python
expr_factor = sympy.factor(expr_ex)
```


```python
print(expr_factor)
```

    (x + 1)**2



```python
print(sympy.factor(x**3 - x**2 - 3 * x + 3))
```

    (x - 1)*(x**2 - 3)



```python
print(sympy.factor(x * y + x + y + 1))
```

    (x + 1)*(y + 1)



```python
print(sympy.solve(x**2 - 3 * x + 2))
```

    [1, 2]



```python
print(sympy.solve(x**2 + x + 1))
```

    [-1/2 - sqrt(3)*I/2, -1/2 + sqrt(3)*I/2]



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


```python
print(sympy.solve(expr, x))
```

    [-y**2 + 4]



```python
print(sympy.solve(expr, y))
```

    [-sqrt(-x + 4), sqrt(-x + 4)]



```python
expr1 = 3 * x + 5 * y - 29
expr2 = x + y - 7

print(sympy.solve([expr1, expr2]))
```

    {x: 3, y: 4}



```python
print(sympy.diff(x**3 + 2 * x**2 + x))
```

    3*x**2 + 4*x + 1



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


```python
print(sympy.diff(expr, x))
```

    3*x**2



```python
print(sympy.diff(expr, y))
```

    2*y - 1



```python
print(sympy.integrate(3 * x**2 + 4 * x + 1))
```

    x**3 + 2*x**2 + x



```python
print(sympy.diff(sympy.cos(x)))
```

    -sin(x)



```python
print(sympy.diff(sympy.exp(x)))
```

    exp(x)



```python
print(sympy.diff(sympy.log(x)))
```

    1/x



```python
print(sympy.integrate(sympy.cos(x)))
```

    sin(x)



```python
print(sympy.integrate(sympy.exp(x)))
```

    exp(x)



```python
print(sympy.integrate(sympy.log(x)))
```

    x*log(x) - x


839892cb2cd090028d539bdc90910078cf55e471
ipynb
Jupyter Notebook
notebook/sympy_basic.ipynb
vhn0912/python-snippets
80b2e1d6b2b8f12ae30d6dbe86d25bb2b3a02038
MIT
2018-05-30T21:14:50.000Z
2022-03-25T07:59:37.000Z
notebook/sympy_basic.ipynb
vhn0912/python-snippets
80b2e1d6b2b8f12ae30d6dbe86d25bb2b3a02038
MIT
2019-08-10T03:22:02.000Z
2021-07-12T20:31:17.000Z
notebook/sympy_basic.ipynb
vhn0912/python-snippets
80b2e1d6b2b8f12ae30d6dbe86d25bb2b3a02038
MIT
2018-04-27T05:26:35.000Z
2022-03-25T07:59:37.000Z
Qwen/Qwen-72B
1. YES
2. YES