# Combinatorial Functions

 Function Library Home Combinatorial Functions

## Table of Available Combinatorial Functions

### Factorial and Log Factorial

The factorial of a nonnegative integer n, n!, is defined as follows:
For n = 0, n! = 0! = 1 and for n ≥ 1, n! is defined in terms of (n-1)! by n! = n(n-1)!.

#### Function List

• double Factorial( int n )

For an integer n where 0 ≤ n ≤ Factorial_Max_Arg(), Factorial( n ) returns n!.  If n < 0, then 0 is returned and if n > Factorial_Max_Arg(), then DBL_MAX is returned.

• long double xFactorial( int n )

For an integer n where 0 ≤ n ≤ Factorial_Max_Arg(), xFactorial( n ) returns n!.  If n < 0, then 0 is returned and if n > Factorial_Max_Arg(), then DBL_MAX is returned.

• int Factorial_Max_Arg( void )

Factorial_Max_Arg( ) returns the maximum integer n for which n! is representable as the type double.

• double Ln_Factorial( int n )

For a non-negative integer n, Ln_Factorial(n) returns ln(n!).  If n is a negative integer, then -DBL_MAX is returned.

• long double xLn_Factorial( int n )

For a non-negative integer n, xLn_Factorial(n) returns ln(n!).  If n is a negative integer, then -LDBL_MAX is returned.

#### Source Code

C source code is available for these routines:
• The file, factorial.c, contains the functions Factorial( ), xFactorial( ), and Factorial_Max_Arg( ).

Dependencies: No external dependencies.

• The file, ln_factorial.c, contains the functions Ln_Factorial( ) and xLn_Factorial( ).

Dependencies: No external dependencies.

#### C Test Code, Test Results, and Build Shell Script

• The file, testfactorial.c, contains a test program of Factorial( ) and xFactorial() written in C. This test program requires the file factorial.c.

• The file, FactorialTest.txt, contains the results of the test program testfactorial.c.

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

• The file, testlnfactorial.c, contains a test program of Ln_Factorial( ) and xLn_Factorial() written in C. This test program requires the file ln_factorial.c.

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

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

### Double Factorial

The double factorial, n!!, of an integer n ≥ -1 is defined as follows:
For n = -1 or 0, n!! = (-1)!! = 0!! = 1 and for n ≥ 1, n!! is defined in terms of (n-2)!! by n!! = n(n-2)!!.

#### Function List

• double Double_Factorial( int n )

For an integer n where -1 ≤ n ≤ Double_Factorial_Max_Arg(), Double_Factorial(n) returns n!!.  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 )

For an integer n where -1 ≤ n ≤ Double_Factorial_Max_Arg(), xDouble_Factorial(n) returns n!!.  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 )

Double_Factorial_Max_Arg( ) returns the maximum integer n for which n!! is representable as the type double.

#### Source Code

C source code is available for these routines:
• The file, double_factorial.c, contains the functions Double_Factorial( ), xDouble_Factorial( ) and Double_Factorial_Max_Arg( ).

Dependencies: No external dependencies.

#### C Test Code, Test Results, and Build Shell Script

• The file, testdoublefactorial.c, contains a test program of Double_Factorial( ) and xDouble_Factorial( ) written in C. This test program requires the file double_factorial.c.

• The file, DoubleFactorialTest.txt, contains the results of the test program testdoublefactorial.c.

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

### Triple Factorial

The triple factorial, n!!!, of an integer n ≥ -2 is recursively defined as follows:
For n = -2, -1 or 0, n!!! = (-2)!!! = (-1)!!! = 0!!! = 1 and for n ≥ 1, n!!! is defined in terms of (n-3)!!! by n!!! = n(n-3)!!!.

#### Function List

• double Triple_Factorial( int n )

For an integer n where -2 ≤ n ≤ Triple_Factorial_Max_Arg(), Triple_Factorial(n) returns n!!!.  If n < -2, then 0 is returned and if n > Triple_Factorial_Max_Arg(), then DBL_MAXis returned.

• long double xTriple_Factorial( int n )

For an integer n where -2 ≤ n ≤ Triple_Factorial_Max_Arg(), xTriple_Factorial(n) returns n!!!.  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 )

Triple_Factorial_Max_Arg( ) returns the maximum integer n for which n!!! is representable as the type double.

#### Source Code

C source code is available for these routines:
• The file, triple_factorial.c, contains the functions Triple_Factorial( ), xTriple_Factorial( ) and Triple_Factorial_Max_Arg( ).

