HP
Prime and Casio fx-5800p Approximating the Factorial Function
A
quick way to estimate the factorial function, which is good for all real
numbers (and complex numbers with the HP Prime) is determined by Gergő Nemes
Ph. D (Mathematics, University of Edinburgh):
N!
≈ N^N * √(2*π*N) * e^(1/(12*N+2/(5*N+53/(42*N)))-N)
The
error is the order of 1 + O(N^-8). Like
the Sterling approximation formula, this formula is a better approximation as N
increases.
Casio
fx-5800p Program: GERGO
“GERGO
RSKEY.ORG”
“N”?
→ N
N^(N)*√(2πN)*e^(
1÷(12N+2÷(5N+53÷
(42N)))-N)
HP
Prime: GERGO
EXPORT GERGO(N)
BEGIN
// rskey.org 2016-03-02
RETURN N^N*√(2*N*π)*
e^(1/(12*N+2/(5*N+53/(42*N)))
-N);
END;
How
accurate is it?
Here
a test of some random values to compare accuracy.
Values
N
|
N!
(Determined by Wolfram Alpha)
|
N!
approximation
|
1.25
|
1.13300309631…
|
1.133039736
|
3.08
|
6.64025496878…
|
6.640255733
|
5
|
120
|
120.0000005
|
6.64
|
2460.94013688180…
|
2460.940138
|
8.27
|
72172.53628421024…
|
72172.53629
|
11.5
|
1.368433654655…
x 10^8
|
136843365.5
|
Source:
“Sterling’s
Approximation” Wikipedia – Page February
26, 2016 https://en.wikipedia.org/wiki/Stirling%27s_approximation#cite_note-Nemes2010-10
Retrieved March 1, 2016
Toth,
Viktor T. “The Gamma Function” R/S Programmable Calculators http://www.rskey.org/CMS/the-library?id=11 Retrieved March 1, 2016