1@menu
2* Functions and Variables for stirling::
3@end menu
4
5@node Functions and Variables for stirling,  , stirling-pkg, stirling-pkg
6@section Functions and Variables for stirling
7
8@deffn {Function} stirling @
9@fname{stirling} (@var{z},@var{n}) @
10@fname{stirling} (@var{z},@var{n},@var{pred})
11
12Replace @code{gamma(x)} with the @math{O(1/x^(2n-1))} Stirling formula. when @var{n} isn't
13a nonnegative integer, signal an error. With the optional third argument @code{pred},
14the Stirling formula is applied only when @code{pred} is true.
15
16Reference: Abramowitz & Stegun, " Handbook of mathematical functions", 6.1.40.
17
18Examples:
19@example
20(%i1) load ("stirling")$
21
22(%i2) stirling(gamma(%alpha+x)/gamma(x),1);
23       1/2 - x             x + %alpha - 1/2
24(%o2) x        (x + %alpha)
25                                   1           1
26                            --------------- - ---- - %alpha
27                            12 (x + %alpha)   12 x
28                          %e
29(%i3) taylor(%,x,inf,1);
30                    %alpha       2    %alpha
31          %alpha   x       %alpha  - x       %alpha
32(%o3)/T/ x       + -------------------------------- + . . .
33                                 2 x
34(%i4) map('factor,%);
35                                       %alpha - 1
36         %alpha   (%alpha - 1) %alpha x
37(%o4)   x       + -------------------------------
38                                  2
39@end example
40
41The function @code{stirling} knows the difference between the variable 'gamma' and
42the function gamma:
43
44@example
45(%i5) stirling(gamma + gamma(x),0);
46                                    x - 1/2   - x
47(%o5)    gamma + sqrt(2) sqrt(%pi) x        %e
48(%i6) stirling(gamma(y) + gamma(x),0);
49                         y - 1/2   - y
50(%o6) sqrt(2) sqrt(%pi) y        %e
51                                              x - 1/2   - x
52                         + sqrt(2) sqrt(%pi) x        %e
53@end example
54
55To apply the Stirling formula only to terms that involve the variable @code{k},
56use an optional third argument; for example
57@example
58(%i7) makegamma(pochhammer(a,k)/pochhammer(b,k));
59(%o7) (gamma(b)*gamma(k+a))/(gamma(a)*gamma(k+b))
60(%i8) stirling(%,1, lambda([s], not(freeof(k,s))));
61(%o8) (%e^(b-a)*gamma(b)*(k+a)^(k+a-1/2)*(k+b)^(-k-b+1/2))/gamma(a)
62@end example
63The terms @code{gamma(a)} and @code{gamma(b)} are free of @code{k}, so the Stirling formula
64was not applied to these two terms.
65
66To use this function write first @code{load("stirling")}.
67
68@opencatbox
69@category{Gamma and factorial functions}
70@category{Share packages}
71@category{Package stirling}
72@closecatbox
73
74@end deffn
75