Dependencies: No external dependencies.

#### C Test Code, Test Results, and Build Shell Script

• The file, testtriplefactorial.c, contains a test program of Triple_Factorial( ) and xTriple_Factorial( ) written in C. This test program requires the file triple_factorial.c.

• The file, TripleFactorialTest.txt, contains the results of the test program testtriplefactorial.c.

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

The quadruple factorial, n!!!!, of an integer n ≥ -3 is recursively defined as follows:
For n = -3, -2, -1 or 0, n!!!! = (-3)!!!! = (-2)!!!! = (-1)!!!! = 0!!!! = 1 and for n ≥ 1, n!!!! is defined in terms of (n-4)!!!! by n!!!! = n(n-4)!!!!.

#### Function List

• double Quadruple_Factorial( int n )

For an integer n where -3 ≤ n ≤ Quadruple_Factorial_Max_Arg(), Quadruple_Factorial(n) returns n!!!!.  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 )

For an integer n where -3 ≤ n ≤ Quadruple_Factorial_Max_Arg(), xQuadruple_Factorial(n) returns n!!!!.  If n < -3, then 0 is returned and if n > Quadruple_Factorial_Max_Arg(), then DBL_MAX is returned.

Quadruple_Factorial_Max_Arg( )returns the maximum integer n for which n!!!! is representable as the type double.

#### Source Code

C source code is available for these routines:

Dependencies: No external dependencies.

#### C Test Code, Test Results, and Build Shell Script

• The file, testquadruplefactorial.c, contains a test program of Quadruple_Factorial( ) and xQuadruple_Factorial( ) written in C. This test program requires the file quadruple_factorial.c.

• The file, QuadrupleFactorialTest.txt, contains the results of the test program testquadruplefactorial.c.

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

### Rising Factorial

The rising factorial of a positive integer n with nonnegative length m is defined as follows: (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

• double Rising_Factorial( int n, int m )

For a postive integer n and nonnegative integer m, Rising_Factorial(n,m) returns (n)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 )

For a postive integer n and nonnegative integer m, xRising_Factorial(n,m) returns (n)m. If n ≤ 0, then 0 is returned and if (n+m-1)! / (n-1)! ≥ DBL_MAX, then DBL_MAX is returned.

#### Source Code

C source code is available for these routines:
• The file, rising_factorial.c, contains the functions Rising_Factorial( ) and xRising_Factorial( ).

Dependencies: In addition to the file rising_factorial.c, the functions Rising_Factorial() and xRising_Factorial() require the following files:

#### C Test Code, Test Results, and Build Shell Script

• The file, testrisingfactorial.c, contains a test program of Rising_Factorial( ) and xRising_Factorial( ) written in C. This test program requires the file rising_factorial.c and its dependencies listed above.

• The file, RisingFactorialTest.txt, contains the results of the test program testrisingfactorial.c.

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

### 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

• double Binomial_Coefficient( int n, int m )

For nonnegative integers n and m ≤ n, Binomial_Coefficient( ) 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 )

For nonnegative integers n and m ≤ n, xBinomial_Coefficient( ) 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.

#### Source Code

C source code is available for these routines:
• The file, binomial_coefficient.c, contains the functions Binomial_Coefficient( ) and xBinomial_Coefficient( ).

Dependencies: In addition to the file binomial_coefficient.c, the functions Binomial_Coefficient() and xBinomial_Coefficient() require the following files:

#### C Test Code, Test Results, and Build Shell Script

• The file, testbinomialcoef.c, contains a test program of Binomial_Coefficient( ) and xBinomial_Coefficient( ) written in C. This test program requires the file binomial_coefficient.c and its dependencies listed above.

• The file, BinomialCoefficientTest.txt, contains the results of the test program testbinomialcoef.c.

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

### 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

• 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.

#### Source Code

C source code is available for these routines:
• The file, multinomial_coefficient.c, contains the functions Multinomial_Coefficient( ) and xMultinomial_Coefficient( ).

Dependencies: In addition to the file multinomial_coefficient.c, the functions Multinomial_Coefficient() and xMultinomial_Coefficient() require the following files:

#### C Test Code, Test Results, and Build Shell Script

• The file, testmultinomialcoef.c, contains a test program of Multinomial_Coefficient( ) and xMultinomial_Coefficient( ) written in C. This test program requires the file multinomial_coefficient.c and its dependencies listed above.

• The file, MultinomialCoefficientTest.txt, contains the results of the test program testmultinomialcoef.c.

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