chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:32:53 +08:00
commit 2a16f2f53b
247 changed files with 69150 additions and 0 deletions
+108
View File
@@ -0,0 +1,108 @@
Bessel functions and related functions
--------------------------------------
The functions in this section arise as solutions to various differential
equations in physics, typically describing wavelike oscillatory behavior or a
combination of oscillation and exponential decay or growth. Mathematically,
they are special cases of the confluent hypergeometric functions `\,_0F_1`,
`\,_1F_1` and `\,_1F_2` (see :doc:`hypergeometric`).
Bessel functions
................
.. autofunction:: mpmath.besselj
.. autofunction:: mpmath.j0
.. autofunction:: mpmath.j1
.. autofunction:: mpmath.bessely
.. autofunction:: mpmath.besseli
.. autofunction:: mpmath.besselk
Bessel function zeros
.....................
.. autofunction:: mpmath.besseljzero
.. autofunction:: mpmath.besselyzero
Hankel functions
................
.. autofunction:: mpmath.hankel1
.. autofunction:: mpmath.hankel2
Spherical Bessel functions
..........................
.. autofunction:: mpmath.spherical_jn
.. autofunction:: mpmath.spherical_yn
.. autofunction:: mpmath.spherical_in
.. autofunction:: mpmath.spherical_kn
Kelvin functions
................
.. autofunction:: mpmath.ber
.. autofunction:: mpmath.bei
.. autofunction:: mpmath.ker
.. autofunction:: mpmath.kei
Struve functions
................
.. autofunction:: mpmath.struveh
.. autofunction:: mpmath.struvel
Anger-Weber functions
.....................
.. autofunction:: mpmath.angerj
.. autofunction:: mpmath.webere
Lommel functions
................
.. autofunction:: mpmath.lommels1
.. autofunction:: mpmath.lommels2
Airy and Scorer functions
.........................
.. autofunction:: mpmath.airyai
.. autofunction:: mpmath.airybi
.. autofunction:: mpmath.airyaizero
.. autofunction:: mpmath.airybizero
.. autofunction:: mpmath.scorergi
.. autofunction:: mpmath.scorerhi
Coulomb wave functions
......................
.. autofunction:: mpmath.coulombf
.. autofunction:: mpmath.coulombg
.. autofunction:: mpmath.coulombc
Confluent U and Whittaker functions
...................................
.. autofunction:: mpmath.hyperu(a, b, z)
.. autofunction:: mpmath.whitm(k,m,z)
.. autofunction:: mpmath.whitw(k,m,z)
Parabolic cylinder functions
............................
.. autofunction:: mpmath.pcfd
.. autofunction:: mpmath.pcfu
.. autofunction:: mpmath.pcfv
.. autofunction:: mpmath.pcfw
+45
View File
@@ -0,0 +1,45 @@
Mathematical constants
----------------------
Mpmath supports arbitrary-precision computation of various common (and less
common) mathematical constants. These constants are implemented as lazy
objects that can evaluate to any precision. Whenever the objects are used as
function arguments or as operands in arithmetic operations, they automagically
evaluate to the current working precision. A lazy number can be converted to a
regular ``mpf`` using the unary ``+`` operator, or by calling it as a
function::
>>> from mpmath import pi, mp
>>> pi
<pi: 3.14159~>
>>> 2*pi
mpf('6.2831853071795862')
>>> +pi
mpf('3.1415926535897931')
>>> pi()
mpf('3.1415926535897931')
>>> mp.dps = 40
>>> pi
<pi: 3.14159~>
>>> 2*pi
mpf('6.28318530717958647692528676655900576839434')
>>> +pi
mpf('3.14159265358979323846264338327950288419717')
>>> pi()
mpf('3.14159265358979323846264338327950288419717')
The predefined objects ``j`` (imaginary unit), ``inf`` (positive infinity) and
``nan`` (not-a-number) are shortcuts to ``mpc`` and ``mpf`` instances with
these fixed values.
.. autofunction:: mpmath.mp.pi
.. autoattribute:: mpmath.mp.degree
.. autoattribute:: mpmath.mp.e
.. autoattribute:: mpmath.mp.phi
.. autofunction:: mpmath.mp.euler
.. autoattribute:: mpmath.mp.catalan
.. autoattribute:: mpmath.mp.apery
.. autoattribute:: mpmath.mp.khinchin
.. autoattribute:: mpmath.mp.glaisher
.. autoattribute:: mpmath.mp.mertens
.. autoattribute:: mpmath.mp.twinprime
+65
View File
@@ -0,0 +1,65 @@
Elliptic functions
------------------
.. automodule:: mpmath.functions.elliptic
:no-index:
Elliptic arguments
..................
.. autofunction:: mpmath.qfrom
.. autofunction:: mpmath.qbarfrom
.. autofunction:: mpmath.mfrom
.. autofunction:: mpmath.kfrom
.. autofunction:: mpmath.taufrom
Legendre elliptic integrals
...........................
.. autofunction:: mpmath.ellipk
.. autofunction:: mpmath.ellipf
.. autofunction:: mpmath.ellipe
.. autofunction:: mpmath.ellippi
Carlson symmetric elliptic integrals
....................................
.. autofunction:: mpmath.elliprf
.. autofunction:: mpmath.elliprc
.. autofunction:: mpmath.elliprj
.. autofunction:: mpmath.elliprd
.. autofunction:: mpmath.elliprg
Jacobi theta functions
......................
.. autofunction:: mpmath.jtheta
Jacobi elliptic functions
.........................
.. autofunction:: mpmath.ellipfun
Weierstrass elliptic functions
..............................
.. autofunction:: mpmath.weierinvariants
.. autofunction:: mpmath.weierhalfperiods
.. autofunction:: mpmath.weierp
.. autofunction:: mpmath.weierpprime
.. autofunction:: mpmath.weiersigma
.. autofunction:: mpmath.weierzeta
.. autofunction:: mpmath.weierpinv
Modular functions
.................
.. autofunction:: mpmath.eta
.. autofunction:: mpmath.kleinj
+70
View File
@@ -0,0 +1,70 @@
Exponential integrals and error functions
-----------------------------------------
Exponential integrals give closed-form solutions to a large class of commonly
occurring transcendental integrals that cannot be evaluated using elementary
functions. Integrals of this type include those with an integrand of the form
`t^a e^{t}` or `e^{-x^2}`, the latter giving rise to the Gaussian (or normal)
probability distribution.
The most general function in this section is the incomplete gamma function, to
which all others can be reduced. The incomplete gamma function, in turn, can
be expressed using hypergeometric functions (see :doc:`hypergeometric`).
Incomplete gamma functions
..........................
.. autofunction:: mpmath.gammainc
.. autofunction:: mpmath.lower_gamma
.. autofunction:: mpmath.upper_gamma
Exponential integrals
.....................
.. autofunction:: mpmath.ei
.. autofunction:: mpmath.e1
.. autofunction:: mpmath.expint
Logarithmic integral
....................
.. autofunction:: mpmath.li
Trigonometric integrals
.......................
.. autofunction:: mpmath.ci
.. autofunction:: mpmath.si
Hyperbolic integrals
....................
.. autofunction:: mpmath.chi
.. autofunction:: mpmath.shi
Error functions
...............
.. autofunction:: mpmath.erf
.. autofunction:: mpmath.erfc
.. autofunction:: mpmath.erfi
.. autofunction:: mpmath.erfinv
The normal distribution
.......................
.. autofunction:: mpmath.npdf
.. autofunction:: mpmath.ncdf
Fresnel integrals
.................
.. autofunction:: mpmath.fresnels
.. autofunction:: mpmath.fresnelc
+79
View File
@@ -0,0 +1,79 @@
Factorials and gamma functions
------------------------------
Factorials and factorial-like sums and products are basic tools of
combinatorics and number theory. Much like the exponential function is
fundamental to differential equations and analysis in general, the factorial
function (and its extension to complex numbers, the gamma function) is
fundamental to difference equations and functional equations.
A large selection of factorial-like functions is implemented in mpmath. All
functions support complex arguments, and arguments may be arbitrarily large.
Results are numerical approximations, so to compute *exact* values a high
enough precision must be set manually::
>>> from mpmath import mp, fac
>>> mp.dps = 15
>>> mp.pretty = True
>>> fac(100)
9.33262154439442e+157
>>> print(int(_)) # most digits are wrong
93326215443944150965646704795953882578400970373184098831012889540582227238570431295066113089288327277825849664006524270554535976289719382852181865895959724032
>>> mp.dps = 160
>>> fac(100)
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000.0
The gamma and polygamma functions are closely related to :doc:`zeta`. See also
:doc:`qfunctions` for q-analogs of factorial-like functions.
Factorials
..........
.. autofunction:: mpmath.factorial
.. autofunction:: mpmath.fac2
Binomial coefficients
.....................
.. autofunction:: mpmath.binomial
Gamma function
..............
.. autofunction:: mpmath.gamma
.. autofunction:: mpmath.rgamma
.. autofunction:: mpmath.gammaprod
.. autofunction:: mpmath.loggamma
Rising and falling factorials
.............................
.. autofunction:: mpmath.rf
.. autofunction:: mpmath.ff
Beta function
.............
.. autofunction:: mpmath.beta
.. autofunction:: mpmath.betainc
Super- and hyperfactorials
..........................
.. autofunction:: mpmath.superfac
.. autofunction:: mpmath.hyperfac
.. autofunction:: mpmath.barnesg
Polygamma functions and harmonic numbers
........................................
.. autofunction:: mpmath.psi
.. autofunction:: mpmath.digamma
.. autofunction:: mpmath.harmonic
+23
View File
@@ -0,0 +1,23 @@
Hyperbolic functions
--------------------
Hyperbolic functions
....................
.. autofunction:: mpmath.cosh
.. autofunction:: mpmath.sinh
.. autofunction:: mpmath.tanh
.. autofunction:: mpmath.sech
.. autofunction:: mpmath.csch
.. autofunction:: mpmath.coth
Inverse hyperbolic functions
............................
.. autofunction:: mpmath.acosh
.. autofunction:: mpmath.asinh
.. autofunction:: mpmath.atanh
.. autofunction:: mpmath.asech
.. autofunction:: mpmath.acsch
.. autofunction:: mpmath.acoth
+74
View File
@@ -0,0 +1,74 @@
Hypergeometric functions
------------------------
The functions listed in :doc:`expintegrals`, :doc:`bessel` and
:doc:`orthogonal`, and many other functions as well, are merely particular
instances of the generalized hypergeometric function `\,_pF_q`. The functions
listed in the following section enable efficient direct evaluation of the
underlying hypergeometric series, as well as linear combinations, limits with
respect to parameters, and analytic continuations thereof. Extensions to
twodimensional series are also provided. See also the basic or q-analog of the
hypergeometric series in :doc:`qfunctions`.
For convenience, most of the hypergeometric series of low order are provided as
standalone functions. They can equivalently be evaluated using
:func:`~mpmath.hyper`. As will be demonstrated in the respective docstrings,
all the ``hyp#f#`` functions implement analytic continuations and/or asymptotic
expansions with respect to the argument `z`, thereby permitting evaluation for
`z` anywhere in the complex plane. Functions of higher degree can be computed
via :func:`~mpmath.hyper`, but generally only in rapidly convergent instances.
Most hypergeometric and hypergeometric-derived functions accept optional
keyword arguments to specify options for :func:`~mpmath.hypercomb` or
:func:`~mpmath.hyper`. Some useful options are *maxprec*, *maxterms*,
*zeroprec*, *accurate_small*, *hmag*, *force_series*, *asymp_tol* and
*eliminate*. These options give control over what to do in case of slow
convergence, extreme loss of accuracy or evaluation at zeros (these two cases
cannot generally be distinguished from each other automatically), and singular
parameter combinations.
Common hypergeometric series
............................
.. autofunction:: mpmath.hyp0f1
.. autofunction:: mpmath.hyp1f1
.. autofunction:: mpmath.hyp1f2
.. autofunction:: mpmath.hyp2f0
.. autofunction:: mpmath.hyp2f1
.. autofunction:: mpmath.hyp2f2
.. autofunction:: mpmath.hyp2f3
.. autofunction:: mpmath.hyp3f2
Generalized hypergeometric functions
....................................
.. autofunction:: mpmath.hyper
.. autofunction:: mpmath.hypercomb
Meijer G-function
.................
.. autofunction:: mpmath.meijerg
Fox H-function
.................
.. autofunction:: mpmath.foxh
Bilateral hypergeometric series
...............................
.. autofunction:: mpmath.bihyper
Hypergeometric functions of two variables
.........................................
.. autofunction:: mpmath.hyper2d
.. autofunction:: mpmath.appellf1
.. autofunction:: mpmath.appellf2
.. autofunction:: mpmath.appellf3
.. autofunction:: mpmath.appellf4
+22
View File
@@ -0,0 +1,22 @@
Mathematical functions
======================
Mpmath implements the standard functions from Python's ``math`` and ``cmath`` modules, for both real and complex numbers and with arbitrary precision. Many other functions are also available in mpmath, including commonly-used variants of standard functions (such as the alternative trigonometric functions sec, csc, cot), but also a large number of "special functions" such as the gamma function, the Riemann zeta function, error functions, Bessel functions, etc.
.. toctree::
:maxdepth: 2
constants
powers
trigonometric
hyperbolic
signals
gamma
expintegrals
bessel
orthogonal
hypergeometric
elliptic
zeta
numtheory
qfunctions
+58
View File
@@ -0,0 +1,58 @@
Number-theoretical, combinatorial and integer functions
-------------------------------------------------------
For factorial-type functions, including binomial coefficients, double
factorials, etc, see the separate section :doc:`gamma`.
Fibonacci numbers
.................
.. autofunction:: mpmath.fibonacci
Bernoulli numbers and polynomials
.................................
.. autofunction:: mpmath.bernoulli
.. autofunction:: mpmath.bernfrac
.. autofunction:: mpmath.bernpoly
Euler numbers and polynomials
.............................
.. autofunction:: mpmath.eulernum
.. autofunction:: mpmath.eulerpoly
Bell numbers and polynomials
............................
.. autofunction:: mpmath.bell
Stirling numbers
................
.. autofunction:: mpmath.stirling1
.. autofunction:: mpmath.stirling2
Prime counting functions
........................
.. autofunction:: mpmath.primepi
.. autofunction:: mpmath.primepi2
.. autofunction:: mpmath.riemannr
Cyclotomic polynomials
......................
.. autofunction:: mpmath.cyclotomic
Arithmetic functions
......................
.. autofunction:: mpmath.mangoldt
+77
View File
@@ -0,0 +1,77 @@
Orthogonal polynomials
----------------------
An orthogonal polynomial sequence is a sequence of polynomials `P_0(x), P_1(x),
\ldots` of degree `0, 1, \ldots`, which are mutually orthogonal in the sense
that
.. math ::
\int_S P_n(x) P_m(x) w(x) dx =
\begin{cases}
c_n \ne 0 & \text{if $m = n$} \\
0 & \text{if $m \ne n$}
\end{cases}
where `S` is some domain (e.g. an interval `[a,b] \in \mathbb{R}`) and `w(x)`
is a fixed *weight function*. A sequence of orthogonal polynomials is
determined completely by `w`, `S`, and a normalization convention (e.g. `c_n =
1`). Applications of orthogonal polynomials include function approximation and
solution of differential equations.
Orthogonal polynomials are sometimes defined using the differential equations
they satisfy (as functions of `x`) or the recurrence relations they satisfy
with respect to the order `n`. Other ways of defining orthogonal polynomials
include differentiation formulas and generating functions. The standard
orthogonal polynomials can also be represented as hypergeometric series (see
:doc:`hypergeometric`), more specifically using the Gauss hypergeometric
function `\,_2F_1` in most cases. The following functions are generally
implemented using hypergeometric functions since this is computationally
efficient and easily generalizes.
For more information, see the `Wikipedia article on orthogonal polynomials
<http://en.wikipedia.org/wiki/Orthogonal_polynomials>`_.
Legendre functions
..................
.. autofunction:: mpmath.legendre
.. autofunction:: mpmath.legenp
.. autofunction:: mpmath.legenq
Chebyshev polynomials
.....................
.. autofunction:: mpmath.chebyt
.. autofunction:: mpmath.chebyu
Jacobi polynomials
..................
.. autofunction:: mpmath.jacobi
Gegenbauer polynomials
......................
.. autofunction:: mpmath.gegenbauer
Hermite polynomials
...................
.. autofunction:: mpmath.hermite
Laguerre polynomials
....................
.. autofunction:: mpmath.laguerre
Spherical harmonics
...................
.. autofunction:: mpmath.spherharm
+45
View File
@@ -0,0 +1,45 @@
Powers and logarithms
---------------------
Nth roots
.........
.. autofunction:: mpmath.sqrt
.. autofunction:: mpmath.hypot
.. autofunction:: mpmath.cbrt
.. autofunction:: mpmath.root
.. autofunction:: mpmath.unitroots
Exponentiation
..............
.. autofunction:: mpmath.exp
.. autofunction:: mpmath.exp2
.. autofunction:: mpmath.power
.. autofunction:: mpmath.expj
.. autofunction:: mpmath.expjpi
.. autofunction:: mpmath.expm1(x)
.. autofunction:: mpmath.powm1(x, y)
Logarithms
..........
.. autofunction:: mpmath.log
.. autofunction:: mpmath.ln
.. autofunction:: mpmath.log2
.. autofunction:: mpmath.log10
.. autofunction:: mpmath.log1p(x)
Lambert W function
..................
.. autofunction:: mpmath.lambertw
Arithmetic-geometric mean
.........................
.. autofunction:: mpmath.agm
+20
View File
@@ -0,0 +1,20 @@
q-functions
-----------
q-Pochhammer symbol
...................
.. autofunction:: mpmath.qp
q-gamma and factorial
.....................
.. autofunction:: mpmath.qgamma
.. autofunction:: mpmath.qfac
Hypergeometric q-series
.......................
.. autofunction:: mpmath.qhyper
+34
View File
@@ -0,0 +1,34 @@
Signal functions
----------------
The functions in this section describe non-sinusoidal waveforms, which are
often used in signal processing and electronics.
Square wave signal
..................
.. autofunction:: mpmath.squarew
Triangle wave signal
....................
.. autofunction:: mpmath.trianglew
Sawtooth wave signal
....................
.. autofunction:: mpmath.sawtoothw
Unit triangle signal
....................
.. autofunction:: mpmath.unit_triangle
Sigmoid wave signal
.....................
.. autofunction:: mpmath.sigmoid
+62
View File
@@ -0,0 +1,62 @@
Trigonometric functions
-----------------------
Except where otherwise noted, the trigonometric functions take a radian angle
as input and the inverse trigonometric functions return radian angles.
The ordinary trigonometric functions are single-valued functions defined
everywhere in the complex plane (except at the poles of tan, sec, csc, and
cot). They are defined generally via the exponential function, e.g.
.. math ::
\cos(x) = \frac{e^{ix} + e^{-ix}}{2}.
The inverse trigonometric functions are multivalued, thus requiring branch
cuts, and are generally real-valued only on a part of the real line.
Definitions and branch cuts are given in the documentation of each function.
The branch cut conventions used by mpmath are essentially the same as those
found in most standard mathematical software, such as Mathematica and Python's
own ``cmath`` libary.
Degree-radian conversion
........................
.. autofunction:: mpmath.degrees
.. autofunction:: mpmath.radians
Trigonometric functions
.......................
.. autofunction:: mpmath.cos
.. autofunction:: mpmath.sin
.. autofunction:: mpmath.tan
.. autofunction:: mpmath.sec
.. autofunction:: mpmath.csc
.. autofunction:: mpmath.cot
Trigonometric functions with modified argument
..............................................
.. autofunction:: mpmath.cospi
.. autofunction:: mpmath.sinpi
Inverse trigonometric functions
...............................
.. autofunction:: mpmath.acos
.. autofunction:: mpmath.asin
.. autofunction:: mpmath.atan
.. autofunction:: mpmath.atan2
.. autofunction:: mpmath.asec
.. autofunction:: mpmath.acsc
.. autofunction:: mpmath.acot
Sinc function
.............
.. autofunction:: mpmath.sinc
.. autofunction:: mpmath.sincpi
+60
View File
@@ -0,0 +1,60 @@
Zeta functions, L-series and polylogarithms
-------------------------------------------
This section includes the Riemann zeta functions and associated functions
pertaining to analytic number theory.
Riemann and Hurwitz zeta functions
..................................
.. autofunction:: mpmath.zeta
Dirichlet L-series
..................
.. autofunction:: mpmath.altzeta
.. autofunction:: mpmath.dirichlet
Stieltjes constants
...................
.. autofunction:: mpmath.stieltjes
Zeta function zeros
...................
These functions are used for the study of the Riemann zeta function in the
critical strip.
.. autofunction:: mpmath.zetazero
.. autofunction:: mpmath.nzeros
.. autofunction:: mpmath.siegelz
.. autofunction:: mpmath.siegeltheta
.. autofunction:: mpmath.grampoint
.. autofunction:: mpmath.backlunds
Lerch transcendent
..................
.. autofunction:: mpmath.lerchphi
Polylogarithms and Clausen functions
....................................
.. autofunction:: mpmath.polylog
.. autofunction:: mpmath.clsin
.. autofunction:: mpmath.clcos
.. autofunction:: mpmath.polyexp
Zeta function variants
......................
.. autofunction:: mpmath.primezeta
.. autofunction:: mpmath.secondzeta