---
author: Nathan Carter (ncarter@bentley.edu)
---

This answer assumes you have imported SymPy as follows.



```python
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output
```


| Mathematical notation | Python code | Requires SymPy? |
|--|--|--|
| $x+y$ | `x+y` | no |
| $x-y$ | `x-y` | no |
| $xy$ | `x*y` | no |
| $\frac xy$ | `x/y` | no |
| $\left\lfloor\frac xy\right\rfloor$ | `x//y` | no |
| remainder of $x\div y$ | `x%y` | no |
| $x^y$ | `x**y` | no |
| $\vert x\vert$ | `abs(x)` | no |
| $\ln x$ | `log(x)` | yes |
| $\log_a b$ | `log(b,a)` | yes |
| $e^x$ | `E` | yes |
| $\pi$ | `pi` | yes |
| $\sin x$ | `sin(x)` | yes |
| $\sin^{-1} x$ | `asin(x)` | yes |
| $\sqrt x$ | `sqrt(x)` | yes |

Other trigonometric functions are also available besides just `sin`,
including `cos`, `tan`, etc.

Note that SymPy gives precise answers to mathematical queries,
which may not be what you want.



```python
sqrt(2)
```




$\displaystyle \sqrt{2}$



If you want a decimal approximation instead, you can use the `N` function.


```python
N(sqrt(2))
```




$\displaystyle 1.4142135623731$



Or you can use the `evalf` function.


```python
sqrt(2).evalf()
```




$\displaystyle 1.4142135623731$



By contrast, if you need an exact rational number when Python gives you
an approximation, you can use the `Rational` function to build one.
Note the differences below:


```python
1/3
```




$\displaystyle 0.333333333333333$




```python
Rational(1,3)
```




$\displaystyle \frac{1}{3}$



db9e8c44739005b10ebd9894adb10eac29091fe2
ipynb
Jupyter Notebook
database/tasks/How to do basic mathematical computations/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to do basic mathematical computations/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to do basic mathematical computations/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
2021-07-18T19:01:29.000Z
2022-03-29T06:47:11.000Z
Qwen/Qwen-72B
1. YES
2. YES