Gamma, Beta and Related Functions



Gamma, Beta and Related Functions

Table of Available Gamma, Beta, and Related Functions


Gamma and Log Gamma Functions

For a complex argument z, the gamma function is defined as:

Γ(z) = (1/z) ∏n=1 { (1 + 1 / n)z / (1 + z / n) } due to Euler
or equivalently by 1 / Γ(z) = z exp(γ z) ∏n=1 { (1 + z / n) exp(- z / n) } due to Weierstrass, where γ is the Euler-Mascheroni constant.
Euler showed that for z with positive real part that Γ(z) = ∫0t z-1e-tdt.
From Γ(z) Γ(1-z) = π / sin(π z),   if z has a negative real part, then 1-z has a positive real part and Γ(z) = π / [ sin(π z) Γ(1-z) ].

For complex z the gamma function, Γ(z), is meromorphic in the complex plane with simple poles at the nonpositive real integers and no zeros. The gamma function is evaluated for real x using Lanczos's expression with a Lanczos error estimate of 8 x 10-15. This estimate should be valid except near a pole.
Note that for x > 0, the gamma function is positive while if x < 0, the sign of the gamma function alternates between adjacent poles.

Function List

  • double Gamma_Function( double x )

    Gamma_Function( x ) returns Γ(x) for 0 < x ≤ Gamma_Function_Max_Arg( ) or if -Gamma_Function_Max_Arg( ) ≤ x < 0 and x is not a pole (nonpositive integer). If x > Gamma_Function_Max_Arg( ), then DBL_MAX is returned. If x is a pole, then DBL_MAX is returned otherwise if x < -Gamma_Function_Max_Arg( ) then 0 is returned. Note that the gamma function changes sign on either side of a pole.

  • long double xGamma_Function( long double x )
     
    This is the same as that for the Gamma_Function( ) except that both the argument and the return type are of type long double.

  • double Gamma_Function_Max_Arg( void )
     
    Gamma_Function_Max_Arg( ) returns the maximum argument x for which Γ(x) is representable as the type double.

  • long double xGamma_Function_Max_Arg( void )
     
    xGamma_Function_Max_Arg( ) returns the maximum argument x for which Γ(x) is representable as the type long double.

  • double Ln_Gamma_Function( double x )
     
    Ln_Gamma_Function( x ) returns ln(Γ(x)) for x > 0. The argument x must be positive. Note that for negative x, ln(Γ(x)) may be imaginary.

  • long double xLn_Gamma_Function( long double x )
     
    This is the same as that for the Ln_Gamma_Function() except that a long double is returned.

Source Code

C source code is available for these routines:
  • The file, gamma_function.c, contains the functions Gamma_Function( ), xGamma_Function( ), Gamma_Function_Max_Arg( ), and xGamma_Function_Max_Arg( ).

    Dependencies: No external dependencies.

  • The file, ln_gamma_function.c, contains the functions Ln_Gamma_Function( ) and xLn_Gamma_Function( ).

    Dependencies: In addition to the file ln_gamma_function.c, the functions Ln_Gamma_Function() and xLn_Gamma_Function() require the following file:

C Test Code, Test Results, and Build Shell Script

  • The file, testgammatable.c, contains a test program of Gamma_Function( ) and xGamma_Function() written in C. This test program requires the file gamma_function.c and the file GammaTable.dat.

  • The file, TestGammaTable.txt, contains the results of the test program testgammatable.c.

  • The file, testgammatable.sh, contains the shell script used to compile, link, and execute the test program testgammatable.c.


  • The file, testlngamma.c, contains a test program of Ln_Gamma_Function( ) and xLn_Gamma_Function() written in C. This test program requires the files ln_gamma_function.c and gamma_function.c.

  • The file, TestLnGamma.txt, contains the results of the test program testlnfactorial.c.

  • The file, testlngamma.sh, contains the shell script used to compile, link, and execute the test program testlngamma.c.

Incomplete Gamma Function

The incomplete gamma function is defined as:

γ(x,ν) = ∫0xt ν-1e-tdt.

Function List

  • double Incomplete_Gamma_Function(double x, double nu)

    This function returns γ(x,ν) = ∫0xt ν-1e-tdt.

  • long double xIncomplete_Gamma_Function(long double x, long double nu)

    This is the same as that for the Incomplete_Gamma_Function() except that the arguments are of type long double and the return value is of type long double.

Source Code

C source code is available for these routines:

Entire Incomplete Gamma Function

The entire incomplete gamma function is defined as:

γ*(x,ν) = (1 / Γ(ν) ) ∫0xt ν-1e-tdt.

Function List

  • double Entire_Incomplete_Gamma_Function(double x, double nu)

    This function returns γ*(x,ν) = (1 / Γ(ν) ) ∫0xt ν-1e-tdt.

  • long double xEntire_Incomplete_Gamma_Function(long double x, long double nu)
     
    This is the same as that for the Entire_Incomplete_Gamma_Function() except that the arguments are of type long double and the return value is of type long double.

Source Code

C source code is available for these routines:

Digamma

The digamma function, also called the psi function, is defined as:

&psi(x)=(1/Γ(x)) dΓ(x)/dx.

The digamma function has positive slope throughout its domain of definition with infinite singularities at the nonpositive integers.

Function List

  • double DiGamma_Function( double x )
     
    This function returns &psi(x) if x is not a nonpositive integer and DBL_MAX if x is a nonpositive integer.

  • long double xDiGamma_Function( long double x )
     
    This is the same as that for the DiGamma_Function() except that the argument is of type long double and the return value is of type long double.

Source Code

C source code is available for these routines:
  • The file, digamma_function.c, contains the functions DiGamma_Function( ) and xDiGamma_Function( ).

    Dependencies: No external dependencies.


Beta and Log Beta Functions

The beta function B(a,b) is defined as:

B(a,b) = ∫01t a-1(1-t) b-1dt = Γ(a) Γ(b) / Γ(a + b), where a > 0 and b > 0.

Function List

  • double Beta_Function( double a, double b)
     
    This function returns B(a,b) for positive a and b. If B(a,b) > DBL_MAX, then DBL_MAX is returned.

  • long double xBeta_Function( long double a, long double b)
     
    This is the same as that for the Beta_Function() except that the arguments are of type long double and a long double is returned.

  • double Ln_Beta_Function( double a, double b)

    This function returns ln(B(a,b)) for positive a and b.

  • long double xLn_Beta_Function( long double a, long double b)
     
    This is the same as that for the Ln_Beta_Function() except that the arguments are of type long double and a long double is returned.

Source Code

C source code is available for these routines:
  • The file, beta_function.c, contains the functions Beta_Function( ) and xBeta_Function( ).

    Dependencies: In addition to the file beta_function.c, the functions Beta_Function() and xBeta_Function() require the following files:


  • The file, ln_beta_function.c, contains the functions Ln_Beta_Function( ) and xLn_Beta_Function( ).

    Dependencies: In addition to the file ln_beta_function.c, the functions Ln_Beta_Function() and xLn_Beta_Function() require the following files:


Incomplete Beta Function

This function returns Ix(a,b) = ∫0xt a-1(1-t) b-1dt, where a > 0, b > 0. and 0 ≤ x ≤ 1.

Function List

  • double Incomplete_Beta_Function( double x, double a, double b )
     
    This function returns Ix(a,b). If Ix(a,b) > DBL_MAX, then DBL_MAX is returned.

  • long double xIncomplete_Beta_Function( long double x, long double a, long double b )
     
    This is the same as that for the Incomplete_Beta_Function() except that the arguments are of type long double and a long double is returned.

Source Code

C source code is available for these routines: