Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,30 @@
create or replace function gamma_taylor(x) as (
select gamma
from ( select [
1.00000000000000000000, 0.57721566490153286061, -0.65587807152025388108, -0.04200263503409523553,
0.16653861138229148950, -0.04219773455554433675, -0.00962197152787697356, 0.00721894324666309954,
-0.00116516759185906511, -0.00021524167411495097, 0.00012805028238811619, -0.00002013485478078824,
-0.00000125049348214267, 0.00000113302723198170, -0.00000020563384169776, 0.00000000611609510448,
0.00000000500200764447, -0.00000000118127457049, 0.00000000010434267117, 0.00000000000778226344,
-0.00000000000369680562, 0.00000000000051003703, -0.00000000000002058326, -0.00000000000000534812,
0.00000000000000122678, -0.00000000000000011813, 0.00000000000000000119, 0.00000000000000000141,
-0.00000000000000000023, 0.00000000000000000002
] as a,
length(a) as n,
(with recursive cte as (
select 2 as an, a[n] as acc
union all
select an+1 as an,
(acc * (x-1)) + a[1 + n-an] as acc
from cte
where an <= n
)
select 1 / last(acc order by an) from cte) as gamma
)
limit 1
);
## Comparison
select x, gamma, taylor, 2 * @(gamma-taylor)/(gamma+taylor) as "%"
from (select x, gamma(x) as gamma, gamma_taylor(x) as taylor
from (select x/3 as x from range(1,11) t(x))) ;

View file

@ -0,0 +1,35 @@
include "NSLog.incl"
#define FB_M_E 2.7182818284590452
double local fn StirlingGamma( x as double )
return fn sqrt(2 * M_PI / x ) * fn pow(x / FB_M_E, x )
end fn = 0.0
double local fn LanczosGamma( x as double )
int g = 7
static double p(8) = {0.99999999999980993, 676.5203681218851, -1259.1392167224028,¬
771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012,¬
9.9843695780195716e-6, 1.5056327351493116e-7}
if ( x < 0.5 ) then return M_PI / ( sin( M_PI * x ) * fn LanczosGamma( 1 - x ) )
x -= 1.0
double a = p(0)
for int i = 1 to 8
a += p(i) / ( x + i )
next
double t = x + g + 0.5
return fn sqrt(2 * M_PI ) * fn pow(t, x + 0.5 ) * exp(-t ) * a
end fn = 0.0
void local fn RunGammaFunctions
NSLog( @"Gamma\tStirling\t\t\t Lanczos" )
for double i = 1.0 to 20
double value = i / 10.0
NSLog( @"%1.2f\t%17.15f\t %1.15f", value, fn StirlingGamma( value ), fn LanczosGamma( value ) )
next
end fn
fn RunGammaFunctions
HandleEvents

View file

@ -0,0 +1,12 @@
local fmt = require "fmt"
require "math2"
local function stirling(x)
return math.sqrt(2 * math.pi / x) * ((x / math.e) ^ x)
end
print(" x\tStirling\t\tLanczos\n")
for i = 1, 20 do
local d = i / 10
fmt.print("%4.2f\t%0.14f\t%0.14f", d, stirling(d), math.gamma(d))
end

View file

@ -1,10 +1,13 @@
-- 8 May 2025
-- 28 Jul 2025
include Settings
arg n
if n = '' then
n = 100
numeric digits n
say 'GAMMA'
say version
say
arg n; if n = '' then n = 100; numeric digits n
say '(Half)integers formulas'
w = '-99.5 -10.5 -5.5 -2.5 -1.5 -0.5 0.5 1 1.5 2 2.5 5 5.5 10 10.5 99 99.5'
numeric digits n
@ -47,12 +50,8 @@ end
exit
Stirling:
procedure expose glob. fact.
procedure expose Memo. fact.
arg x
return Sqrt(2*Pi()/x) * Power(x/e(),x)
include Constants
include Functions
include Special
include Numbers
include Abend
include Math