summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/specfunc-gamma.texi
blob: f15e7ef0b5f9a6f2ce3a18c907e0397c045a0606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
The  functions described in this section are declared
in the header file @file{gsl_sf_gamma.h}.

@menu
* Gamma Functions::             
* Factorials::                  
* Pochhammer Symbol::           
* Incomplete Gamma Functions::  
* Beta Functions::              
* Incomplete Beta Function::    
@end menu

@node Gamma Functions
@subsection Gamma Functions
@cindex gamma functions

The Gamma function is defined by the following integral,
@tex
\beforedisplay
$$
\Gamma(x) = \int_0^{\infty} dt \, t^{x-1} \exp(-t)
$$
\afterdisplay
@end tex
@ifinfo

@example
\Gamma(x) = \int_0^\infty dt  t^@{x-1@} \exp(-t)
@end example

@end ifinfo
@noindent
It is related to the factorial function by @math{\Gamma(n)=(n-1)!}
for positive integer @math{n}.  Further information on the Gamma function
can be found in Abramowitz & Stegun, Chapter 6.  The functions
described in this section are declared in the header file
@file{gsl_sf_gamma.h}.

@deftypefun double gsl_sf_gamma (double @var{x})
@deftypefunx int gsl_sf_gamma_e (double @var{x}, gsl_sf_result * @var{result})
These routines compute the Gamma function @math{\Gamma(x)}, subject to @math{x}
not being a negative integer or zero.  The function is computed using the real
Lanczos method. The maximum value of @math{x} such that @math{\Gamma(x)} is not
considered an overflow is given by the macro @code{GSL_SF_GAMMA_XMAX}
and is 171.0.
@comment exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EROUND
@end deftypefun

@deftypefun double gsl_sf_lngamma (double @var{x})
@deftypefunx int gsl_sf_lngamma_e (double @var{x}, gsl_sf_result * @var{result})
@cindex logarithm of Gamma function
These routines compute the logarithm of the Gamma function,
@math{\log(\Gamma(x))}, subject to @math{x} not being a negative
integer or zero.  For @math{x<0} the real part of @math{\log(\Gamma(x))} is
returned, which is equivalent to @math{\log(|\Gamma(x)|)}.  The function
is computed using the real Lanczos method.
@comment exceptions: GSL_EDOM, GSL_EROUND
@end deftypefun

@deftypefun int gsl_sf_lngamma_sgn_e (double @var{x}, gsl_sf_result * @var{result_lg}, double * @var{sgn})
This routine computes the sign of the gamma function and the logarithm of
its magnitude, subject to @math{x} not being a negative integer or zero.  The
function is computed using the real Lanczos method.  The value of the
gamma function can be reconstructed using the relation @math{\Gamma(x) =
sgn * \exp(resultlg)}.
@comment exceptions: GSL_EDOM, GSL_EROUND
@end deftypefun

@deftypefun double gsl_sf_gammastar (double @var{x})
@deftypefunx int gsl_sf_gammastar_e (double @var{x}, gsl_sf_result * @var{result})
@cindex Regulated Gamma function
These routines compute the regulated Gamma Function @math{\Gamma^*(x)}
for @math{x > 0}. The regulated gamma function is given by,
@tex
\beforedisplay
$$
\eqalign{
\Gamma^*(x) &= \Gamma(x)/(\sqrt{2\pi} x^{(x-1/2)} \exp(-x))\cr
            &= \left(1 + {1 \over 12x} + ...\right) \quad\hbox{for~} x\to \infty\cr
}
$$
\afterdisplay
@end tex
@ifinfo

@example
\Gamma^*(x) = \Gamma(x)/(\sqrt@{2\pi@} x^@{(x-1/2)@} \exp(-x))
            = (1 + (1/12x) + ...)  for x \to \infty
@end example
@end ifinfo
and is a useful suggestion of Temme.
@comment exceptions: GSL_EDOM
@end deftypefun

@deftypefun double gsl_sf_gammainv (double @var{x})
@deftypefunx int gsl_sf_gammainv_e (double @var{x}, gsl_sf_result * @var{result})
@cindex Reciprocal Gamma function
These routines compute the reciprocal of the gamma function,
@math{1/\Gamma(x)} using the real Lanczos method.
@comment exceptions: GSL_EUNDRFLW, GSL_EROUND
@end deftypefun

@deftypefun int gsl_sf_lngamma_complex_e (double @var{zr}, double @var{zi}, gsl_sf_result * @var{lnr}, gsl_sf_result * @var{arg})
@cindex Complex Gamma function
This routine computes @math{\log(\Gamma(z))} for complex @math{z=z_r+i
z_i} and @math{z} not a negative integer or zero, using the complex Lanczos
method.  The returned parameters are @math{lnr = \log|\Gamma(z)|} and
@math{arg = \arg(\Gamma(z))} in @math{(-\pi,\pi]}.  Note that the phase
part (@var{arg}) is not well-determined when @math{|z|} is very large,
due to inevitable roundoff in restricting to @math{(-\pi,\pi]}.  This
will result in a @code{GSL_ELOSS} error when it occurs.  The absolute
value part (@var{lnr}), however, never suffers from loss of precision.
@comment exceptions: GSL_EDOM, GSL_ELOSS
@end deftypefun

