gsl_sf_gamma.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. /* Author: G. Jungman */
  20. #ifndef __GSL_SF_GAMMA_H__
  21. #define __GSL_SF_GAMMA_H__
  22. #include "gsl_sf_result.h"
  23. #undef __BEGIN_DECLS
  24. #undef __END_DECLS
  25. #ifdef __cplusplus
  26. # define __BEGIN_DECLS extern "C" {
  27. # define __END_DECLS }
  28. #else
  29. # define __BEGIN_DECLS /* empty */
  30. # define __END_DECLS /* empty */
  31. #endif
  32. __BEGIN_DECLS
  33. /* Log[Gamma(x)], x not a negative integer
  34. * Uses real Lanczos method.
  35. * Returns the real part of Log[Gamma[x]] when x < 0,
  36. * i.e. Log[|Gamma[x]|].
  37. *
  38. * exceptions: GSL_EDOM, GSL_EROUND
  39. */
  40. int gsl_sf_lngamma_e(double x, gsl_sf_result * result);
  41. double gsl_sf_lngamma(const double x);
  42. /* Log[Gamma(x)], x not a negative integer
  43. * Uses real Lanczos method. Determines
  44. * the sign of Gamma[x] as well as Log[|Gamma[x]|] for x < 0.
  45. * So Gamma[x] = sgn * Exp[result_lg].
  46. *
  47. * exceptions: GSL_EDOM, GSL_EROUND
  48. */
  49. int gsl_sf_lngamma_sgn_e(double x, gsl_sf_result * result_lg, double *sgn);
  50. /* Gamma(x), x not a negative integer
  51. * Uses real Lanczos method.
  52. *
  53. * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EROUND
  54. */
  55. int gsl_sf_gamma_e(const double x, gsl_sf_result * result);
  56. double gsl_sf_gamma(const double x);
  57. /* Regulated Gamma Function, x > 0
  58. * Gamma^*(x) = Gamma(x)/(Sqrt[2Pi] x^(x-1/2) exp(-x))
  59. * = (1 + 1/(12x) + ...), x->Inf
  60. * A useful suggestion of Temme.
  61. *
  62. * exceptions: GSL_EDOM
  63. */
  64. int gsl_sf_gammastar_e(const double x, gsl_sf_result * result);
  65. double gsl_sf_gammastar(const double x);
  66. /* 1/Gamma(x)
  67. * Uses real Lanczos method.
  68. *
  69. * exceptions: GSL_EUNDRFLW, GSL_EROUND
  70. */
  71. int gsl_sf_gammainv_e(const double x, gsl_sf_result * result);
  72. double gsl_sf_gammainv(const double x);
  73. /* Log[Gamma(z)] for z complex, z not a negative integer
  74. * Uses complex Lanczos method. Note that the phase part (arg)
  75. * is not well-determined when |z| is very large, due
  76. * to inevitable roundoff in restricting to (-Pi,Pi].
  77. * This will raise the GSL_ELOSS exception when it occurs.
  78. * The absolute value part (lnr), however, never suffers.
  79. *
  80. * Calculates:
  81. * lnr = log|Gamma(z)|
  82. * arg = arg(Gamma(z)) in (-Pi, Pi]
  83. *
  84. * exceptions: GSL_EDOM, GSL_ELOSS
  85. */
  86. int gsl_sf_lngamma_complex_e(double zr, double zi, gsl_sf_result * lnr, gsl_sf_result * arg);
  87. /* x^n / n!
  88. *
  89. * x >= 0.0, n >= 0
  90. * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
  91. */
  92. int gsl_sf_taylorcoeff_e(const int n, const double x, gsl_sf_result * result);
  93. double gsl_sf_taylorcoeff(const int n, const double x);
  94. /* n!
  95. *
  96. * exceptions: GSL_EDOM, GSL_OVRFLW
  97. */
  98. int gsl_sf_fact_e(const unsigned int n, gsl_sf_result * result);
  99. double gsl_sf_fact(const unsigned int n);
  100. /* n!! = n(n-2)(n-4) ...
  101. *
  102. * exceptions: GSL_EDOM, GSL_OVRFLW
  103. */
  104. int gsl_sf_doublefact_e(const unsigned int n, gsl_sf_result * result);
  105. double gsl_sf_doublefact(const unsigned int n);
  106. /* log(n!)
  107. * Faster than ln(Gamma(n+1)) for n < 170; defers for larger n.
  108. *
  109. * exceptions: none
  110. */
  111. int gsl_sf_lnfact_e(const unsigned int n, gsl_sf_result * result);
  112. double gsl_sf_lnfact(const unsigned int n);
  113. /* log(n!!)
  114. *
  115. * exceptions: none
  116. */
  117. int gsl_sf_lndoublefact_e(const unsigned int n, gsl_sf_result * result);
  118. double gsl_sf_lndoublefact(const unsigned int n);
  119. /* log(n choose m)
  120. *
  121. * exceptions: GSL_EDOM
  122. */
  123. int gsl_sf_lnchoose_e(unsigned int n, unsigned int m, gsl_sf_result * result);
  124. double gsl_sf_lnchoose(unsigned int n, unsigned int m);
  125. /* n choose m
  126. *
  127. * exceptions: GSL_EDOM, GSL_EOVRFLW
  128. */
  129. int gsl_sf_choose_e(unsigned int n, unsigned int m, gsl_sf_result * result);
  130. double gsl_sf_choose(unsigned int n, unsigned int m);
  131. /* Logarithm of Pochhammer (Apell) symbol
  132. * log( (a)_x )
  133. * where (a)_x := Gamma[a + x]/Gamma[a]
  134. *
  135. * a > 0, a+x > 0
  136. *
  137. * exceptions: GSL_EDOM
  138. */
  139. int gsl_sf_lnpoch_e(const double a, const double x, gsl_sf_result * result);
  140. double gsl_sf_lnpoch(const double a, const double x);
  141. /* Logarithm of Pochhammer (Apell) symbol, with sign information.
  142. * result = log( |(a)_x| )
  143. * sgn = sgn( (a)_x )
  144. * where (a)_x := Gamma[a + x]/Gamma[a]
  145. *
  146. * a != neg integer, a+x != neg integer
  147. *
  148. * exceptions: GSL_EDOM
  149. */
  150. int gsl_sf_lnpoch_sgn_e(const double a, const double x, gsl_sf_result * result, double * sgn);
  151. /* Pochhammer (Apell) symbol
  152. * (a)_x := Gamma[a + x]/Gamma[x]
  153. *
  154. * a != neg integer, a+x != neg integer
  155. *
  156. * exceptions: GSL_EDOM, GSL_EOVRFLW
  157. */
  158. int gsl_sf_poch_e(const double a, const double x, gsl_sf_result * result);
  159. double gsl_sf_poch(const double a, const double x);
  160. /* Relative Pochhammer (Apell) symbol
  161. * ((a,x) - 1)/x
  162. * where (a,x) = (a)_x := Gamma[a + x]/Gamma[a]
  163. *
  164. * exceptions: GSL_EDOM
  165. */
  166. int gsl_sf_pochrel_e(const double a, const double x, gsl_sf_result * result);
  167. double gsl_sf_pochrel(const double a, const double x);
  168. /* Normalized Incomplete Gamma Function
  169. *
  170. * Q(a,x) = 1/Gamma(a) Integral[ t^(a-1) e^(-t), {t,x,Infinity} ]
  171. *
  172. * a >= 0, x >= 0
  173. * Q(a,0) := 1
  174. * Q(0,x) := 0, x != 0
  175. *
  176. * exceptions: GSL_EDOM
  177. */
  178. int gsl_sf_gamma_inc_Q_e(const double a, const double x, gsl_sf_result * result);
  179. double gsl_sf_gamma_inc_Q(const double a, const double x);
  180. /* Complementary Normalized Incomplete Gamma Function
  181. *
  182. * P(a,x) = 1/Gamma(a) Integral[ t^(a-1) e^(-t), {t,0,x} ]
  183. *
  184. * a > 0, x >= 0
  185. *
  186. * exceptions: GSL_EDOM
  187. */
  188. int gsl_sf_gamma_inc_P_e(const double a, const double x, gsl_sf_result * result);
  189. double gsl_sf_gamma_inc_P(const double a, const double x);
  190. /* Non-normalized Incomplete Gamma Function
  191. *
  192. * Gamma(a,x) := Integral[ t^(a-1) e^(-t), {t,x,Infinity} ]
  193. *
  194. * x >= 0.0
  195. * Gamma(a, 0) := Gamma(a)
  196. *
  197. * exceptions: GSL_EDOM
  198. */
  199. int gsl_sf_gamma_inc_e(const double a, const double x, gsl_sf_result * result);
  200. double gsl_sf_gamma_inc(const double a, const double x);
  201. /* Logarithm of Beta Function
  202. * Log[B(a,b)]
  203. *
  204. * a > 0, b > 0
  205. * exceptions: GSL_EDOM
  206. */
  207. int gsl_sf_lnbeta_e(const double a, const double b, gsl_sf_result * result);
  208. double gsl_sf_lnbeta(const double a, const double b);
  209. int gsl_sf_lnbeta_sgn_e(const double x, const double y, gsl_sf_result * result, double * sgn);
  210. /* Beta Function
  211. * B(a,b)
  212. *
  213. * a > 0, b > 0
  214. * exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
  215. */
  216. int gsl_sf_beta_e(const double a, const double b, gsl_sf_result * result);
  217. double gsl_sf_beta(const double a, const double b);
  218. /* Normalized Incomplete Beta Function
  219. * B_x(a,b)/B(a,b)
  220. *
  221. * a > 0, b > 0, 0 <= x <= 1
  222. * exceptions: GSL_EDOM, GSL_EUNDRFLW
  223. */
  224. int gsl_sf_beta_inc_e(const double a, const double b, const double x, gsl_sf_result * result);
  225. double gsl_sf_beta_inc(const double a, const double b, const double x);
  226. /* The maximum x such that gamma(x) is not
  227. * considered an overflow.
  228. */
  229. #define GSL_SF_GAMMA_XMAX 171.0
  230. /* The maximum n such that gsl_sf_fact(n) does not give an overflow. */
  231. #define GSL_SF_FACT_NMAX 170
  232. /* The maximum n such that gsl_sf_doublefact(n) does not give an overflow. */
  233. #define GSL_SF_DOUBLEFACT_NMAX 297
  234. __END_DECLS
  235. #endif /* __GSL_SF_GAMMA_H__ */