PHP Class MathPHP\Probability\Combinatorics

Show file Open project: markrogoyski/math-php Class Usage Examples

Public Methods

Method Description
catalanNumber ( integer $n ) : integer Catalan number
centralBinomialCoefficient ( integer $n ) : integer Central Binomial Coefficient
combinations ( integer $n, integer $k, boolean $repetition = false ) : integer Combinations - Binomial Coefficient Number of ways of picking k unordered outcomes from n possibilities n choose k: number of possible combinations of n objects taken k at a time.
doubleFactorial ( integer $n ) : integer Double facatorial (iterative) Also known as semifactorial
factorial ( integer $n ) : integer Factorial (iterative) Represents the number of ways to arrange n things (permutations) n! = n(n - 1)(n - 2) ・・・ (n - (n - 1))
fallingFactorial ( number $x, integer $n ) : number Falling Factorial Also known as descending factorial, falling sequential product, lower factorial.
lahNumber ( integer $n, integer $k ) : number Lah number Coefficients expressing rising factorials in terms of falling factorials.
multinomial ( array $groups ) : integer Multinomial coefficient (Multinomial Theorem) Finds the number of divisions of n items into r distinct nonoverlapping subgroups of sizes k₁, k₂, etc.
permutations ( integer $n, integer $k = null ) : integer Permutations (ordered arrangements)
risingFactorial ( number $x, integer $n ) : number Rising Factorial Also known as Pochhammer function, Pochhammer polynomial, ascending factorial, rising sequential product, upper factorial.
subfactorial ( integer $n ) : integer Subfactorial - Derangement number (iterative) The number of permutations of n objects in which no object appears in its natural place.

Method Details

catalanNumber() public static method

1 (2n) Cn = ----- ( ) for n ≥ 0 n + 1 (n ) https://en.wikipedia.org/wiki/Catalan_number
public static catalanNumber ( integer $n ) : integer
$n integer
return integer number

centralBinomialCoefficient() public static method

(2n) (2n)! ( ) = ----- for n ≥ 0 (n ) (n!)² https://en.wikipedia.org/wiki/Central_binomial_coefficient
public static centralBinomialCoefficient ( integer $n ) : integer
$n integer
return integer number

combinations() public static method

Without repetition: (n) n! nCk = ( ) = ---------- (k) (n - k)!k! With repetition: (n) (n + k - 1)! nC'k = ( ) = ------------ (k) (n - 1)!k! http://mathworld.wolfram.com/BinomialCoefficient.html
public static combinations ( integer $n, integer $k, boolean $repetition = false ) : integer
$n integer
$k integer
$repetition boolean Whether to do n choose k with or without repetitions
return integer number of possible combinations of n objects taken k at a time

doubleFactorial() public static method

The product of all the integers from 1 up to some non-negative integer n that have the same parity as n. Denoted by n!! n‼︎ = n(n - 2)(n - 4) ・・・ For even n: n/2 n‼︎ = ∏ (2k) = n(n - 2) ・・・ 2 k=1 For odd n: (n+1)/2 n‼︎ = ∏ (2k - 1) = n(n - 2) ・・・ 1 k=1 0‼︎ = 1
public static doubleFactorial ( integer $n ) : integer
$n integer
return integer

factorial() public static method

Factorial (iterative) Represents the number of ways to arrange n things (permutations) n! = n(n - 1)(n - 2) ・・・ (n - (n - 1))
public static factorial ( integer $n ) : integer
$n integer
return integer number of permutations of n

fallingFactorial() public static method

https://en.wikipedia.org/wiki/Falling_and_rising_factorials x₍ᵢ₎ = x * (x - 1) * (x - 2) ... (x - i + 1)
public static fallingFactorial ( number $x, integer $n ) : number
$x number
$n integer
return number

lahNumber() public static method

https://en.wikipedia.org/wiki/Lah_number n - 1 \ n! L(n,k) = | | -- \ k - 1 / k!
public static lahNumber ( integer $n, integer $k ) : number
$n integer
$k integer
return number

multinomial() public static method

n! (n₁ + n₂ + ⋯ + nk)! ---------- = ------------------- k₁!k₂!⋯km! k₁!k₂!⋯km! http://mathworld.wolfram.com/MultinomialCoefficient.html https://en.wikipedia.org/wiki/Multinomial_theorem
public static multinomial ( array $groups ) : integer
$groups array Sizes of each subgroup
return integer Number of divisions of n items into r distinct nonoverlapping subgroups

permutations() public static method

nPn - number of permutations of n things, taken n at a time. P(n) = nPn = (N)n = n(n - 1)(n - 2) ・・・ (n - (n - 1)) = n! nPk: number of permutations of n things, taking only k of them. n! P(n,k) = nPk = -------- (n - k)!
public static permutations ( integer $n, integer $k = null ) : integer
$n integer
$k integer (Optional) for nPk permutations
return integer number of permutations of n

risingFactorial() public static method

https://en.wikipedia.org/wiki/Falling_and_rising_factorials x⁽ⁿ⁾ = x * (x + 1) * (x + 2) ... (x + n - 1)
public static risingFactorial ( number $x, integer $n ) : number
$x number
$n integer
return number

subfactorial() public static method

n (-1)ⁱ !n = n! ∑ ----- ᵢ₌₀ i! https://en.wikipedia.org/wiki/Derangement http://mathworld.wolfram.com/Subfactorial.html
public static subfactorial ( integer $n ) : integer
$n integer
return integer number of permutations of n