@node Factorials
@subsection Factorials
@cindex factorial

Although factorials can be computed from the Gamma function, using
the relation @math{n! = \Gamma(n+1)} for non-negative integer @math{n},
it is usually more efficient to call the functions in this section,
particularly for small values of @math{n}, whose factorial values are
maintained in hardcoded tables.

@deftypefun double gsl_sf_fact (unsigned int @var{n})
@deftypefunx int gsl_sf_fact_e (unsigned int @var{n}, gsl_sf_result * @var{result})
@cindex factorial
These routines compute the factorial @math{n!}.  The factorial is
related to the Gamma function by @math{n! = \Gamma(n+1)}.
The maximum value of @math{n} such that @math{n!} is not
considered an overflow is given by the macro @code{GSL_SF_FACT_NMAX}
and is 170.
@comment exceptions: GSL_EDOM, GSL_OVRFLW
@end deftypefun

@deftypefun double gsl_sf_doublefact (unsigned int @var{n})
@deftypefunx int gsl_sf_doublefact_e (unsigned int @var{n}, gsl_sf_result * @var{result})
@cindex double factorial
These routines compute the double factorial @math{n!! = n(n-2)(n-4) \dots}. 
The maximum value of @math{n} such that @math{n!!} is not
considered an overflow is given by the macro @code{GSL_SF_DOUBLEFACT_NMAX}
and is 297.
@comment exceptions: GSL_EDOM, GSL_OVRFLW
@end deftypefun

@deftypefun double gsl_sf_lnfact (unsigned int @var{n})
@deftypefunx int gsl_sf_lnfact_e (unsigned int @var{n}, gsl_sf_result * @var{result})
@cindex logarithm of factorial
These routines compute the logarithm of the factorial of @var{n},
@math{\log(n!)}.  The algorithm is faster than computing
@math{\ln(\Gamma(n+1))} via @code{gsl_sf_lngamma} for @math{n < 170},
but defers for larger @var{n}.
@comment exceptions: none
@end deftypefun

@deftypefun double gsl_sf_lndoublefact (unsigned int @var{n})
@deftypefunx int gsl_sf_lndoublefact_e (unsigned int @var{n}, gsl_sf_result * @var{result})
@cindex logarithm of double factorial
These routines compute the logarithm of the double factorial of @var{n},
@math{\log(n!!)}.
@comment exceptions: none
@end deftypefun

@deftypefun double gsl_sf_choose (unsigned int @var{n}, unsigned int @var{m})
@deftypefunx int gsl_sf_choose_e (unsigned int @var{n}, unsigned int @var{m}, gsl_sf_result * @var{result})
@cindex combinatorial factor C(m,n)
These routines compute the combinatorial factor @code{n choose m}
@math{= n!/(m!(n-m)!)}
@comment exceptions: GSL_EDOM, GSL_EOVRFLW
@end deftypefun


@deftypefun double gsl_sf_lnchoose (unsigned int @var{n}, unsigned int @var{m})
@deftypefunx int gsl_sf_lnchoose_e (unsigned int @var{n}, unsigned int @var{m}, gsl_sf_result * @var{result})
@cindex logarithm of combinatorial factor C(m,n)
These routines compute the logarithm of @code{n choose m}.  This is
equivalent to the sum @math{\log(n!) - \log(m!) - \log((n-m)!)}.
@comment exceptions: GSL_EDOM 
@end deftypefun

@deftypefun double gsl_sf_taylorcoeff (int @var{n}, double @var{x})
@deftypefunx int gsl_sf_taylorcoeff_e (int @var{n}, double @var{x}, gsl_sf_result * @var{result})
@cindex Taylor coefficients, computation of
These routines compute the Taylor coefficient @math{x^n / n!} for 
@c{$x \ge 0$}
@math{x >= 0}, 
@c{$n \ge 0$}
@math{n >= 0}.
@comment exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
@end deftypefun

@node Pochhammer Symbol
@subsection Pochhammer Symbol

@deftypefun double gsl_sf_poch (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_poch_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex Pochhammer symbol
@cindex Apell symbol, see Pochammer symbol
These routines compute the Pochhammer symbol @math{(a)_x = \Gamma(a +
x)/\Gamma(a)}, subject to @math{a} and @math{a+x} not being negative
integers or zero. The Pochhammer symbol is also known as the Apell symbol and
sometimes written as @math{(a,x)}.
@comment exceptions:  GSL_EDOM, GSL_EOVRFLW
@end deftypefun


@deftypefun double gsl_sf_lnpoch (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_lnpoch_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex logarithm of Pochhammer symbol
These routines compute the logarithm of the Pochhammer symbol,
@math{\log((a)_x) = \log(\Gamma(a + x)/\Gamma(a))} for @math{a > 0},
@math{a+x > 0}.
@comment exceptions:  GSL_EDOM
@end deftypefun

@deftypefun int gsl_sf_lnpoch_sgn_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result}, double * @var{sgn})
These routines compute the sign of the Pochhammer symbol and the
logarithm of its magnitude.  The computed parameters are @math{result =
\log(|(a)_x|)} and @math{sgn = \sgn((a)_x)} where @math{(a)_x =
\Gamma(a + x)/\Gamma(a)}, subject to @math{a}, @math{a+x} not being
negative integers or zero.
@comment exceptions:  GSL_EDOM
@end deftypefun

