Source code for ddg.math.functions

"""Basic functions and math expressions.
"""

import mpmath
import scipy as sp


[docs]def qgamma(z, q): """A generalised variant of :func:`mpmath.qgamma`. Unlike :func:`mpmath.qgamma`, this function returns infinity instead of raising a `ZeroDivisionError`. Parameters ---------- z : complex or mpmath.mpf q : complex or mpmath.mpf Returns ------- mpmath.mpf """ try: g = mpmath.qgamma(z, q) except ZeroDivisionError: g = mpmath.mpf("inf") return g
[docs]def double_factorial(n): """The double factorial function. .. math :: \\text{double_factorial}(n) = \\begin{cases} n \\cdot \\text{double_factorial}(n - 2) &\\text{ if } n \\ge 2 \\\\ 1 &\\text{ otherwise}. \\end{cases} Parameters ---------- n : int Returns ------- int """ if n < 2: return 1 return n * double_factorial(n - 2)
[docs]def sn(u, k): return sp.special.ellipj(u, k**2)[0]
[docs]def cn(u, k): return sp.special.ellipj(u, k**2)[1]
[docs]def dn(u, k): return sp.special.ellipj(u, k**2)[2]
[docs]def ns(u, k): return 1 / sn(u, k)
[docs]def nc(u, k): return 1 / cn(u, k)
[docs]def nd(u, k): return 1 / dn(u, k)
[docs]def sc(u, k): return sn(u, k) / cn(u, k)
[docs]def sd(u, k): return sn(u, k) / dn(u, k)
[docs]def dc(u, k): return dn(u, k) / cn(u, k)
[docs]def ds(u, k): return dn(u, k) / sn(u, k)
[docs]def cs(u, k): return cn(u, k) / sn(u, k)
[docs]def cd(u, k): return cn(u, k) / dn(u, k)
[docs]def K(k): return sp.special.ellipk(k**2)