Stirling's Series

Author

Eric W. Weisstein
December 30, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Calculus/StirlingsSeries.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/StirlingsSeries.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Code

PermutationCyclesD::usage="PermutationCyclesD[r,n,k] gives the number of permutations of {1, 2, ..., n} having exactly k cycles, each of which is of length >=r."

PermutationCyclesD2::usage="PermutationCyclesD2[r,n,k] gives the number of permutations of {1, 2, ..., n} having exactly k cycles, each of which is of length >=r
by explicitly counting them."

StirlingCoefficient::usage="StirlingCoefficient[n] gives the coefficient of z^(-n) in Stirling's asymptotic series for Gamma[n]."

AssociatedStirlingS1[n_,k_]:=PermutationCyclesD[2,n,k]

(*Permutation Cycles*)
(*PermutationCyclesD[r_,0,0]:=1*)PermutationCyclesD[r_,n_,k_]:=0/;n≤k r-1
PermutationCyclesD[r_,n_,1]:=(n-1)!
PermutationCyclesD[r_,n_,k_]:=PermutationCyclesD[r,n,k]=(n-1)PermutationCyclesD[r,n-1,k]+(-1)^(r-1)Pochhammer[-(n-1),r-1]*PermutationCyclesD[r,n-r,k-1]

(*Explicitly compute them;VERY inefficient but useful for checking*)

