1 /* specfunc/gsl_sf_gamma.h 2 * 3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or (at 8 * your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 /* Author: G. Jungman */ 21 22 #ifndef __GSL_SF_GAMMA_H__ 23 #define __GSL_SF_GAMMA_H__ 24 25 #include "gsl_sf_result.h" 26 27 #undef __BEGIN_DECLS 28 #undef __END_DECLS 29 #ifdef __cplusplus 30 # define __BEGIN_DECLS extern "C" { 31 # define __END_DECLS } 32 #else 33 # define __BEGIN_DECLS /* empty */ 34 # define __END_DECLS /* empty */ 35 #endif 36 37 __BEGIN_DECLS 38 39 40 /* Log[Gamma(x)], x not a negative integer 41 * Uses real Lanczos method. 42 * Returns the real part of Log[Gamma[x]] when x < 0, 43 * i.e. Log[|Gamma[x]|]. 44 * 45 * exceptions: GSL_EDOM, GSL_EROUND 46 */ 47 int gsl_sf_lngamma_e(double x, gsl_sf_result * result); 48 double gsl_sf_lngamma(const double x); 49 50 51 /* Log[Gamma(x)], x not a negative integer 52 * Uses real Lanczos method. Determines 53 * the sign of Gamma[x] as well as Log[|Gamma[x]|] for x < 0. 54 * So Gamma[x] = sgn * Exp[result_lg]. 55 * 56 * exceptions: GSL_EDOM, GSL_EROUND 57 */ 58 int gsl_sf_lngamma_sgn_e(double x, gsl_sf_result * result_lg, double *sgn); 59 60 61 /* Gamma(x), x not a negative integer 62 * Uses real Lanczos method. 63 * 64 * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EROUND 65 */ 66 int gsl_sf_gamma_e(const double x, gsl_sf_result * result); 67 double gsl_sf_gamma(const double x); 68 69 70 /* Regulated Gamma Function, x > 0 71 * Gamma^*(x) = Gamma(x)/(Sqrt[2Pi] x^(x-1/2) exp(-x)) 72 * = (1 + 1/(12x) + ...), x->Inf 73 * A useful suggestion of Temme. 74 * 75 * exceptions: GSL_EDOM 76 */ 77 int gsl_sf_gammastar_e(const double x, gsl_sf_result * result); 78 double gsl_sf_gammastar(const double x); 79 80 81 /* 1/Gamma(x) 82 * Uses real Lanczos method. 83 * 84 * exceptions: GSL_EUNDRFLW, GSL_EROUND 85 */ 86 int gsl_sf_gammainv_e(const double x, gsl_sf_result * result); 87 double gsl_sf_gammainv(const double x); 88 89 90 /* Log[Gamma(z)] for z complex, z not a negative integer 91 * Uses complex Lanczos method. Note that the phase part (arg) 92 * is not well-determined when |z| is very large, due 93 * to inevitable roundoff in restricting to (-Pi,Pi]. 94 * This will raise the GSL_ELOSS exception when it occurs. 95 * The absolute value part (lnr), however, never suffers. 96 * 97 * Calculates: 98 * lnr = log|Gamma(z)| 99 * arg = arg(Gamma(z)) in (-Pi, Pi] 100 * 101 * exceptions: GSL_EDOM, GSL_ELOSS 102 */ 103 int gsl_sf_lngamma_complex_e(double zr, double zi, gsl_sf_result * lnr, gsl_sf_result * arg); 104 105 106 /* x^n / n! 107 * 108 * x >= 0.0, n >= 0 109 * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW 110 */ 111 int gsl_sf_taylorcoeff_e(const int n, const double x, gsl_sf_result * result); 112 double gsl_sf_taylorcoeff(const int n, const double x); 113 114 115 /* n! 116 * 117 * exceptions: GSL_EDOM, GSL_OVRFLW 118 */ 119 int gsl_sf_fact_e(const unsigned int n, gsl_sf_result * result); 120 double gsl_sf_fact(const unsigned int n); 121 122 123 /* n!! = n(n-2)(n-4) ... 124 * 125 * exceptions: GSL_EDOM, GSL_OVRFLW 126 */ 127 int gsl_sf_doublefact_e(const unsigned int n, gsl_sf_result * result); 128 double gsl_sf_doublefact(const unsigned int n); 129 130 131 /* log(n!) 132 * Faster than ln(Gamma(n+1)) for n < 170; defers for larger n. 133 * 134 * exceptions: none 135 */ 136 int gsl_sf_lnfact_e(const unsigned int n, gsl_sf_result * result); 137 double gsl_sf_lnfact(const unsigned int n); 138 139 140 /* log(n!!) 141 * 142 * exceptions: none 143 */ 144 int gsl_sf_lndoublefact_e(const unsigned int n, gsl_sf_result * result); 145 double gsl_sf_lndoublefact(const unsigned int n); 146 147 148 /* log(n choose m) 149 * 150 * exceptions: GSL_EDOM 151 */ 152 int gsl_sf_lnchoose_e(unsigned int n, unsigned int m, gsl_sf_result * result); 153 double gsl_sf_lnchoose(unsigned int n, unsigned int m); 154 155 156 /* n choose m 157 * 158 * exceptions: GSL_EDOM, GSL_EOVRFLW 159 */ 160 int gsl_sf_choose_e(unsigned int n, unsigned int m, gsl_sf_result * result); 161 double gsl_sf_choose(unsigned int n, unsigned int m); 162 163 164 /* Logarithm of Pochhammer (Apell) symbol 165 * log( (a)_x ) 166 * where (a)_x := Gamma[a + x]/Gamma[a] 167 * 168 * a > 0, a+x > 0 169 * 170 * exceptions: GSL_EDOM 171 */ 172 int gsl_sf_lnpoch_e(const double a, const double x, gsl_sf_result * result); 173 double gsl_sf_lnpoch(const double a, const double x); 174 175 176 /* Logarithm of Pochhammer (Apell) symbol, with sign information. 177 * result = log( |(a)_x| ) 178 * sgn = sgn( (a)_x ) 179 * where (a)_x := Gamma[a + x]/Gamma[a] 180 * 181 * a != neg integer, a+x != neg integer 182 * 183 * exceptions: GSL_EDOM 184 */ 185 int gsl_sf_lnpoch_sgn_e(const double a, const double x, gsl_sf_result * result, double * sgn); 186 187 188 /* Pochhammer (Apell) symbol 189 * (a)_x := Gamma[a + x]/Gamma[x] 190 * 191 * a != neg integer, a+x != neg integer 192 * 193 * exceptions: GSL_EDOM, GSL_EOVRFLW 194 */ 195 int gsl_sf_poch_e(const double a, const double x, gsl_sf_result * result); 196 double gsl_sf_poch(const double a, const double x); 197 198 199 /* Relative Pochhammer (Apell) symbol 200 * ((a,x) - 1)/x 201 * where (a,x) = (a)_x := Gamma[a + x]/Gamma[a] 202 * 203 * exceptions: GSL_EDOM 204 */ 205 int gsl_sf_pochrel_e(const double a, const double x, gsl_sf_result * result); 206 double gsl_sf_pochrel(const double a, const double x); 207 208 209 /* Normalized Incomplete Gamma Function 210 * 211 * Q(a,x) = 1/Gamma(a) Integral[ t^(a-1) e^(-t), {t,x,Infinity} ] 212 * 213 * a >= 0, x >= 0 214 * Q(a,0) := 1 215 * Q(0,x) := 0, x != 0 216 * 217 * exceptions: GSL_EDOM 218 */ 219 int gsl_sf_gamma_inc_Q_e(const double a, const double x, gsl_sf_result * result); 220 double gsl_sf_gamma_inc_Q(const double a, const double x); 221 222 223 /* Complementary Normalized Incomplete Gamma Function 224 * 225 * P(a,x) = 1/Gamma(a) Integral[ t^(a-1) e^(-t), {t,0,x} ] 226 * 227 * a > 0, x >= 0 228 * 229 * exceptions: GSL_EDOM 230 */ 231 int gsl_sf_gamma_inc_P_e(const double a, const double x, gsl_sf_result * result); 232 double gsl_sf_gamma_inc_P(const double a, const double x); 233 234 235 /* Non-normalized Incomplete Gamma Function 236 * 237 * Gamma(a,x) := Integral[ t^(a-1) e^(-t), {t,x,Infinity} ] 238 * 239 * x >= 0.0 240 * Gamma(a, 0) := Gamma(a) 241 * 242 * exceptions: GSL_EDOM 243 */ 244 int gsl_sf_gamma_inc_e(const double a, const double x, gsl_sf_result * result); 245 double gsl_sf_gamma_inc(const double a, const double x); 246 247 248 /* Logarithm of Beta Function 249 * Log[B(a,b)] 250 * 251 * a > 0, b > 0 252 * exceptions: GSL_EDOM 253 */ 254 int gsl_sf_lnbeta_e(const double a, const double b, gsl_sf_result * result); 255 double gsl_sf_lnbeta(const double a, const double b); 256 257 int gsl_sf_lnbeta_sgn_e(const double x, const double y, gsl_sf_result * result, double * sgn); 258 259 260 /* Beta Function 261 * B(a,b) 262 * 263 * a > 0, b > 0 264 * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW 265 */ 266 int gsl_sf_beta_e(const double a, const double b, gsl_sf_result * result); 267 double gsl_sf_beta(const double a, const double b); 268 269 270 /* Normalized Incomplete Beta Function 271 * B_x(a,b)/B(a,b) 272 * 273 * a > 0, b > 0, 0 <= x <= 1 274 * exceptions: GSL_EDOM, GSL_EUNDRFLW 275 */ 276 int gsl_sf_beta_inc_e(const double a, const double b, const double x, gsl_sf_result * result); 277 double gsl_sf_beta_inc(const double a, const double b, const double x); 278 279 280 /* The maximum x such that gamma(x) is not 281 * considered an overflow. 282 */ 283 #define GSL_SF_GAMMA_XMAX 171.0 284 285 /* The maximum n such that gsl_sf_fact(n) does not give an overflow. */ 286 #define GSL_SF_FACT_NMAX 170 287 288 /* The maximum n such that gsl_sf_doublefact(n) does not give an overflow. */ 289 #define GSL_SF_DOUBLEFACT_NMAX 297 290 291 __END_DECLS 292 293 #endif /* __GSL_SF_GAMMA_H__ */ 294