@deftypefun double gsl_sf_pochrel (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_pochrel_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex relative Pochhammer symbol
These routines compute the relative Pochhammer symbol @math{((a)_x -
1)/x} where @math{(a)_x = \Gamma(a + x)/\Gamma(a)}.
@comment exceptions:  GSL_EDOM
@end deftypefun


@node Incomplete Gamma Functions
@subsection Incomplete Gamma Functions

@deftypefun double gsl_sf_gamma_inc (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_gamma_inc_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex non-normalized incomplete Gamma function
@cindex unnormalized incomplete Gamma function
These functions compute the unnormalized incomplete Gamma Function
@c{$\Gamma(a,x) = \int_x^\infty dt\, t^{(a-1)} \exp(-t)$}
@math{\Gamma(a,x) = \int_x^\infty dt t^@{a-1@} \exp(-t)}
for @math{a} real and @c{$x \ge 0$}
@math{x >= 0}.
@comment exceptions: GSL_EDOM
@end deftypefun

@deftypefun double gsl_sf_gamma_inc_Q (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_gamma_inc_Q_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex incomplete Gamma function
These routines compute the normalized incomplete Gamma Function
@c{$Q(a,x) = 1/\Gamma(a) \int_x^\infty dt\, t^{(a-1)} \exp(-t)$}
@math{Q(a,x) = 1/\Gamma(a) \int_x^\infty dt t^@{a-1@} \exp(-t)}
for @math{a > 0}, @c{$x \ge 0$}
@math{x >= 0}.
@comment exceptions: GSL_EDOM
@end deftypefun

@deftypefun double gsl_sf_gamma_inc_P (double @var{a}, double @var{x})
@deftypefunx int gsl_sf_gamma_inc_P_e (double @var{a}, double @var{x}, gsl_sf_result * @var{result})
@cindex complementary incomplete Gamma function
These routines compute the complementary normalized incomplete Gamma Function
@c{$P(a,x) = 1 - Q(a,x) = 1/\Gamma(a) \int_0^x dt\, t^{(a-1)} \exp(-t)$}
@math{P(a,x) = 1 - Q(a,x) = 1/\Gamma(a) \int_0^x dt t^@{a-1@} \exp(-t)}
for @math{a > 0}, @c{$x \ge 0$}
@math{x >= 0}. 

Note that Abramowitz & Stegun call @math{P(a,x)} the incomplete gamma
function (section 6.5).
@comment exceptions: GSL_EDOM
@end deftypefun

@node Beta Functions
@subsection Beta Functions

@deftypefun double gsl_sf_beta (double @var{a}, double @var{b})
@deftypefunx int gsl_sf_beta_e (double @var{a}, double @var{b}, gsl_sf_result * @var{result})
@cindex Beta function
These routines compute the Beta Function, @math{B(a,b) =
\Gamma(a)\Gamma(b)/\Gamma(a+b)} subject to @math{a} and @math{b} not
being negative integers.
@comment exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
@end deftypefun

@deftypefun double gsl_sf_lnbeta (double @var{a}, double @var{b})
@deftypefunx int gsl_sf_lnbeta_e (double @var{a}, double @var{b}, gsl_sf_result * @var{result})
@cindex logarithm of Beta function
These routines compute the logarithm of the Beta Function, @math{\log(B(a,b))}
subject to @math{a} and @math{b} not
being negative integers.
@comment exceptions: GSL_EDOM
@end deftypefun

@node Incomplete Beta Function
@subsection Incomplete Beta Function

@deftypefun double gsl_sf_beta_inc (double @var{a}, double @var{b}, double @var{x})
@deftypefunx int gsl_sf_beta_inc_e (double @var{a}, double @var{b}, double @var{x}, gsl_sf_result * @var{result})
@cindex incomplete Beta function, normalized
@cindex normalized incomplete Beta function
@cindex Beta function, incomplete normalized 
These routines compute the normalized incomplete Beta function
@math{I_x(a,b)=B_x(a,b)/B(a,b)} where @c{$B_x(a,b) = \int_0^x t^{a-1} (1-t)^{b-1} dt$}
@math{B_x(a,b) = \int_0^x t^@{a-1@} (1-t)^@{b-1@} dt}
for @math{a > 0}, @math{b > 0}, and @c{$0 \le x \le 1$}
@math{0 <= x <= 1}. 
@end deftypefun