PermutationCyclesD2[r_,n_,k_]:=Module[{c=Map[Length,ToCycles/@Permutations[Range[n]],{2}]},Length[Select[c,Min[#]≥r&&Length[#]==k&]]]

(*Stirling Coefficient*)
StirlingCoefficient[0]:=1
StirlingCoefficient[n_Integer?Positive]:=Module[{k},Sum[(-1)^k PermutationCyclesD[3,2n+2k,k]/2^(n+k)/(n+k)!,{k,2n}]]

Sums

(∑_n^∞)((BernoulliB[2 n])/(2 n (2 n-1) (z^(2 n-1))))-z+(z-(1/2)) log(z)+(1/2) log(2 π)==(LogGamma[z])

(1/2)Log[2π]+(z-(1/2))Log[z]-z+Sum[((BernoulliB[2n])/(2n(2n-1)(z^(2n-1)))),{n,∞}]

(1/2)Log[2π]+(z-(1/2))Log[z]-z+Sum[((BernoulliB[2n])/(2n(2n-1)(z^(2n-1)))),{n,∞},Regularization->"Borel"]//Timing

(1/2)Log[2π]+(z-(1/2))Log[z]-z+Sum[((BernoulliB[2n])/(2n(2n-1)(z^(2n-1)))),{n,∞},Regularization->"Dirichlet"]//Timing

With[{z=10^3.},{(1/2)Log[2π]+(z-(1/2))Log[z]-z+Sum[((BernoulliB[2n])/(2n(2n-1)(z^(2n-1)))),{n,1000}],LogGamma[z]}]

Permutation Numbers

<<Combinatorica`

PermutationCyclesD[r_,n_,k_]:=0/;n≤k r-1
PermutationCyclesD[r_,n_,1]:=(n-1)!
PermutationCyclesD[r_,n_,k_]:=PermutationCyclesD[r,n,k]=(n-1)PermutationCyclesD[r,n-1,k]+(-1)^(r-1)Pochhammer[-(n-1),r-1]*PermutationCyclesD[r,n-r,k-1]

PermutationCyclesD2[r_,n_,k_]:=Module[{c=Map[Length,ToCycles/@Permutations[Range[n]],{2}]},Length[Select[c,Min[#]≥r&&Length[#]==k&]]]

D3[k_,n_]:=Block[{x,t},(((-1))^k)k!SeriesCoefficient[(1+t)^(-x)*Exp[x*(t-t^2/2)],{t,0,k},{x,0,n}]]

l1=Table[PermutationCyclesD[3,n,k],{n,10},{k,10}]

Table[D3[n,k],{n,10},{k,10}]

l2=Table[(-1)^k k!SeriesCoefficient[(1+t)^(-x)*Exp[x*(t-t^2/2)],{t,0,k},{x,0,n}],{k,10},{n,10}]

l1-l2

SeriesCoefficient[(1+t)^(-x)*Exp[x*(t-t^2/2)],{t,0,k},{x,0,n}]

Series

SeriesCoefficient[LogGamma[z],{z,∞,n}]

SeriesCoefficient[Gamma[z]/Sqrt[2Pi z]/z^z Exp[z],{z,∞,n}]

Series[Gamma[z]/Sqrt[2Pi z]/z^z Exp[z],{z,∞,5}]//FullSimplify

SeriesCoefficient[LogGamma[z]-(1/2)Log[2π]-(z-(1/2))Log[z]+z,{z,∞,n}]

Series[LogGamma[z]-(1/2)Log[2π]-(z-(1/2))Log[z]+z,{z,∞,10}]//FullSimplify

Sum[BernoulliB[2n]/(2n(2n-1)z^(2n-1)),{n,5}]

Table[Piecewise[{{BernoulliB[-n]/(-n (-n-1)),Mod[n,2]==0&&n<0}}],{n,-10,10}]

Asymptotic Series

n!

Series[n!,{n,Infinity,10}]/(Sqrt[2Pi n]n^n Exp[n])

Simplify[PowerExpand[Normal[Series[n!,{n,Infinity,10}]]]/Sqrt[2Pi n]/n^n Exp[n]]

log(Γ(z))

V4.2

Series[Log[Gamma[z]],{z,∞,10}]//PowerExpand

V5.0

Series[Log[Gamma[z]],{z,∞,10}]//PowerExpand

Simplify[%]

Simplify[Normal[%]]

Table[BernoulliB[2n]/(2n(2n-1)z^(2n-1)),{n,5}]

V7

Series[LogGamma[z],{z,∞,10}]

Simplify[PowerExpand[%]]

Simplify[Normal[%]]

Analytic Coefficients

Table[Sum[(((-1))^k)((D3[2n+2k,k])/((2^(n+k))(n+k)!)),{k,2n}],{n,0,3}]

a[n_]:=Module[{k},Sum[(-1)^k PermutationCyclesD[3,2n+2k,k]/2^(n+k)/(n+k)!,{k,2n}]]

Table[a[n],{n,10}]

b[0]:=1
b[1]:=1
b[n_]:=b[n]=Module[{k},
(b[n-1]-Sum[k b[k] b[n+1-k],{k,2,n-1}])/(n+1)
]

Table[b[n],{n,6}]

c[k_]:=(2k+1)!! b[2k+1]

Table[c[n],{n,5}]

Table[StirlingCoefficient[n],{n,10}]

CoefficientList[Exp[x]/x^x Sqrt[x/(2Pi)]Series[Gamma[x],{x,Infinity,5}],1/x]

FullSimplify[%]

Leading Term

Integrate[Exp[-ξ^2/2/n],{ξ,-Infinity,Infinity},Assumptions->Re[n]>0]

⌊((n^n)/(n!))⌋

Table[Floor[n^n/n!],{n,10}]

Table[Exp[n]/Sqrt[Pi 2n],{n,10}]//N

Numerator Differs from Numerator (Subscript[B, 2n])/(2n)

<<Utilities`Date`

l1={};
l2={};
Do[
If[GCD[r=Numerator[b=BernoulliB[2n]/(2n)],2n-1]>1,
v=r/Numerator[b/(2n-1)];
AppendTo[l1,n];
AppendTo[l2,v];Print[{n,v,YMDHMS[Date[]]}]];
If[Mod[n,100]==0,Print[n,"..."]],
{n,2600,5000}];
{l1,l2}

{l1,l2}

l1={574,1185,1240,1269,1376,1906,1910,2572,2689,2980,3238,3384,3801,3904,4121,4570,4691,4789,5236,5862,5902,6227,6332,6402,6438,6568,7234,7900,8113,8434,8543,8557,8566,9232,9611,9670,9824,9891,9898,10564,10587,10754,11230,11247};
l2={37,103,37,59,131,37,67,37,283,59,37,101,691,37,67,37,59,157,37,617,37,593,67,59,103,37,37,37,59,101,67,157,37,37,149,233,59,131,37,37,683,67,37,271};

Length/@{l1,l2}

l1[[40]]