Blame doc/specfunc-gamma.rst

Packit 67cb25
The following routines compute the gamma and beta functions in their
Packit 67cb25
full and incomplete forms, as well as various kinds of factorials.
Packit 67cb25
The functions described in this section are declared in the header
Packit 67cb25
file :file:`gsl_sf_gamma.h`.
Packit 67cb25
Packit 67cb25
Gamma Functions
Packit 67cb25
---------------
Packit 67cb25
.. index:: gamma functions
Packit 67cb25
Packit 67cb25
The Gamma function is defined by the following integral,
Packit 67cb25
Packit 67cb25
.. math:: \Gamma(x) = \int_0^{\infty} dt t^{x-1} \exp(-t)
Packit 67cb25
Packit 67cb25
It is related to the factorial function by :math:`\Gamma(n) = (n-1)!`
Packit 67cb25
for positive integer :math:`n`.  Further information on the Gamma function
Packit 67cb25
can be found in Abramowitz & Stegun, Chapter 6.  
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gamma (double x)
Packit 67cb25
              int gsl_sf_gamma_e (double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the Gamma function :math:`\Gamma(x)`, subject to :math:`x`
Packit 67cb25
   not being a negative integer or zero.  The function is computed using the real
Packit 67cb25
   Lanczos method. The maximum value of :math:`x` such that :math:`\Gamma(x)` is not
Packit 67cb25
   considered an overflow is given by the macro :macro:`GSL_SF_GAMMA_XMAX`
Packit 67cb25
   and is 171.0.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EROUND
Packit 67cb25
Packit 67cb25
.. index:: logarithm of Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lngamma (double x)
Packit 67cb25
              int gsl_sf_lngamma_e (double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of the Gamma function,
Packit 67cb25
   :math:`\log(\Gamma(x))`, subject to :math:`x` not being a negative
Packit 67cb25
   integer or zero.  For :math:`x < 0` the real part of :math:`\log(\Gamma(x))` is
Packit 67cb25
   returned, which is equivalent to :math:`\log(|\Gamma(x)|)`.  The function
Packit 67cb25
   is computed using the real Lanczos method.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EROUND
Packit 67cb25
Packit 67cb25
.. function:: int gsl_sf_lngamma_sgn_e (double x, gsl_sf_result * result_lg, double * sgn)
Packit 67cb25
Packit 67cb25
   This routine computes the sign of the gamma function and the logarithm of
Packit 67cb25
   its magnitude, subject to :math:`x` not being a negative integer or zero.  The
Packit 67cb25
   function is computed using the real Lanczos method.  The value of the
Packit 67cb25
   gamma function and its error can be reconstructed using the relation 
Packit 67cb25
   :math:`\Gamma(x) = sgn * \exp(result\_lg)`, taking into account the two 
Packit 67cb25
   components of :data:`result_lg`.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EROUND
Packit 67cb25
Packit 67cb25
.. index:: Regulated Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gammastar (double x)
Packit 67cb25
              int gsl_sf_gammastar_e (double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the regulated Gamma Function :math:`\Gamma^*(x)`
Packit 67cb25
   for :math:`x > 0`. The regulated gamma function is given by,
Packit 67cb25
Packit 67cb25
   .. only:: not texinfo
Packit 67cb25
Packit 67cb25
      .. math::
Packit 67cb25
Packit 67cb25
         \Gamma^*(x) &= \Gamma(x)/(\sqrt{2\pi} x^{(x-1/2)} \exp(-x))\cr
Packit 67cb25
                     &= \left(1 + {1 \over 12x} + ...\right) \quad\hbox{for~} x\to \infty\cr
Packit 67cb25
Packit 67cb25
   .. only:: texinfo
Packit 67cb25
Packit 67cb25
      ::
Packit 67cb25
Packit 67cb25
         \Gamma^*(x) = \Gamma(x)/(\sqrt{2\pi} x^{(x-1/2)} \exp(-x))
Packit 67cb25
                     = (1 + (1/12x) + ...)  for x \to \infty
Packit 67cb25
Packit 67cb25
   and is a useful suggestion of Temme.
Packit 67cb25
.. exceptions: GSL_EDOM
Packit 67cb25
Packit 67cb25
.. index:: Reciprocal Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gammainv (double x)
Packit 67cb25
              int gsl_sf_gammainv_e (double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the reciprocal of the gamma function,
Packit 67cb25
   :math:`1/\Gamma(x)` using the real Lanczos method.
Packit 67cb25
.. exceptions: GSL_EUNDRFLW, GSL_EROUND
Packit 67cb25
Packit 67cb25
.. index:: Complex Gamma function
Packit 67cb25
Packit 67cb25
.. function:: int gsl_sf_lngamma_complex_e (double zr, double zi, gsl_sf_result * lnr, gsl_sf_result * arg)
Packit 67cb25
Packit 67cb25
   This routine computes :math:`\log(\Gamma(z))` for complex :math:`z = z_r + i z_i`
Packit 67cb25
   and :math:`z` not a negative integer or zero, using the complex Lanczos
Packit 67cb25
   method.  The returned parameters are :math:`lnr = \log|\Gamma(z)|` and
Packit 67cb25
   :math:`arg = \arg(\Gamma(z))` in :math:`(-\pi,\pi]`.  Note that the phase
Packit 67cb25
   part (:data:`arg`) is not well-determined when :math:`|z|` is very large,
Packit 67cb25
   due to inevitable roundoff in restricting to :math:`(-\pi,\pi]`.  This
Packit 67cb25
   will result in a :macro:`GSL_ELOSS` error when it occurs.  The absolute
Packit 67cb25
   value part (:data:`lnr`), however, never suffers from loss of precision.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_ELOSS
Packit 67cb25
Packit 67cb25
Factorials
Packit 67cb25
----------
Packit 67cb25
.. index:: factorial
Packit 67cb25
Packit 67cb25
Although factorials can be computed from the Gamma function, using
Packit 67cb25
the relation :math:`n! = \Gamma(n+1)` for non-negative integer :math:`n`,
Packit 67cb25
it is usually more efficient to call the functions in this section,
Packit 67cb25
particularly for small values of :math:`n`, whose factorial values are
Packit 67cb25
maintained in hardcoded tables.
Packit 67cb25
Packit 67cb25
.. index:: factorial
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_fact (unsigned int n)
Packit 67cb25
              int gsl_sf_fact_e (unsigned int n, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the factorial :math:`n!`.  The factorial is
Packit 67cb25
   related to the Gamma function by :math:`n! = \Gamma(n+1)`.
Packit 67cb25
   The maximum value of :math:`n` such that :math:`n!` is not
Packit 67cb25
   considered an overflow is given by the macro :macro:`GSL_SF_FACT_NMAX`
Packit 67cb25
   and is 170.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW
Packit 67cb25
Packit 67cb25
.. index:: double factorial
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_doublefact (unsigned int n)
Packit 67cb25
              int gsl_sf_doublefact_e (unsigned int n, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the double factorial :math:`n!! = n(n-2)(n-4) \dots`. 
Packit 67cb25
   The maximum value of :math:`n` such that :math:`n!!` is not
Packit 67cb25
   considered an overflow is given by the macro :macro:`GSL_SF_DOUBLEFACT_NMAX`
Packit 67cb25
   and is 297.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW
Packit 67cb25
Packit 67cb25
.. index:: logarithm of factorial
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lnfact (unsigned int n)
Packit 67cb25
              int gsl_sf_lnfact_e (unsigned int n, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of the factorial of :data:`n`,
Packit 67cb25
   :math:`\log(n!)`.  The algorithm is faster than computing
Packit 67cb25
   :math:`\ln(\Gamma(n+1))` via :func:`gsl_sf_lngamma` for :math:`n < 170`,
Packit 67cb25
   but defers for larger :data:`n`.
Packit 67cb25
.. exceptions: none
Packit 67cb25
Packit 67cb25
.. index:: logarithm of double factorial
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lndoublefact (unsigned int n)
Packit 67cb25
              int gsl_sf_lndoublefact_e (unsigned int n, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of the double factorial of :data:`n`,
Packit 67cb25
   :math:`\log(n!!)`.
Packit 67cb25
.. exceptions: none
Packit 67cb25
Packit 67cb25
.. index:: combinatorial factor C(m,n)
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_choose (unsigned int n, unsigned int m)
Packit 67cb25
              int gsl_sf_choose_e (unsigned int n, unsigned int m, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the combinatorial factor :code:`n choose m`
Packit 67cb25
   :math:`= n!/(m!(n-m)!)`
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW
Packit 67cb25
Packit 67cb25
.. index:: logarithm of combinatorial factor C(m,n)
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lnchoose (unsigned int n, unsigned int m)
Packit 67cb25
              int gsl_sf_lnchoose_e (unsigned int n, unsigned int m, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of :code:`n choose m`.  This is
Packit 67cb25
   equivalent to the sum :math:`\log(n!) - \log(m!) - \log((n-m)!)`.
Packit 67cb25
.. exceptions: GSL_EDOM 
Packit 67cb25
Packit 67cb25
.. index::
Packit 67cb25
   single: Taylor coefficients, computation of
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_taylorcoeff (int n, double x)
Packit 67cb25
              int gsl_sf_taylorcoeff_e (int n, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the Taylor coefficient :math:`x^n / n!` for 
Packit 67cb25
   :math:`x \ge 0`, :math:`n \ge 0`
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
Packit 67cb25
Packit 67cb25
.. _pochhammer-symbol:
Packit 67cb25
Packit 67cb25
Pochhammer Symbol
Packit 67cb25
-----------------
Packit 67cb25
Packit 67cb25
.. index::
Packit 67cb25
   single: Pochhammer symbol
Packit 67cb25
   single:  Apell symbol, see Pochhammer symbol
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_poch (double a, double x)
Packit 67cb25
              int gsl_sf_poch_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the Pochhammer symbol :math:`(a)_x = \Gamma(a + x)/\Gamma(a)`.
Packit 67cb25
   The Pochhammer symbol is also known as the Apell symbol and
Packit 67cb25
   sometimes written as :math:`(a,x)`.  When :math:`a` and :math:`a + x` 
Packit 67cb25
   are negative integers or zero, the limiting value of the ratio is returned. 
Packit 67cb25
.. exceptions:  GSL_EDOM, GSL_EOVRFLW
Packit 67cb25
Packit 67cb25
.. index:: logarithm of Pochhammer symbol
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lnpoch (double a, double x)
Packit 67cb25
              int gsl_sf_lnpoch_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of the Pochhammer symbol,
Packit 67cb25
   :math:`\log((a)_x) = \log(\Gamma(a + x)/\Gamma(a))`.
Packit 67cb25
.. exceptions:  GSL_EDOM
Packit 67cb25
Packit 67cb25
.. function:: int gsl_sf_lnpoch_sgn_e (double a, double x, gsl_sf_result * result, double * sgn)
Packit 67cb25
Packit 67cb25
   These routines compute the sign of the Pochhammer symbol and the
Packit 67cb25
   logarithm of its magnitude.  The computed parameters are :math:`result = \log(|(a)_x|)`
Packit 67cb25
   with a corresponding error term,  and :math:`sgn = \sgn((a)_x)` where :math:`(a)_x = \Gamma(a + x)/\Gamma(a)`.
Packit 67cb25
.. exceptions:  GSL_EDOM
Packit 67cb25
Packit 67cb25
.. index:: relative Pochhammer symbol
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_pochrel (double a, double x)
Packit 67cb25
              int gsl_sf_pochrel_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the relative Pochhammer symbol :math:`((a)_x - 1)/x`
Packit 67cb25
   where :math:`(a)_x = \Gamma(a + x)/\Gamma(a)`.
Packit 67cb25
.. exceptions:  GSL_EDOM
Packit 67cb25
Packit 67cb25
Incomplete Gamma Functions
Packit 67cb25
--------------------------
Packit 67cb25
Packit 67cb25
.. index::
Packit 67cb25
   single: non-normalized incomplete Gamma function
Packit 67cb25
   single: unnormalized incomplete Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gamma_inc (double a, double x)
Packit 67cb25
              int gsl_sf_gamma_inc_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These functions compute the unnormalized incomplete Gamma Function
Packit 67cb25
   :math:`\Gamma(a,x) = \int_x^\infty dt t^{(a-1)} \exp(-t)`
Packit 67cb25
   for :math:`a` real and :math:`x \ge 0`.
Packit 67cb25
.. exceptions: GSL_EDOM
Packit 67cb25
Packit 67cb25
.. index:: incomplete Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gamma_inc_Q (double a, double x)
Packit 67cb25
              int gsl_sf_gamma_inc_Q_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the normalized incomplete Gamma Function
Packit 67cb25
   :math:`Q(a,x) = 1/\Gamma(a) \int_x^\infty dt t^{(a-1)} \exp(-t)`
Packit 67cb25
   for :math:`a > 0`, :math:`x \ge 0`.
Packit 67cb25
.. exceptions: GSL_EDOM
Packit 67cb25
Packit 67cb25
.. index:: complementary incomplete Gamma function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_gamma_inc_P (double a, double x)
Packit 67cb25
              int gsl_sf_gamma_inc_P_e (double a, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the complementary normalized incomplete Gamma Function
Packit 67cb25
   :math:`P(a,x) = 1 - Q(a,x) = 1/\Gamma(a) \int_0^x dt t^{(a-1)} \exp(-t)`
Packit 67cb25
   for :math:`a > 0`, :math:`x \ge 0`.
Packit 67cb25
Packit 67cb25
   Note that Abramowitz & Stegun call :math:`P(a,x)` the incomplete gamma
Packit 67cb25
   function (section 6.5).
Packit 67cb25
.. exceptions: GSL_EDOM
Packit 67cb25
Packit 67cb25
Beta Functions
Packit 67cb25
--------------
Packit 67cb25
Packit 67cb25
.. index:: Beta function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_beta (double a, double b)
Packit 67cb25
              int gsl_sf_beta_e (double a, double b, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the Beta Function, :math:`B(a,b) = \Gamma(a)\Gamma(b)/\Gamma(a+b)`
Packit 67cb25
   subject to :math:`a` and :math:`b` not being negative integers.
Packit 67cb25
.. exceptions: GSL_EDOM, GSL_EOVRFLW, GSL_EUNDRFLW
Packit 67cb25
Packit 67cb25
.. index:: logarithm of Beta function
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_lnbeta (double a, double b)
Packit 67cb25
              int gsl_sf_lnbeta_e (double a, double b, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the logarithm of the Beta Function, :math:`\log(B(a,b))`
Packit 67cb25
   subject to :math:`a` and :math:`b` not being negative integers.
Packit 67cb25
.. exceptions: GSL_EDOM
Packit 67cb25
Packit 67cb25
Incomplete Beta Function
Packit 67cb25
------------------------
Packit 67cb25
Packit 67cb25
.. index::
Packit 67cb25
   single: incomplete Beta function, normalized
Packit 67cb25
   single: normalized incomplete Beta function
Packit 67cb25
   single: Beta function, incomplete normalized 
Packit 67cb25
Packit 67cb25
.. function:: double gsl_sf_beta_inc (double a, double b, double x)
Packit 67cb25
              int gsl_sf_beta_inc_e (double a, double b, double x, gsl_sf_result * result)
Packit 67cb25
Packit 67cb25
   These routines compute the normalized incomplete Beta function
Packit 67cb25
   :math:`I_x(a,b) = B_x(a,b) / B(a,b)` where
Packit 67cb25
   
Packit 67cb25
   .. math:: B_x(a,b) = \int_0^x t^{a-1} (1-t)^{b-1} dt
Packit 67cb25
Packit 67cb25
   for :math:`0 \le x \le 1`.
Packit 67cb25
   For :math:`a > 0`, :math:`b > 0` the value is computed using
Packit 67cb25
   a continued fraction expansion.  For all other values it is computed using 
Packit 67cb25
   the relation
Packit 67cb25
   
Packit 67cb25
   .. only:: not texinfo
Packit 67cb25
Packit 67cb25
      .. math:: I_x(a,b,x) = (1/a) x^a {}_2F_1(a,1-b,a+1,x)/B(a,b)
Packit 67cb25
Packit 67cb25
   .. only:: texinfo
Packit 67cb25
Packit 67cb25
      ::
Packit 67cb25
Packit 67cb25
         I_x(a,b,x) = (1/a) x^a 2F1(a,1-b,a+1,x) / B(a,b)