Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.mathspecial

Mathematical Special Functions
The technical term 'Special Functions' includes several families of transcendental functions, which have important applications in particular branches of mathematics and physics.
The gamma and related functions, and the error function are crucial for mathematical statistics. The Bessel and related functions arise in problems involving wave propagation (especially in optics). Other major categories of special functions include the elliptic integrals (related to the arc length of an ellipse), and the hypergeometric functions.

StatusMany more functions will be added to this module. The naming convention for the distribution functions (gammaIncomplete, etc) is not yet finalized and will probably change.

License:
Boost License 1.0.
Authors:
Stephen L. Moshier (original C code). Conversion to D by Don Clugston

Sourcestd/mathspecial.d

pure nothrow @nogc @safe realgamma(realx);
The Gamma function, Γ(x)
Γ(x) is a generalisation of the factorial function to real and complex numbers. Like x!, Γ(x+1) = x * Γ(x).
Mathematically, if z.re > 0 then Γ(z) =0 tz-1e-t dt
Special Values
x Γ(x)
NANNAN
±0.0±∞
integer > 0 (x-1)!
integer < 0NAN
+∞ +∞
-∞NAN
pure nothrow @nogc @safe reallogGamma(realx);
Natural logarithm of the gamma function, Γ(x)
Returns the base e (2.718...) logarithm of the absolute value of the gamma function of the argument.
For reals, logGamma is equivalent to log(fabs(gamma(x))).
Special Values
x logGamma(x)
NANNAN
integer <= 0 +∞
±∞ +∞
pure nothrow @nogc @safe realsgnGamma(realx);
The sign of Γ(x).
Parameters:
realxthe argument of Γ
Returns:
-1 if Γ(x) < 0, +1 if Γ(x) > 0, andNAN if Γ(x) does not exist.

NoteThis function can be used in conjunction withlogGamma to evaluate Γ(x) whengamma(x) is too large to be represented as areal.

Examples:
writeln(sgnGamma(10_000));// 1
pure nothrow @nogc @safe realbeta(realx, realy);
Beta function, B(x,y)
Mathematically, if x > 0 and y > 0 then B(x,y) =01tx-1(l-t)y-1dt. Through analytic continuation, it is extended to ℂ2 where it can be expressed in terms of Γ(z).
B(x,y) = Γ(x)Γ(y) / Γ(x+y).
This implementation restricts x and y to the set of real numbers.
Parameters:
realxthe first argument of B
realythe second argument of B
Returns:
It returns B(x,y) if it can be computed, otherwiseNAN.
Special Values
xybeta(x, y)
NANyNAN
-∞yNAN
integer < 0yNAN
noninteger and x+y even ≤ 0noninteger-0
noninteger and x+y odd ≤ 0noninteger+0
+0positive finite+∞
+0+∞NAN
> 0+∞+0
-0+0NAN
-0> 0-∞
noninteger < 0, ⌈x⌉ odd+∞-∞
noninteger < 0, ⌈x⌉ even+∞+∞
noninteger < 0±0±∞
Since B(x,y) = B(y,x), if the table states that beta(x, y) is a special value, then beta(y, x) is one as well.
Examples:
writeln(beta(1, 2));// 0.5
pure nothrow @nogc @safe realdigamma(realx);
Digamma function, Ψ(x)
Ψ(x), is the logarithmic derivative of the gamma function, Γ(x).
Ψ(x) =d/dx ln|Γ(x)| (the derivative oflogGamma(x))
Parameters:
realxthe domain value
Returns:
It returns Ψ(x).
Special Values
x digamma(x)
integer < 0NAN
±0.0 ∓∞
+∞ +∞
-∞NAN
NANNAN
See Also:
Examples:
const euler = 0.57721_56649_01532_86060_65121L;assert(isClose(digamma(1), -euler));writeln(digamma(+0.));// -real.infinitywriteln(digamma(-0.));// +real.infinitywriteln(digamma(+real.infinity));// +real.infinityassert(isNaN(digamma(-1)));assert(isNaN(digamma(-real.infinity)));
pure nothrow @nogc @safe reallogmdigamma(realx);
Log Minus Digamma function
logmdigamma(x) = log(x) - digamma(x)
See Also:
pure nothrow @nogc @safe reallogmdigammaInverse(realx);
Inverse of the Log Minus Digamma function
Given y, the function finds x such log(x) - digamma(x) = y.
See Also:
pure nothrow @nogc @safe realbetaIncomplete(reala, realb, realx);
Incomplete beta integral
Returns regularized incomplete beta integral of the arguments, evaluated from zero to x. The regularized incomplete beta function is defined as
betaIncomplete(a, b, x) = Γ(a + b) / ( Γ(a) Γ(b) ) *0x ta-1(1-t)b-1 dt
and is the same as the cumulative distribution function of the Beta distribution.
The domain of definition is 0 <= x <= 1. In this implementation a and b are restricted to positive values. The integral from x to 1 may be obtained by the symmetry relation
betaIncompleteCompl(a, b, x ) = betaIncomplete( b, a, 1-x )
The integral is evaluated by a continued fraction expansion or, when b * x is small, by a power series.
pure nothrow @nogc @safe realbetaIncompleteInverse(reala, realb, realy);
Inverse of incomplete beta integral
Given y, the function finds x such that
betaIncomplete(a, b, x) == y
Newton iterations or interval halving is used.
pure nothrow @nogc @safe realgammaIncomplete(reala, realx);

pure nothrow @nogc @safe realgammaIncompleteCompl(reala, realx);
Incomplete gamma integral and its complement
These functions are defined by
gammaIncomplete = (0x e-t ta-1 dt )/ Γ(a)
gammaIncompleteCompl(a,x) = 1 - gammaIncomplete(a,x) = (x e-t ta-1 dt )/ Γ(a)
In this implementation both arguments must be positive. The integral is evaluated by either a power series or continued fraction expansion, depending on the relative values of a and x.
pure nothrow @nogc @safe realgammaIncompleteComplInverse(reala, realp);
Inverse of complemented incomplete gamma integral
Given a and p, the function finds x such that
gammaIncompleteCompl( a, x ) = p.
pure nothrow @nogc @safe realerf(realx);
Error function
The integral is
erf(x) = 2/ √(π)0x exp( - t2) dt
The magnitude of x is limited to about 106.56 for IEEE 80-bit arithmetic; 1 or -1 is returned outside this range.
pure nothrow @nogc @safe realerfc(realx);
Complementary error function
erfc(x) = 1 - erf(x) = 2/ √(π)x exp( - t2) dt
This function has high relative accuracy for values of x far from zero. (For values near zero, use erf(x)).
pure nothrow @nogc @safe realnormalDistribution(realx);
Standard normal distribution function.
The normal (or Gaussian, or bell-shaped) distribution is defined as:
normalDist(x) = 1/√(2π)-∞x exp( - t2/2) dt = 0.5 + 0.5 * erf(x/sqrt(2)) = 0.5 * erfc(- x/sqrt(2))
To maintain accuracy at values of x near 1.0, use normalDistribution(x) = 1.0 - normalDistribution(-x).

Referenceshttp://www.netlib.org/cephes/ldoubdoc.html, G. Marsaglia, "Evaluating the Normal Distribution", Journal of Statistical Software11, (July 2004).

pure nothrow @nogc @safe realnormalDistributionInverse(realp);
Inverse of Standard normal distribution function
Returns the argument, x, for which the area under the Normal probability density function (integrated from minus infinity to x) is equal to p.

NoteThis function is only implemented to 80 bit precision.

Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 06:42:57 2026

[8]ページ先頭

©2009-2026 Movatter.jp