Differences between revisions 6 and 7
 ⇤ ← Revision 6 as of 2007-09-05 21:59:30 → Size: 1127 Editor: RogerHui Comment: ← Revision 7 as of 2008-12-08 10:45:44 → ⇥ Size: 1107 Editor: anonymous Comment: converted to 1.6 markup Deletions are marked like this. Additions are marked like this. Line 6: Line 6: [http://www.math.sfu.ca/~cbm/aands/page_257.htm Abramowitz and Stegun Section 6.1]. [[http://www.math.sfu.ca/~cbm/aands/page_257.htm|Abramowitz and Stegun Section 6.1]]. Line 37: Line 37: [[BR]] <
> Line 41: Line 41: [http://mathworld.wolfram.com/StirlingsApproximation.html MathWorld] [[MathWorld:StirlingsApproximation|MathWorld]] Line 43: Line 43: [[BR]] <
>

Stirling's formulae provide approximations to the gamma or factorial functions. They are given in Abramowitz and Stegun Section 6.1.

```sbase =: %:@(2p1&%) * %&1x1 ^ ]
scorr =: 1 1r12 1r288 _139r51840 _571r2488320&p.@%
stirlg=: sbase * scorr                         NB. 6.1.37

stirlf=: ^@(1r12&%) * %:@(2p1&*) * %&1x1 ^ ]   NB. 6.1.38```

stirlf approximates the factorial function while the more accurate stirlg approximates the gamma function.

```g =: stirlg |@-.@% !@<:  NB. relative difference between stirlg and !@<:
f =: stirlf |@-.@% !     NB. relative difference between stirlf and !

(stirlf , stirlg@>: , !) 10
3.62881e6 3.6288e6 3.6288e6
f 10
2.7699e_6
g 11
4.84055e_9

(stirlf , stirlg@>: , !) 5j4
20.7062j23.4239 20.7061j23.4242 20.7061j23.4242
f 5j4
1.05637e_5
g 6j4
4.00025e_8```