2 * Functions and Variables for stirling::
5 @node Functions and Variables for stirling, , Package stirling, Package stirling
6 @section Functions and Variables for stirling
9 @deffn {Function} stirling @
10 @fname{stirling} (@var{z},@var{n}) @
11 @fname{stirling} (@var{z},@var{n},@var{pred})
13 Replace @code{gamma(x)} with the @math{O(1/x^{2n-1})} Stirling formula. when @var{n} isn't
14 a nonnegative integer, signal an error. With the optional third argument @code{pred},
15 the Stirling formula is applied only when @code{pred} is true.
17 Reference: Abramowitz & Stegun, " Handbook of mathematical functions", 6.1.40.
21 (%i1) load ("stirling")$
23 (%i2) stirling(gamma(%alpha+x)/gamma(x),1);
24 1/2 - x x + %alpha - 1/2
27 --------------- - ---- - %alpha
30 (%i3) taylor(%,x,inf,1);
32 %alpha x %alpha - x %alpha
33 (%o3)/T/ x + -------------------------------- + . . .
37 %alpha (%alpha - 1) %alpha x
38 (%o4) x + -------------------------------
42 The function @code{stirling} knows the difference between the variable 'gamma' and
46 (%i5) stirling(gamma + gamma(x),0);
48 (%o5) gamma + sqrt(2) sqrt(%pi) x %e
49 (%i6) stirling(gamma(y) + gamma(x),0);
51 (%o6) sqrt(2) sqrt(%pi) y %e
53 + sqrt(2) sqrt(%pi) x %e
56 To apply the Stirling formula only to terms that involve the variable @code{k},
57 use an optional third argument; for example
59 (%i7) makegamma(pochhammer(a,k)/pochhammer(b,k));
60 (%o7) (gamma(b)*gamma(k+a))/(gamma(a)*gamma(k+b))
61 (%i8) stirling(%,1, lambda([s], not(freeof(k,s))));
62 (%o8) (%e^(b-a)*gamma(b)*(k+a)^(k+a-1/2)*(k+b)^(-k-b+1/2))/gamma(a)
64 The terms @code{gamma(a)} and @code{gamma(b)} are free of @code{k}, so the Stirling formula
65 was not applied to these two terms.
67 To use this function write first @code{load("stirling")}.
69 @opencatbox{Categories:}
70 @category{Gamma and factorial functions}
71 @category{Share packages}
72 @category{Package stirling}