Function Repository Resource:

StirlingsFormula

Source Notebook

Compute an approximation to a factorial with Stirling's formula

Contributed by: Peter Cullen Burbery

ResourceFunction["StirlingsFormula"][n]

computes an approximation to n! with Stirling’s formula.

Examples

Basic Examples (4) 

Compute an approximation for 5!:

In[1]:=
ResourceFunction["StirlingsFormula"][5]
Out[1]=
In[2]:=
N[(3125 Sqrt[10 \[Pi]])/E^5]
Out[2]=

Compute the absolute error by comparing to 5!:

In[3]:=
N[(3125 Sqrt[10 \[Pi]])/E^5 - 5!]
Out[3]=

Compute the relative error:

In[4]:=
N[(3125 Sqrt[10 \[Pi]])/E^5 - 5!]/5!
Out[4]=

Compute the relative error for 2018!:

In[5]:=
N[(ResourceFunction["StirlingsFormula"][2018] - 2018!)/2018!, 100]
Out[5]=

Properties and Relations (1) 

The formula can be computed with DiscreteAsymptotic:

In[6]:=
DiscreteAsymptotic[n!, n -> \[Infinity]]
Out[6]=

Publisher

Peter Burbery

Version History

  • 1.0.0 – 30 August 2022

Related Resources

License Information