|
LMMC
Lamina Mathematic core
|
#include <math.h>#include "lmmc/special_functions.h"#include <float.h>#include "statistics_internal.h"结构体 | |
| struct | lmmc_lambertw_state_t |
函数 | |
| lmmc_status_t | lmmc_erf (lmmc_real_t x, lmmc_real_t *out) |
| 通过 C99 erf 计算误差函数 erf(x)。 | |
| lmmc_status_t | lmmc_erfc (lmmc_real_t x, lmmc_real_t *out) |
| 通过 C 标准库 erfc 计算互补误差函数 erfc(x) = 1 - erf(x)。 | |
| lmmc_status_t | lmmc_lgamma (lmmc_real_t x, lmmc_real_t *out) |
| 使用 Lanczos 近似计算对数伽马函数(g=7,n=9)。 | |
| lmmc_status_t | lmmc_tgamma (lmmc_real_t x, lmmc_real_t *out) |
| 计算伽马函数 tgamma(x) = exp(lgamma(x)),要求 x > 0。 | |
| lmmc_status_t | lmmc_beta (lmmc_real_t a, lmmc_real_t b, lmmc_real_t *out) |
| 使用稳定的共享 log-beta 内核,仅拒绝最终结果溢出。 | |
| lmmc_status_t | lmmc_digamma (lmmc_real_t x, lmmc_real_t *out) |
| 计算双伽马函数 psi(x) = d/dx ln(Gamma(x))。 | |
| lmmc_status_t | lmmc_lambertw (lmmc_real_t z, lmmc_real_t *out_res) |
| 计算 Lambert W 函数主分支 \(W_0(z)\) . | |
| lmmc_status_t | lmmc_lambertw_wm1 (lmmc_real_t z, lmmc_real_t *out_res) |
| 计算 Lambert W 函数 \(W_{-1}\) 分支,要求 \(z \in [-1/e, 0)\) . | |
| struct lmmc_lambertw_state_t |
在文件 special_functions.c 第 230 行定义.
| 成员变量 | ||
|---|---|---|
| double | lo | |
| double | hi | |
| double | w | |
| double | target | |
| double | target_error | |
| double | step | |
| int | region | |
| int | increasing | |
| lmmc_status_t lmmc_erf | ( | lmmc_real_t | x, |
| lmmc_real_t * | out ) |
通过 C99 erf 计算误差函数 erf(x)。
计算误差函数 \(\mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt\) .
通过 C99 erf 计算误差函数 erf(x)。
| [in] | x | 输入值. |
| [out] | out | 输出 \(\mathrm{erf}(x)\) . |
在文件 special_functions.c 第 7 行定义.
引用了 lmmc_erf(), LMMC_STATUS_INVALID_ARGUMENT , 以及 LMMC_STATUS_OK.
被这些函数引用 lmmc_erf().
| lmmc_status_t lmmc_erfc | ( | lmmc_real_t | x, |
| lmmc_real_t * | out ) |
通过 C 标准库 erfc 计算互补误差函数 erfc(x) = 1 - erf(x)。
计算互补误差函数 \(\mathrm{erfc}(x) = 1 - \mathrm{erf}(x)\) .
直接计算 erfc,保持大 |x| 时的尾部精度。
通过 C 标准库 erfc 计算互补误差函数 erfc(x) = 1 - erf(x)。
对大 \(|x|\) 使用直接近似以保持有效精度.
| [in] | x | 输入值. |
| [out] | out | 输出 \(\mathrm{erfc}(x)\) . |
在文件 special_functions.c 第 18 行定义.
引用了 lmmc_erfc(), LMMC_STATUS_INVALID_ARGUMENT , 以及 LMMC_STATUS_OK.
被这些函数引用 lmmc_erfc().
| lmmc_status_t lmmc_lgamma | ( | lmmc_real_t | x, |
| lmmc_real_t * | out ) |
使用 Lanczos 近似计算对数伽马函数(g=7,n=9)。
计算对数伽马函数 \(\ln\Gamma(x)\) ,要求 \(x > 0\) .
ln(Gamma(x)) = (x - 0.5) * ln(x + g - 0.5) - (x + g - 0.5) + 0.5*ln(2*pi) + ln(Ag(x)), 其中 Ag(x) 为 Lanczos 级数和。
使用 Lanczos 近似计算对数伽马函数(g=7,n=9)。
使用 Lanczos 近似(g=7, n=9 系数),精度约 15 位有效数字.
| [in] | x | 输入值,必须为正数. |
| [out] | out | 输出 \(\ln\Gamma(x)\) . |
Numerical Recipes / Cephes 的 Lanczos 系数(g=7,n=9)。
反射公式:Gamma(x) * Gamma(1-x) = pi / sin(pi*x)。
对数形式:lgamma(x) = ln(pi) - ln(sin(pi*x)) - lgamma(1-x)。
在文件 special_functions.c 第 30 行定义.
引用了 lmmc_lgamma(), LMMC_PI, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_NUMERICAL_FAILURE , 以及 LMMC_STATUS_OK.
被这些函数引用 lmmc_lgamma() , 以及 lmmc_tgamma().
| lmmc_status_t lmmc_tgamma | ( | lmmc_real_t | x, |
| lmmc_real_t * | out ) |
计算伽马函数 tgamma(x) = exp(lgamma(x)),要求 x > 0。
计算伽马函数 \(\Gamma(x)\) ,要求 \(x > 0\) .
计算伽马函数 tgamma(x) = exp(lgamma(x)),要求 x > 0。
| [in] | x | 输入值,必须为正数. |
| [out] | out | 输出 \(\Gamma(x)\) . |
在文件 special_functions.c 第 75 行定义.
引用了 lmmc_lgamma(), LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_NUMERICAL_FAILURE, LMMC_STATUS_OK , 以及 lmmc_tgamma().
被这些函数引用 lmmc_tgamma().
| lmmc_status_t lmmc_beta | ( | lmmc_real_t | a, |
| lmmc_real_t | b, | ||
| lmmc_real_t * | out ) |
使用稳定的共享 log-beta 内核,仅拒绝最终结果溢出。
计算贝塔函数 \(B(a,b) = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}\) ,要求 \(a,b > 0\) .
使用稳定的共享 log-beta 内核,仅拒绝最终结果溢出。
使用 log-beta、Gamma 比值及 Stirling 公式稳定求值,支持 a+b 超出可表示范围。
| [in] | a | 第一个有限正形状参数。 |
| [in] | b | 第二个有限正形状参数。 |
| [out] | out | B(a,b);有效下溢返回零,仅成功时写入。 |
在文件 special_functions.c 第 92 行定义.
引用了 lmmc_beta(), lmmc_log_beta(), LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_NUMERICAL_FAILURE , 以及 LMMC_STATUS_OK.
被这些函数引用 lmmc_beta().
| lmmc_status_t lmmc_digamma | ( | lmmc_real_t | x, |
| lmmc_real_t * | out ) |
计算双伽马函数 psi(x) = d/dx ln(Gamma(x))。
计算双伽马函数 \(\psi(x) = \frac{d}{dx}\ln\Gamma(x)\) ,要求 \(x > 0\) .
按 psi(x+1) = psi(x) + 1/x 递推至 x >= 7,再使用渐近展开: psi(x) ~ ln(x) - 1/(2x) - sum_{k=1}^{N} B_{2k}/(2k * x^{2k}), 其中 B_{2k} 为 Bernoulli 数。
计算双伽马函数 psi(x) = d/dx ln(Gamma(x))。
使用递推关系将 x 提升到大值区域后应用渐近展开.
| [in] | x | 输入值,必须为正数. |
| [out] | out | 输出 \(\psi(x)\) . |
渐近展开:psi(x) ~ ln(x) - 1/(2x) - 1/(12x^2) + 1/(120x^4) - 1/(252x^6) + ...。
Bernoulli 数:B2=1/6,B4=-1/30,B6=1/42,B8=-1/30,B10=5/66,B12=-691/2730。
展开系数为 B_{2k} / (2k)。
< 系数:B2/(2*1) = (1/6)/2。
< 系数:B4/(2*2) = (-1/30)/4。
< 系数:B6/(2*3) = (1/42)/6。
< 系数:B8/(2*4) = (-1/30)/8。
< 系数:B10/(2*5) = (5/66)/10。
< 系数:B12/(2*6) = (-691/2730)/12。
< 系数:B14/(2*7) = (7/6)/14 = 1/12。
< ix^(2k),初值为 ix^2。
在文件 special_functions.c 第 112 行定义.
引用了 lmmc_digamma(), LMMC_STATUS_INVALID_ARGUMENT , 以及 LMMC_STATUS_OK.
被这些函数引用 lmmc_digamma().
| lmmc_status_t lmmc_lambertw | ( | lmmc_real_t | z, |
| lmmc_real_t * | out_res ) |
计算 Lambert W 函数主分支 \(W_0(z)\) .
微小输入使用逆级数,分支点附近使用抗消减级数,其余使用带保护的 Halley/二分迭代求解单调残差。恰等于 -LMMC_INV_E 的 binary64 输入 代表端点 -1/e,返回 -1;相邻输入按各自值处理。W0 保留零的符号。
前向误差工程目标为 64*DBL_EPSILON*abs(W)+2*minimum_subnormal。 验收以残差误差半径包围根,计入 binary64 舍入,并假设所支持 libm 的 log/exp/expm1 误差至多为 2 ULP;此为工程误差模型, 不构成精确算术证明或 C 标准对 libm 的保证。
| [in] | z | 大于或等于端点代表值的有限输入。 |
| [out] | out_res | 有限结果,仅在成功时写入。 |
在文件 special_functions.c 第 364 行定义.
引用了 lmmc_lambertw().
被这些函数引用 lmmc_lambertw().
| lmmc_status_t lmmc_lambertw_wm1 | ( | lmmc_real_t | z, |
| lmmc_real_t * | out_res ) |
计算 Lambert W 函数 \(W_{-1}\) 分支,要求 \(z \in [-1/e, 0)\) .
保护迭代、工程精度模型、端点约定和失败时保留输出的规则同 lmmc_lambertw。
| [in] | z | [-LMMC_INV_E,0) 内的有限输入;正零和负零均无效。 |
| [out] | out_res | <= -1 的有限结果,仅在成功时写入。 |
在文件 special_functions.c 第 368 行定义.
引用了 lmmc_lambertw_wm1().
被这些函数引用 lmmc_lambertw_wm1().