Combinatorial Functions


Function Library Home
Combinatorial Functions

Factorial and Log Factorial

The factorial, n!, of a nonnegative integer n is recursively defined by:
0! = 1,
n! = n(n-1)!, for n ≥ 1.

Function List

    Functions:
  • double Factorial( int n )
     
    This function returns n! for 0 ≤ n ≤ Factorial_Max_Arg(). If n < 0, then 0 is returned and if n > Factorial_Max_Arg(), then DBL_MAX is returned.

  • long double xFactorial( int n )
     
    This function returns n! for 0 ≤ n ≤ Factorial_Max_Arg(). If n < 0, then 0 is returned and if n > Factorial_Max_Arg(), then DBL_MAX is returned.

  • int Factorial_Max_Arg( void )
     
    This function returns the maximum integer n for which n! is representable as the type double.

  • double Ln_Factorial( int n )
     
    This function returns ln(n!) for n ≥ 0. If n < 0, then -DBL_MAX is returned.

  • long double xLn_Factorial( int n )
     
    This function returns ln(n!) for n ≥ 0. If n < 0, then -LDBL_MAX is returned.

Double Factorial

The double factorial, n!!, of an integer n ≥ -1 is recursively defined by:
(-1)!! = 0!! = 1,
n!! = n(n-2)!!, for n ≥ 1.

Function List

    Functions:
  • double Double_Factorial( int n )
     
    This function returns n!! for -1 ≤ n ≤ Double_Factorial_Max_Arg(). If n < -1, then 0 is returned and if n > Double_Factorial_Max_Arg(), then DBL_MAX is returned.

  • long double xDouble_Factorial( int n )
     
    This function returns n!! for -1 ≤ n ≤ Double_Factorial_Max_Arg(). If n < -1, then 0 is returned and if n > Double_Factorial_Max_Arg(), then DBL_MAX is returned.

  • int Double_Factorial_Max_Arg( void )
     
    This function returns the maximum integer n for which n!! is representable as the type double.

Triple Factorial

The triple factorial, n!!!, of an integer n ≥ -2 is recursively defined by:
(-2)!!! = (-1)!!! = 0!!! = 1,
n!!! = n(n-3)!!!, for n ≥ 1.

Function List

    Functions:
  • double Triple_Factorial( int n )
     
    This function returns n!!! for -2 ≤ n ≤ Triple_Factorial_Max_Arg(). If n < -2, then 0 is returned and if n > Triple_Factorial_Max_Arg(), then DBL_MAX is returned.

  • long double xTriple_Factorial( int n )
     
    This function returns n!!! for -2 ≤ n ≤ Triple_Factorial_Max_Arg(). If n < -2, then 0 is returned and if n > Triple_Factorial_Max_Arg(), then DBL_MAX is returned.

  • int Triple_Factorial_Max_Arg( void )
     
    This function returns the maximum integer n for which n!!! is representable as the type double.

Quadruple Factorial

The quadruple factorial, n!!!!, of an integer n ≥ -3 is recursively defined by:
(-3)!!!! = (-2)!!!! = (-1)!!!! = 0!!!! = 1,
n!!!! = n(n-4)!!!! for n ≥ 1.

Function List

    Functions:
  • double Quadruple_Factorial( int n )
     
    This function returns n!!!! for -3 ≤ n ≤ Quadruple_Factorial_Max_Arg(). If n < -3, then 0 is returned and if n > Quadruple_Factorial_Max_Arg(), then DBL_MAX is returned.

  • long double xQuadruple_Factorial( int n )
     
    This function returns n!!!! for -3 ≤ n ≤ Quadruple_Factorial_Max_Arg(). If n < -3, then 0 is returned and if n > Quadruple_Factorial_Max_Arg(), then DBL_MAX is returned.

  • int Quadruple_Factorial_Max_Arg( void )
     
    This function returns the maximum integer n for which n!!!! is representable as the type double.

Rising Factorial

The rising factorial of a positive integer n with nonnegative length m is defined as: (n)m = n(n+1)···(n+m-1) = (n+m-1)! / (n-1)!, where, by convention, (n)0 = 1. The rising factorial is Pochhammer's function, (x)m, where x is restricted to the positive integers.

Function List

    Functions:
  • double Rising_Factorial( int n, int m )
     
    This function returns (n)m for nonnegative integers n and positive integers m. If n ≤ 0, then 0 is returned and if (n+m-1)! / (n-1)! > DBL_MAX, then DBL_MAX is returned.

  • long double xRising_Factorial( int n, int m )
     
    This function returns (n)m for nonnegative integers n and positive integers m. If n ≤ 0, then 0 is returned and if (n+m-1)! / (n-1)! > DBL_MAX, then DBL_MAX is returned.

Binomial Coefficient

Expanding the expression (x+y)n where n is a positive integer in terms of powers of x and y, the coefficient of xmyn-m is Cnm = n! / [m! (n-m)!].

Function List

    Functions:
  • double Binomial_Coefficient( int n, int m )
     
    This function returns the combination of n things taken m at a time. If n ≤ 0, m < 0 or n < m then 0 is returned and if n! / [m! (n-m)!] > DBL_MAX, then DBL_MAX is returned.

  • long double xBinomial_Coefficient( int n, int m )
     
    This function returns the combination of n things taken m at a time. If n ≤ 0, m < 0 or n < m then 0 is returned and if n! / [m! (n-m)!] > DBL_MAX, then DBL_MAX is returned.

Multinomial Coefficient

Expanding the expression (x0 + ··· + xm-1)n, where n is a positive integer, in terms of powers of xi, the coefficient of x0a0 ··· xm-1am-1 is Cna = n! / [a0! ··· am-1!], where a0 + ··· + am-1 = n.

Function List

    Functions:
  • double Multinomial_Coefficient( int n, int a[], int m )
     
    This function returns the combination of n things taken a0 ··· am-2(n-a0 - ··· - am-2) at a time. If n ≤ 0, ai < 0 for some i, or n < a0 + ··· + am-2 then 0 is returned and if Cna > DBL_MAX, then DBL_MAX is returned. Note that only a0 ··· am-2 need be set in the array a, the final term am-1 is calculated in the routine.

  • long double xMultinomial_Coefficient( int n, int a[], int m )
     
    This function returns the combination of n things taken a0 ··· am-2(n-a0 - ··· - am-2) at a time. If n ≤ 0, ai < 0 for some i, or n < a0 + ··· + am-2 then 0 is returned and if Cna > DBL_MAX, then DBL_MAX is returned. Note that only a0 ··· am-2 need be set in the array a, the final term am-1 is calculated in the routine.