Some useful tidibts in sympy

Some useful tidibts in sympy
ML
Author

Nipun Batra

Published

November 9, 2022

from sympy import *
init_printing(use_unicode=True)
n, k = symbols("n k")
expr = Limit((1 + k/n)**n, n, oo)
expr

\(\displaystyle \lim_{n \to \infty} \left(\frac{k}{n} + 1\right)^{n}\)

expr.doit()

\(\displaystyle e^{k}\)

x, mu, sigma = symbols("x \mu \sigma")
norm  = exp(-(x-mu)**2/(2*sigma**2))
norm

\(\displaystyle e^{- \frac{\left(- \mu + x\right)^{2}}{2 \sigma^{2}}}\)

expr = integrate(norm, x)
norm

\(\displaystyle e^{- \frac{\left(- \mu + x\right)^{2}}{2 \sigma^{2}}}\)

simplify(expr)

\(\displaystyle - \frac{\sqrt{2} \sqrt{\pi} \sigma \operatorname{erf}{\left(\frac{\sqrt{2} \left(\mu - x\right)}{2 \sigma} \right)}}{2}\)