Class SpecialFunctions
All methods are stateless and thread-safe. Implementations use well-known numerical approximations with documented error bounds.
所有方法无状态且线程安全。实现使用已知的数值近似方法,具有文档化的误差范围。
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublebeta(double a, double b) Computes the Beta function: B(a, b) = Gamma(a) * Gamma(b) / Gamma(a + b).static doubleerf(double x) Computes the error function erf(x).static doubleerfc(double x) Computes the complementary error function erfc(x) = 1 - erf(x).static doublegamma(double x) Computes the Gamma function using the Lanczos approximation.static doublelogGamma(double x) Computes the natural logarithm of the Gamma function.static doubleregularizedBeta(double x, double a, double b) Computes the regularized incomplete beta function I_x(a, b).static doubleregularizedGammaP(double a, double x) Computes the regularized lower incomplete gamma function P(a, x) = gamma(a, x) / Gamma(a).
-
Method Details
-
gamma
public static double gamma(double x) Computes the Gamma function using the Lanczos approximation. 使用 Lanczos 近似计算 Gamma 函数For negative non-integer values, the reflection formula is used: Gamma(x) = pi / (sin(pi*x) * Gamma(1-x)).
对于负非整数值,使用反射公式:Gamma(x) = pi / (sin(pi*x) * Gamma(1-x))。
- Parameters:
x- the argument / 参数- Returns:
- Gamma(x) / Gamma 函数值
- Throws:
MathException- if x is a non-positive integer (pole) / 如果 x 为非正整数(极点)
-
logGamma
public static double logGamma(double x) Computes the natural logarithm of the Gamma function. 计算 Gamma 函数的自然对数More numerically stable than
Math.log(gamma(x))for large x.对于大 x 值,比
Math.log(gamma(x))在数值上更稳定。- Parameters:
x- the argument, must be positive / 参数,必须为正数- Returns:
- ln(Gamma(x)) / Gamma 函数自然对数值
- Throws:
MathException- if x is not positive / 如果 x 不是正数
-
beta
public static double beta(double a, double b) Computes the Beta function: B(a, b) = Gamma(a) * Gamma(b) / Gamma(a + b). 计算 Beta 函数:B(a, b) = Gamma(a) * Gamma(b) / Gamma(a + b)- Parameters:
a- first parameter, must be positive / 第一个参数,必须为正数b- second parameter, must be positive / 第二个参数,必须为正数- Returns:
- Beta(a, b) / Beta 函数值
- Throws:
MathException- if a or b is not positive / 如果 a 或 b 不是正数
-
erf
public static double erf(double x) Computes the error function erf(x). 计算误差函数 erf(x)Uses Abramowitz & Stegun approximation 7.1.26 in Horner form. Maximum error approximately 1.5e-7.
使用 Abramowitz & Stegun 近似 7.1.26 的 Horner 形式。 最大误差约 1.5e-7。
- Parameters:
x- the argument / 参数- Returns:
- erf(x), in the range [-1, 1] / 误差函数值,范围 [-1, 1]
-
erfc
public static double erfc(double x) Computes the complementary error function erfc(x) = 1 - erf(x). 计算互补误差函数 erfc(x) = 1 - erf(x)Computed directly (not as 1 - erf(x)) for better precision when x is large.
直接计算(非 1 - erf(x)),以在 x 较大时获得更好的精度。
- Parameters:
x- the argument / 参数- Returns:
- erfc(x), in the range [0, 2] / 互补误差函数值,范围 [0, 2]
-
regularizedBeta
public static double regularizedBeta(double x, double a, double b) Computes the regularized incomplete beta function I_x(a, b). 计算正则化不完全 Beta 函数 I_x(a, b)Uses continued fraction expansion (Lentz's method) for efficient convergence.
使用连分数展开(Lentz 方法)实现高效收敛。
- Parameters:
x- the integration upper limit, in [0, 1] / 积分上限,范围 [0, 1]a- first shape parameter, must be positive / 第一个形状参数,必须为正数b- second shape parameter, must be positive / 第二个形状参数,必须为正数- Returns:
- I_x(a, b), in [0, 1] / 正则化不完全 Beta 函数值
- Throws:
MathException- if parameters are invalid or algorithm does not converge
-
regularizedGammaP
public static double regularizedGammaP(double a, double x) Computes the regularized lower incomplete gamma function P(a, x) = gamma(a, x) / Gamma(a). 计算正则化下不完全 Gamma 函数 P(a, x) = gamma(a, x) / Gamma(a)Uses series expansion for x < a+1, and continued fraction for x ≥ a+1.
当 x < a+1 时使用级数展开,x ≥ a+1 时使用连分数展开。
- Parameters:
a- shape parameter, must be positive / 形状参数,必须为正数x- upper integration limit, must be non-negative / 积分上限,必须非负- Returns:
- P(a, x), in [0, 1] / 正则化下不完全 Gamma 函数值
- Throws:
MathException- if parameters are invalid or algorithm does not converge
-