### Install mpmath from source Source: https://mpmath.org/doc/current/setup.html Install mpmath by downloading the source package, extracting it, and running the setup script. ```bash python setup.py install ``` -------------------------------- ### Install mpmath using easy_install Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Install mpmath using easy_install if setuptools is available. Use the -U flag to force an upgrade. ```bash easy_install mpmath ``` ```bash python -m easy_install mpmath ``` -------------------------------- ### Initialize mpmath settings Source: https://mpmath.org/doc/current/functions/hypergeometric.html Sets the decimal precision and pretty-printing for mpmath. This is a common setup for examples. ```python from mpmath import * mp.dps = 25; mp.pretty = True a = mpf(0.75) b = mpf(1.5) z = mpf(2.25) ``` -------------------------------- ### Install mpmath on Debian/Ubuntu Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Install mpmath on Debian or Ubuntu systems using the apt-get package manager. ```bash sudo apt-get install python-mpmath ``` -------------------------------- ### Verify mpmath installation and basic usage Source: https://mpmath.org/doc/current/_sources/setup.rst.txt After installation, verify mpmath works by importing it, setting decimal places, and performing calculations. ```python from mpmath import * mp.dps = 50 print(mpf(2) ** mpf('0.5')) ``` ```python print(2*pi) ``` -------------------------------- ### Install mpmath using pip Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Use pip to install the latest release of mpmath. For specific versions, append '==version_number'. ```bash pip install mpmath ``` ```bash pip install mpmath==0.19 ``` -------------------------------- ### Example: hyper2d() with closed-form series Source: https://mpmath.org/doc/current/functions/hypergeometric.html Shows an example of hyper2d() that can be evaluated in closed form. Requires mpmath to be imported. ```python >>> hyper2d({'m':1,'n':1},{'m+n':1},x,y) 2.013417124712514809623881 >>> (exp(x)*x-exp(y)*y)/(x-y) 2.013417124712514809623881 ``` -------------------------------- ### Verify mpmath installation Source: https://mpmath.org/doc/current/setup.html Check if the mpmath library is installed and working correctly by performing calculations in the Python interpreter. ```python >>> from mpmath import * >>> mp.dps = 50 >>> print(mpf(2) ** mpf('0.5')) 1.4142135623730950488016887242096980785696718753769 >>> print(2*pi) 6.2831853071795864769252867665590057683943387987502 ``` -------------------------------- ### Incomplete Elliptic Integral Pi(n,z,m) Examples Source: https://mpmath.org/doc/current/functions/elliptic.html Provides examples for basic values, limits, and comparisons with other functions for the incomplete elliptic integral of the third kind. Supports complex arguments and quasi-periodic extension. ```python >>> ellippi(0.25,-0.5); ellippi(0.25,pi/2,-0.5) 1.622944760954741603710555 1.622944760954741603710555 >>> ellippi(1,0,1) 0.0 >>> ellippi(inf,0,1) 0.0 >>> ellippi(0,0.25,0.5); ellipf(0.25,0.5) 0.2513040086544925794134591 0.2513040086544925794134591 >>> ellippi(1,1,1); (log(sec(1)+tan(1))+sec(1)*tan(1))/2 2.054332933256248668692452 2.054332933256248668692452 >>> ellippi(0.25, 53*pi/2, 0.75); 53*ellippi(0.25,0.75) 135.240868757890840755058 135.240868757890840755058 >>> ellippi(0.5,pi/4,0.5); 2*ellipe(pi/4,0.5)-1/sqrt(3) 0.9190227391656969903987269 0.9190227391656969903987269 ``` ```python >>> ellippi(0.5, 5+6j-2*pi, -7-8j) (-0.3612856620076747660410167 + 0.5217735339984807829755815j) ``` ```python >>> ellippi(1,1) +inf >>> ellippi(1,0) +inf >>> ellippi(1,2,0) +inf >>> ellippi(1,2,1) +inf >>> ellippi(1,0,1) 0.0 ``` -------------------------------- ### Compute Logarithmic Integrals Source: https://mpmath.org/doc/current/functions/expintegrals.html Examples demonstrating basic values, limits, complex arguments, and the offset logarithmic integral. ```python >>> from mpmath import * >>> mp.dps = 30; mp.pretty = True >>> li(0) 0.0 >>> li(1) -inf >>> li(1) -inf >>> li(2) 1.04516378011749278484458888919 >>> findroot(li, 2) 1.45136923488338105028396848589 >>> li(inf) +inf >>> li(2, offset=True) 0.0 >>> li(1, offset=True) -inf >>> li(0, offset=True) -1.04516378011749278484458888919 >>> li(10, offset=True) 5.12043572466980515267839286347 ``` ```python >>> mp.dps = 20 >>> li(3+4j) (3.1343755504645775265 + 2.6769247817778742392j) ``` ```python >>> ei(log(3)) 2.1635885946671919729 >>> li(3) 2.1635885946671919729 ``` ```python >>> mp.dps = 15 >>> x = 10**100 >>> x/log(x) 4.34294481903252e+97 >>> li(x) 4.3619719871407e+97 ``` ```python >>> li(10**23, offset=True) 1.92532039161405e+21 ``` ```python >>> quad(li, [0, 1]) -0.693147180559945 >>> -ln(2) -0.693147180559945 ``` -------------------------------- ### Basic AiryBi function examples Source: https://mpmath.org/doc/current/functions/bessel.html Demonstrates basic evaluation of the `airybi` function for real and complex arguments, including limits. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> airybi(0); 1/(power(3,'1/6')*gamma('2/3')) 0.6149266274460007351509224 0.6149266274460007351509224 >>> airybi(1) 1.207423594952871259436379 >>> airybi(-1) 0.10399738949694461188869 >>> airybi(inf); airybi(-inf) +inf 0.0 ``` ```python >>> airybi(-100) 0.02427388768016013160566747 >>> airybi(100) 6.041223996670201399005265e+288 >>> airybi(50+50j) (-5.322076267321435669290334e+63 + 1.478450291165243789749427e+65j) >>> airybi(-50+50j) (-3.347525544923600321838281e+157 + 1.041242537363167632587245e+158j) ``` ```python >>> airybi(10**10) 1.369385787943539818688433e+289529654602165 >>> airybi(-10**10) 0.001775656141692932747610973 >>> w = airybi(10**10*(1+j)) >>> w.real -6.559955931096196875845858e+186339621747689 >>> w.imag -6.822462726981357180929024e+186339621747690 ``` -------------------------------- ### Complete Elliptic Integral E(z,m) Examples Source: https://mpmath.org/doc/current/functions/elliptic.html Demonstrates basic values, limits, and verification of the complete elliptic integral of the second kind. Supports arbitrary complex m. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> ellipe(0) 1.570796326794896619231322 >>> ellipe(1) 1.0 >>> ellipe(-1) 1.910098894513856008952381 >>> ellipe(2) (0.5990701173677961037199612 + 0.5990701173677961037199612j) >>> ellipe(inf) (0.0 + +infj) >>> ellipe(-inf) +inf ``` ```python >>> ellipe(0.5) 1.350643881047675502520175 >>> quad(lambda t: sqrt(1-0.5*sin(t)**2), [0, pi/2]) 1.350643881047675502520175 >>> pi/2*hyp2f1(0.5,-0.5,1,0.5) 1.350643881047675502520175 ``` ```python >>> ellipe(0.5+0.25j) (1.360868682163129682716687 - 0.1238733442561786843557315j) >>> ellipe(3+4j) (1.499553520933346954333612 - 1.577879007912758274533309j) ``` ```python >>> quad(ellipe, [0,1]) 1.333333333333333333333333 ``` -------------------------------- ### Basic factorial usage and limits Source: https://mpmath.org/doc/current/functions/gamma.html Examples of factorial values, limits, and Stirling's approximation. ```python >>> from mpmath import * >>> mp.dps = 15; mp.pretty = True >>> for k in range(6): ... print("%s %s" % (k, fac(k))) ... 0 1.0 1 1.0 2 2.0 3 6.0 4 24.0 5 120.0 >>> fac(inf) +inf >>> fac(0.5), sqrt(pi)/2 (0.886226925452758, 0.886226925452758) ``` ```python >>> x = 10**10 >>> fac(x) 2.32579620567308e+95657055186 >>> sqrt(2*pi*x)*(x/e)**x 2.32579597597705e+95657055186 ``` ```python >>> fac(10**30) 6.22311232304258e+29565705518096748172348871081098 ``` ```python >>> nsum(lambda k: 1/fac(k), [0, inf]), exp(1) (2.71828182845905, 2.71828182845905) >>> nsum(lambda k: pi**k/fac(k), [0, inf]), exp(pi) (23.1406926327793, 23.1406926327793) ``` -------------------------------- ### Integrate over real line and half-infinite intervals Source: https://mpmath.org/doc/current/calculus/integration.html Examples of integrating functions over (-inf, inf) and (-inf, -1). ```python >>> quadosc(lambda x: cos(x)/(1+x**2), [-inf, inf], omega=1) 1.15572734979092 >>> pi/e 1.15572734979092 >>> quadosc(lambda x: cos(x)/x**2, [-inf, -1], period=2*pi) -0.0844109505595739 >>> cos(1)+si(1)-pi/2 -0.0844109505595738 ``` -------------------------------- ### Run mpmath unit tests Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Execute the full suite of mpmath unit tests using py.test. Ensure py.test is installed. ```bash py.test --pyargs mpmath ``` -------------------------------- ### Compute 1D integrals with infinite ranges Source: https://mpmath.org/doc/current/calculus/integration.html Examples of evaluating integrals over infinite or half-infinite intervals. ```python >>> mp.dps = 15 >>> quad(lambda x: 2/(x**2+1), [0, inf]) 3.14159265358979 >>> quad(lambda x: exp(-x**2), [-inf, inf])**2 3.14159265358979 ``` -------------------------------- ### Compute Sine Integrals Source: https://mpmath.org/doc/current/functions/expintegrals.html Examples for calculating the sine integral, including limits, complex plane evaluation, and series summation. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> si(0) 0.0 >>> si(1) 0.9460830703671830149413533 >>> si(-1) -0.9460830703671830149413533 >>> si(pi) 1.851937051982466170361053 >>> si(inf) 1.570796326794896619231322 >>> si(-inf) -1.570796326794896619231322 >>> si(2+3j) (4.547513889562289219853204 + 1.399196580646054789459839j) ``` ```python >>> si(10**10) 1.570796326707584656968511 >>> pi/2 1.570796326794896619231322 ``` ```python >>> si(10**6*(1+j)) (-9.75744874290013526417059e+434287 + 4.449410587611035724984376e+434287j) ``` ```python >>> mp.dps = 15 >>> quad(sinc, [0, 5]) 1.54993124494467 >>> si(5) 1.54993124494467 ``` ```python >>> nsum(lambda k: (-1)**k/(fac(2*k+1)*(2*k+1)), [0,inf]) 0.946083070367183 >>> si(1) 0.946083070367183 ``` -------------------------------- ### Compute Cosine Integrals Source: https://mpmath.org/doc/current/functions/expintegrals.html Examples for calculating the cosine integral, including limits, complex plane evaluation, and series summation. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> ci(0) -inf >>> ci(1) 0.3374039229009681346626462 >>> ci(pi) 0.07366791204642548599010096 >>> ci(inf) 0.0 >>> ci(-inf) (0.0 + 3.141592653589793238462643j) >>> ci(2+3j) (1.408292501520849518759125 - 2.983617742029605093121118j) ``` ```python >>> ci(10**10) -4.875060251748226537857298e-11 >>> sinc(10**10) -4.875060250875106915277943e-11 >>> chop(limit(ci, inf)) 0.0 ``` ```python >>> findroot(ci, 1) 0.6165054856207162337971104 >>> findroot(ci, 2) 3.384180422551186426397851 ``` ```python >>> ci(10**6*(1+j)) (4.449410587611035724984376e+434287 + 9.75744874290013526417059e+434287j) ``` ```python >>> mp.dps = 15 >>> -quadosc(lambda t: cos(t)/t, [5, inf], omega=1) -0.190029749656644 >>> ci(5) -0.190029749656644 ``` ```python >>> nsum(lambda k: (-1)**k/(fac(2*k)*(2*k)), [1,inf]) -0.239811742000565 >>> ci(1) - euler -0.239811742000565 ``` -------------------------------- ### Check mpmath Backend in Sage Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Verify that mpmath is configured to use Sage's backend for optimized arithmetic. This is the default behavior when mpmath is installed within Sage. ```python sage: mpmath.libmp.BACKEND 'sage' ``` -------------------------------- ### Plotting Multiple Functions with mpmath.plot Source: https://mpmath.org/doc/current/_sources/plotting.rst.txt Use `mpmath.plot` to generate x-y graphs of functions. Ensure matplotlib is installed. This example plots the cosine and sine functions over the interval [-4, 4]. ```python plot([cos, sin], [-4, 4]) ``` -------------------------------- ### Creating mpf instances Source: https://mpmath.org/doc/current/_sources/basics.rst.txt Shows how to instantiate mpf objects from various data types. ```python >>> mpf(4) mpf('4.0') >>> mpf(2.5) mpf('2.5') >>> mpf("1.25e6") mpf('1250000.0') >>> mpf(mpf(2)) mpf('2.0') >>> mpf("inf") mpf('+inf') ``` -------------------------------- ### Creating Matrices Source: https://mpmath.org/doc/current/matrices.html Demonstrates how to create matrices using the `matrix` class, specifying dimensions, and initializing with zeros. ```APIDOC ## Creating Matrices ### Basic methods Matrices in mpmath are implemented using dictionaries, efficiently storing only non-zero values for sparse matrix representation. **Creating an empty matrix:** ```python >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> matrix(2) matrix( [['0.0', '0.0'], ['0.0', '0.0']]) >>> matrix(2, 3) matrix( [['0.0', '0.0', '0.0'], ['0.0', '0.0', '0.0']]) ``` Calling `matrix` with one dimension creates a square matrix. **Accessing dimensions:** ```python >>> A = matrix(3, 2) >>> A.rows 3 >>> A.cols 2 ``` **Changing dimensions:** Resizing a matrix sets new elements to 0. Elements outside the new dimensions are discarded. ```python >>> A.rows = 2 >>> A matrix( [['0.0', '0.0'], ['0.0', '0.0']]) ``` **Setting elements:** Elements are accessed using `A[row, column]` (0-indexed). ```python >>> A = matrix(2) >>> A[1,1] = 1 + 1j >>> print(A) [0.0 0.0] [0.0 (1.0 + 1.0j)] ``` **Creating from nested lists:** A more convenient way to create matrices. ```python >>> matrix([[1, 2], [3, 4]]) matrix( [['1.0', '2.0'], ['3.0', '4.0']]) ``` ``` -------------------------------- ### Create numbers and matrices Source: https://mpmath.org/doc/current/_sources/contexts.rst.txt Demonstrates creating real numbers, complex numbers, and matrices using different contexts. ```python >>> from mpmath import mp, fp >>> mp.mpf(3) mpf('3.0') >>> fp.mpf(3) 3.0 ``` ```python >>> mp.mpc(2,3) mpc(real='2.0', imag='3.0') >>> fp.mpc(2,3) (2+3j) ``` ```python >>> mp.matrix([[1,0],[0,1]]) matrix( [['1.0', '0.0'], ['0.0', '1.0']]) >>> _[0,0] mpf('1.0') >>> fp.matrix([[1,0],[0,1]]) matrix( [['1.0', '0.0'], ['0.0', '1.0']]) >>> _[0,0] 1.0 ``` -------------------------------- ### Example: hyper2d() with separable cases Source: https://mpmath.org/doc/current/functions/hypergeometric.html Demonstrates two separable cases for hyper2d(): a product of two geometric series and a product of two Gaussian hypergeometric functions. Requires mpmath to be imported. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> x, y = mpf(0.25), mpf(0.5) >>> hyper2d({'m':1,'n':1}, {}, x,y) 2.666666666666666666666667 >>> 1/(1-x)/(1-y) 2.666666666666666666666667 >>> hyper2d({'m':[1,2],'n':[3,4]}, {'m':[5],'n':[6]}, x,y) 4.164358531238938319669856 >>> hyp2f1(1,2,5,x)*hyp2f1(3,4,6,y) 4.164358531238938319669856 ``` -------------------------------- ### Create PDF documentation Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Generate a PDF version of the mpmath documentation from the built LaTeX files. ```bash make -C build/sphinx/latex all-pdf ``` -------------------------------- ### Creating matrices with mp and fp contexts Source: https://mpmath.org/doc/current/contexts.html Demonstrates matrix creation using the `matrix` method from both `mp` and `fp` contexts, and accessing elements. ```python >>> mp.matrix([[1,0],[0,1]]) matrix( [['1.0', '0.0'], ['0.0', '1.0']]) ``` ```python >>> _[0,0] mpf('1.0') ``` ```python >>> fp.matrix([[1,0],[0,1]]) matrix( [['1.0', '0.0'], ['0.0', '1.0']]) ``` ```python >>> _[0,0] 1.0 ``` -------------------------------- ### Get Nearest Integer and Log-Precision with nint_distance() Source: https://mpmath.org/doc/current/general.html Use nint_distance(x) to get a tuple (n, d), where n is the nearest integer to x and d is an estimate of log2(|x-n|). A negative d indicates precision lost due to cancellation when computing x-n. ```python >>> from mpmath import * >>> n, d = nint_distance(5) >>> print(n); print(d) 5 -inf ``` ```python >>> n, d = nint_distance(mpf(5)) >>> print(n); print(d) 5 -inf ``` ```python >>> n, d = nint_distance(mpf(5.00000001)) >>> print(n); print(d) 5 -26 ``` ```python >>> n, d = nint_distance(mpf(4.99999999)) >>> print(n); print(d) 5 -26 ``` ```python >>> n, d = nint_distance(mpc(5,10)) >>> print(n); print(d) 5 4 ``` ```python >>> n, d = nint_distance(mpc(5,0.000001)) >>> print(n); print(d) 5 -19 ``` -------------------------------- ### Build mpmath documentation Source: https://mpmath.org/doc/current/_sources/setup.rst.txt Compile the mpmath documentation into HTML and LaTeX formats using Sphinx. ```bash python setup.py build_sphinx -c docs -b html,latex ``` -------------------------------- ### GET /mpmath/spherharm Source: https://mpmath.org/doc/current/_sources/functions/orthogonal.rst.txt Calculates the spherical harmonic function. ```APIDOC ## GET /mpmath/spherharm ### Description Computes the spherical harmonic Y_l^m(theta, phi). ### Method GET ### Parameters #### Query Parameters - **l** (int) - Required - Degree - **m** (int) - Required - Order - **theta** (float) - Required - Polar angle - **phi** (float) - Required - Azimuthal angle ``` -------------------------------- ### GET /root Source: https://mpmath.org/doc/current/functions/powers.html Computes the n-th root of a complex number z. ```APIDOC ## GET /root ### Description Computes an n-th root of z, returning a number r such that r^n = z. Every complex number z != 0 has n distinct n-th roots. ### Parameters #### Query Parameters - **z** (number/complex) - Required - The number to compute the root of. - **n** (integer) - Required - The degree of the root. - **k** (integer) - Optional - The index of the root to return (default is 0). Roots are indexed counterclockwise starting from the positive real half-axis. ``` -------------------------------- ### GET /mpmath/legendre Source: https://mpmath.org/doc/current/_sources/functions/orthogonal.rst.txt Calculates the Legendre polynomial of degree n at x. ```APIDOC ## GET /mpmath/legendre ### Description Computes the Legendre polynomial P_n(x). ### Method GET ### Parameters #### Query Parameters - **n** (int) - Required - The degree of the polynomial - **x** (float/complex) - Required - The point at which to evaluate ``` -------------------------------- ### Compute complex contour integrals Source: https://mpmath.org/doc/current/calculus/integration.html Example of integrating along a complex path. ```python >>> mp.dps = 15 >>> chop(quad(lambda z: 1/z, [1,j,-1,-j,1])) (0.0 + 6.28318530717959j) ``` -------------------------------- ### Complete Elliptic Integral Pi(n,m) Examples Source: https://mpmath.org/doc/current/functions/elliptic.html Shows basic values, limits, and evaluations in terms of simpler functions for the complete elliptic integral of the third kind. Handles infinite and complex arguments. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> ellippi(0,-5); ellipk(-5) 0.9555039270640439337379334 0.9555039270640439337379334 >>> ellippi(inf,2) 0.0 >>> ellippi(2,inf) 0.0 >>> abs(ellippi(1,5)) +inf >>> abs(ellippi(0.25,1)) +inf ``` ```python >>> ellippi(0.25,0.25); ellipe(0.25)/(1-0.25) 1.956616279119236207279727 1.956616279119236207279727 >>> ellippi(3,0); pi/(2*sqrt(-2)) (0.0 - 1.11072073453959156175397j) (0.0 - 1.11072073453959156175397j) >>> ellippi(-3,0); pi/(2*sqrt(4)) 0.7853981633974483096156609 0.7853981633974483096156609 ``` -------------------------------- ### Compute exact high order roots Source: https://mpmath.org/doc/current/functions/powers.html Examples of calculating roots for large powers. ```python >>> root(75**210, 105) 5625.0 >>> root(1, 128, 96) (0.0 - 1.0j) >>> root(4**128, 128, 96) (0.0 - 4.0j) ``` -------------------------------- ### Creating mpc instances Source: https://mpmath.org/doc/current/_sources/basics.rst.txt Demonstrates construction of complex numbers using the mpc type. ```python >>> mpc(2,3) mpc(real='2.0', imag='3.0') >>> mpc(complex(2,3)).imag mpf('3.0') ``` -------------------------------- ### Compute multiple integrals over infinite ranges Source: https://mpmath.org/doc/current/calculus/integration.html Example of a 2D integral over infinite ranges. ```python >>> mp.dps = 15 >>> print(quad(lambda x,y: exp(-x-y), [0, inf], [1, inf])) 0.367879441171442 >>> print(1/e) 0.367879441171442 ``` -------------------------------- ### Compute 2D integrals Source: https://mpmath.org/doc/current/calculus/integration.html Examples of evaluating various 2D integrals to high precision. ```python >>> mp.dps = 30 >>> f = lambda x, y: (x-1)/((1-x*y)*log(x*y)) >>> quad(f, [0, 1], [0, 1]) 0.577215664901532860606512090082 >>> +euler 0.577215664901532860606512090082 >>> f = lambda x, y: 1/sqrt(1+x**2+y**2) >>> quad(f, [-1, 1], [-1, 1]) 3.17343648530607134219175646705 >>> 4*log(2+sqrt(3))-2*pi/3 3.17343648530607134219175646705 >>> f = lambda x, y: 1/(1-x**2 * y**2) >>> quad(f, [0, 1], [0, 1]) 1.23370055013616982735431137498 >>> pi**2 / 8 1.23370055013616982735431137498 >>> quad(lambda x, y: 1/(1-x*y), [0, 1], [0, 1]) 1.64493406684822643647241516665 >>> pi**2 / 6 1.64493406684822643647241516665 ``` -------------------------------- ### Using fp context for calculations Source: https://mpmath.org/doc/current/_sources/contexts.rst.txt Demonstrates basic usage of the fp context for erfc, matrix operations, and numerical integration. ```python >>> u = fp.erfc(2.5) >>> print(u) # doctest:+SKIP 0.000406952017445 >>> type(u) # doctest:+SKIP >>> mp.dps = 15 >>> print(mp.erfc(2.5)) 0.000406952017444959 >>> fp.matrix([[1,2],[3,4]]) ** 2 matrix( [['7.0', '10.0'], ['15.0', '22.0']]) >>> >>> type(_[0,0]) # doctest:+SKIP >>> print(fp.quad(fp.sin, [0, fp.pi])) # numerical integration 2.0 ``` -------------------------------- ### GET hyp1f2 Source: https://mpmath.org/doc/current/functions/hypergeometric.html Evaluates the hypergeometric function 1F2(a1; b1, b2; z). ```APIDOC ## GET hyp1f2 ### Description Gives the hypergeometric function 1F2(a1; b1, b2; z). This is equivalent to calling hyper([a1], [b1, b2], z). ### Method GET ### Parameters #### Path Parameters - **a1** (number/complex) - Required - First parameter of the hypergeometric function - **b1** (number/complex) - Required - First denominator parameter - **b2** (number/complex) - Required - Second denominator parameter - **z** (number/complex) - Required - The argument of the function ``` -------------------------------- ### Create and Configure Matrices Source: https://mpmath.org/doc/current/_sources/matrices.rst.txt Initialize matrices using dimensions or nested lists, and manage their dimensions dynamically. ```python >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> matrix(2) matrix( [['0.0', '0.0'], ['0.0', '0.0']]) >>> matrix(2, 3) matrix( [['0.0', '0.0', '0.0'], ['0.0', '0.0', '0.0']]) ``` ```python >>> A = matrix(3, 2) >>> A matrix( [['0.0', '0.0'], ['0.0', '0.0'], ['0.0', '0.0']]) >>> A.rows 3 >>> A.cols 2 ``` ```python >>> A.rows = 2 >>> A matrix( [['0.0', '0.0'], ['0.0', '0.0']]) ``` ```python >>> A = matrix(2) >>> A[1,1] = 1 + 1j >>> print(A) [0.0 0.0] [0.0 (1.0 + 1.0j)] ``` ```python >>> matrix([[1, 2], [3, 4]]) matrix( [['1.0', '2.0'], ['3.0', '4.0']]) ``` -------------------------------- ### GET /altzeta Source: https://mpmath.org/doc/current/functions/zeta.html Computes the Dirichlet eta function (alternating zeta function) η(s). ```APIDOC ## GET /altzeta ### Description Gives the Dirichlet eta function, η(s), defined as the sum of the alternating series η(s)=∑k=0∞(−1)k/(k+1)^s. ### Method GET ### Parameters #### Query Parameters - **s** (number/complex) - Required - The complex argument for the function. - **rounding** (string) - Optional - Rounding mode for high-precision results. ### Request Example { "s": 1 } ### Response #### Success Response (200) - **result** (number) - The computed value of the alternating zeta function. #### Response Example { "result": 0.693147180559945 } ``` -------------------------------- ### GET /mpmath/jacobi Source: https://mpmath.org/doc/current/_sources/functions/orthogonal.rst.txt Calculates the Jacobi polynomial of degree n with parameters a and b at z. ```APIDOC ## GET /mpmath/jacobi ### Description Computes the Jacobi polynomial P_n^(a,b)(z). ### Method GET ### Parameters #### Query Parameters - **n** (int) - Required - The degree of the polynomial - **a** (float) - Required - Parameter a - **b** (float) - Required - Parameter b - **z** (float/complex) - Required - The point at which to evaluate ``` -------------------------------- ### Incomplete Elliptic Integral E(z,m) Examples Source: https://mpmath.org/doc/current/functions/elliptic.html Illustrates basic values, limits, and comparisons with numerical integration for the incomplete elliptic integral of the second kind. Supports complex arguments. ```python >>> ellipe(0,1) 0.0 >>> ellipe(0,0) 0.0 >>> ellipe(1,0) 1.0 >>> ellipe(2+3j,0) (2.0 + 3.0j) >>> ellipe(1,1); sin(1) 0.8414709848078965066525023 0.8414709848078965066525023 >>> ellipe(pi/2, -0.5); ellipe(-0.5) 1.751771275694817862026502 1.751771275694817862026502 >>> ellipe(pi/2, 1); ellipe(-pi/2, 1) 1.0 -1.0 >>> ellipe(1.5, 1) 0.9974949866040544309417234 ``` ```python >>> z,m = 0.5, 1.25 >>> ellipe(z,m) 0.4740152182652628394264449 >>> quad(lambda t: sqrt(1-m*sin(t)**2), [0,z]) 0.4740152182652628394264449 ``` ```python >>> ellipe(3j, 0.5) (0.0 + 7.551991234890371873502105j) >>> ellipe(3+4j, 5-6j) (24.15299022574220502424466 + 75.2503670480325997418156j) >>> k = 35 >>> z,m = 2+3j, 1.25 >>> ellipe(z+pi*k,m); ellipe(z,m) + 2*k*ellipe(m) (48.30138799412005235090766 + 17.47255216721987688224357j) (48.30138799412005235090766 + 17.47255216721987688224357j) ``` ```python >>> z,m = 0.5, 0.25 >>> ellipe(z,m) 0.4950017030164151928870375 >>> sin(z)*appellf1(0.5,0.5,-0.5,1.5,sin(z)**2,m*sin(z)**2) 0.4950017030164151928870376 ``` -------------------------------- ### Example: hyper2d() for Horn functions G1, G2, G3 Source: https://mpmath.org/doc/current/functions/hypergeometric.html Demonstrates the computation of Horn functions G1, G2, and G3 using hyper2d(). Requires mpmath to be imported and sets precision to 10 decimal places. ```python >>> from mpmath import * >>> mp.dps = 10; mp.pretty = True >>> x, y = 0.0625, 0.125 >>> a1,a2,b1,b2,c1,c2,d = 1.1,-1.2,-1.3,-1.4,1.5,-1.6,1.7 >>> hyper2d({'m+n':a1,'n-m':b1,'m-n':b2},{},x,y) # G1 1.139090746 >>> nsum(lambda m,n: rf(a1,m+n)*rf(b1,n-m)*rf(b2,m-n)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) 1.139090746 >>> hyper2d({'m':a1,'n':a2,'n-m':b1,'m-n':b2},{},x,y) # G2 0.9503682696 >>> nsum(lambda m,n: rf(a1,m)*rf(a2,n)*rf(b1,n-m)*rf(b2,m-n)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) 0.9503682696 >>> hyper2d({'2n-m':a1,'2m-n':a2},{},x,y) # G3 1.029372029 >>> nsum(lambda m,n: rf(a1,2*n-m)*rf(a2,2*m-n)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) 1.029372029 ``` -------------------------------- ### Compute Product from Negative Infinity Source: https://mpmath.org/doc/current/calculus/sums_limits.html Calculate a product where the interval starts from negative infinity. ```python nprod(lambda k: 1-k**(-3), [-inf,-2]) ``` ```python cosh(pi*sqrt(3)/2)/(3*pi) ``` -------------------------------- ### Evaluate Irregular Coulomb Wave Function Source: https://mpmath.org/doc/current/functions/bessel.html Examples of evaluating the irregular Coulomb wave function. ```python >>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> coulombg(-2, 1.5, 3.5) 1.380011900612186346255524 >>> coulombg(2, 1.5, 3.5) 1.919153700722748795245926 >>> coulombg(-2, 1.5, '1e-10') 201126715824.7329115106793 >>> coulombg(-2, 1.5, 1000) 0.1802071520691149410425512 >>> coulombg(-2, 1.5, 10**10) 0.652103020061678070929794 ``` -------------------------------- ### Importing mpmath Source: https://mpmath.org/doc/current/_sources/basics.rst.txt Demonstrates different ways to import mpmath functionality to avoid namespace collisions. ```python >>> from mpmath import * ``` ```python from mpmath import sin, cos sin(1), cos(1) import mpmath mpmath.sin(1), mpmath.cos(1) from mpmath import mp # mp context object -- to be explained mp.sin(1), mp.cos(1) ``` -------------------------------- ### Creating mpf real numbers with mp and fp contexts Source: https://mpmath.org/doc/current/contexts.html Shows how to create arbitrary-precision real numbers using the `mpf` method from both the `mp` and `fp` contexts. ```python >>> from mpmath import mp, fp >>> mp.mpf(3) mpf('3.0') ``` ```python >>> fp.mpf(3) 3.0 ``` -------------------------------- ### Double factorial usage Source: https://mpmath.org/doc/current/functions/gamma.html Examples of double factorial calculations, asymptotic behavior, and recurrence relations. ```python >>> from mpmath import * >>> mp.dps = 15; mp.pretty = True >>> nprint([fac2(n) for n in range(10)]) [1.0, 1.0, 2.0, 3.0, 8.0, 15.0, 48.0, 105.0, 384.0, 945.0] ``` ```python >>> x = mpf(10000) >>> fac2(x) 5.97272691416282e+17830 >>> sqrt(pi)*x**((x+1)/2)*exp(-x/2) 5.97262736954392e+17830 ``` ```python >>> fac2(-1), fac2(-3), fac2(-5), fac2(-7) (1.0, -1.0, 0.333333333333333, -0.0666666666666667) >>> fac2(-2) Traceback (most recent call last): ... ValueError: gamma function pole ``` ```python >>> fac2(pi+2j) (-1.3697207890154e-12 + 3.93665300979176e-12j) >>> (pi+2j)*fac2(pi-2+2j) (-1.3697207890154e-12 + 3.93665300979176e-12j) ``` ```python >>> fac(fac(20)) 5.13805976125208e+43675043585825292774 >>> fac2(20) 3715891200.0 ``` ```python >>> nsum(lambda k: 1/fac2(k), [0, inf]) 3.05940740534258 >>> sqrt(e)*(1+sqrt(pi/2)*erf(sqrt(2)/2)) 3.05940740534258 >>> nsum(lambda k: 2**k/fac2(2*k-1), [1, inf]) 4.06015693855741 >>> e * erf(1) * sqrt(pi) 4.06015693855741 ``` ```python >>> nsum(lambda k: (-1)**k*(fac2(2*k-1)/fac2(2*k))**3, [0,inf]) 0.90917279454693 >>> (gamma('9/8')/gamma('5/4')/gamma('7/8'))**2 0.90917279454693 ``` -------------------------------- ### Initialize matrices with dimensions Source: https://mpmath.org/doc/current/matrices.html Create empty matrices by specifying row and column counts. ```python >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> matrix(2) matrix( [['0.0', '0.0'], ['0.0', '0.0']]) >>> matrix(2, 3) matrix( [['0.0', '0.0', '0.0'], ['0.0', '0.0', '0.0']]) ``` -------------------------------- ### Example: hyper2d() for Horn functions H1, H2, H3 Source: https://mpmath.org/doc/current/functions/hypergeometric.html Demonstrates the computation of Horn functions H1, H2, and H3 using hyper2d(). Requires mpmath to be imported and sets precision to 10 decimal places. ```python >>> hyper2d({'m-n':a1,'m+n':b1,'n':c1},{'m':d},x,y) # H1 -1.605331256 >>> nsum(lambda m,n: rf(a1,m-n)*rf(b1,m+n)*rf(c1,n)/rf(d,m)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) -1.605331256 >>> hyper2d({'m-n':a1,'m':b1,'n':[c1,c2]},{'m':d},x,y) # H2 -2.35405404 >>> nsum(lambda m,n: rf(a1,m-n)*rf(b1,m)*rf(c1,n)*rf(c2,n)/rf(d,m)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) -2.35405404 >>> hyper2d({'2m+n':a1,'n':b1},{'m+n':c1},x,y) # H3 0.974479074 >>> nsum(lambda m,n: rf(a1,2*m+n)*rf(b1,n)/rf(c1,m+n)*\ ... x**m*y**n/fac(m)/fac(n), [0,inf], [0,inf]) 0.974479074 ``` -------------------------------- ### mpmath.levin() Source: https://mpmath.org/doc/current/calculus/sums_limits.html Initializes a Levin or Sidi-S sequence transformation object. ```APIDOC ## mpmath.levin(method='levin', variant='u') ### Description Initializes an object to perform Levin's nonlinear sequence transformation for convergence acceleration and summation of divergent series. ### Parameters #### Query Parameters - **method** (string) - Optional - The transformation method to use: 'levin' or 'sidi'. Defaults to 'levin'. - **variant** (string) - Optional - The weight variant to use: 'u', 't', or 'v'. Defaults to 'u'. ### Methods - **update(terms)**: Updates the transformation with a list of individual terms (ak). - **update_psum(sums)**: Updates the transformation with a list of partial sums (sk). - **step(ak)**: Updates the transformation with a single term (ak). - **step_psum(sk)**: Updates the transformation with a single partial sum (sk). ### Response Returns an object containing the current estimate (v) and an error estimate (e). ```