Combinatorics

scalation.mathstat.Combinatorics
object Combinatorics

The Combinatorics object provides several common combinatorics functions, such as factorial permutations, combinations, gamma and beta functions.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def betaF(a: Double, b: Double): Double

Compute the beta function 'B(a, b)' for the following two cases: (1) when 'a' or 'b' are integers and (2) when 'a' or 'b' are integers + 1/2.

Compute the beta function 'B(a, b)' for the following two cases: (1) when 'a' or 'b' are integers and (2) when 'a' or 'b' are integers + 1/2.

Value parameters

a

the first parameter, a real number satisfying (1) or (2)

b

the second parameter, a real number satisfying (1) or (2)

Attributes

See also
def choose(n: Int, k: Int): Long

Compute binomial coefficients: 'n' choose 'k', combinations of 'n' things, 'k' at a time, using Pascal's Triangle.

Compute binomial coefficients: 'n' choose 'k', combinations of 'n' things, 'k' at a time, using Pascal's Triangle.

Value parameters

k

the of items to choose (requires k <= n)

n

the total number of items

Attributes

See also
def choose(n: Int, k: Int, l: Int): Long

Compute trinomial coefficients: 'n' choose '(k, l'), combinations of 'n' things, '(k, l)' at a time, using Pascal's Tetrahedron. Ex: Given 'n' balls, counts ways in which 'k' are chosen for group 1 and 'l' are chosen for group 2.

Compute trinomial coefficients: 'n' choose '(k, l'), combinations of 'n' things, '(k, l)' at a time, using Pascal's Tetrahedron. Ex: Given 'n' balls, counts ways in which 'k' are chosen for group 1 and 'l' are chosen for group 2.

Value parameters

k

the of items to choose

l

the of items to choose (requires 0 <= k + l <= n)

n

the total number of items

Attributes

See also
def chose(n: Int, k: Int): Long

Compute 'n' choose 'k' (combinations of 'n' things, 'k' at a time). A more efficient implementation is given below.

Compute 'n' choose 'k' (combinations of 'n' things, 'k' at a time). A more efficient implementation is given below.

Value parameters

k

the of items to choose (requires k <= n)

n

the total number of items

Attributes

def fac(k: Int): Double

Compute 'k' factorial 'k!' using three techniques (requires 'k <= 170').

Compute 'k' factorial 'k!' using three techniques (requires 'k <= 170').

Value parameters

k

the nonnegative integer-valued argument to the factorial function

Attributes

def gammaF(a: Double): Double

Compute the gamma function 'gamma (a)' using the Lanczos Approximation.

Compute the gamma function 'gamma (a)' using the Lanczos Approximation.

Value parameters

a

the parameter, a real number

Attributes

See also
def hyp2f1(a: Double, b: Double, c: Double, z: Double): Double

Compute the Gauss Hypergeometric function '2F1(a, b, c; z)' using a power series expansion.

Compute the Gauss Hypergeometric function '2F1(a, b, c; z)' using a power series expansion.

Value parameters

a

the first parameter, a real/complex number

b

the second parameter, a real/complex number

c

the third parameter, a real/complex number, may not be a negative integer

z

the variable, a real/complex number s.t. |z| < 1

Attributes

See also

en.wikipedia.org/wiki/Hypergeometric_function For faster or more robust algorithms,

people.maths.ox.ac.uk/porterm/research/pearson_final.pdf

def iBetaF(z: Double, a: Double, b: Double): Double

Compute the incomplete beta function 'B(z; a, b)', a generalization of the beta function 'z = 1'.

Compute the incomplete beta function 'B(z; a, b)', a generalization of the beta function 'z = 1'.

Value parameters

a

the first parameter, a real/complex number > 0

b

the second parameter, a real/complex number > 0

z

the variable, a real/complex number s.t. 0 <= |z| <= 1

Attributes

See also
def logfac(k: Int): Double

Compute the natural log factorial 'ln (k!)' so 'k! = exp (logfac (k))'. The formula is a log transformation of Ramanujan's Factorial Approximation.

Compute the natural log factorial 'ln (k!)' so 'k! = exp (logfac (k))'. The formula is a log transformation of Ramanujan's Factorial Approximation.

Value parameters

k

the value to take the log factorial of

Attributes

def mfac(k: Int): Long

For small 'k', compute 'k' factorial by iterative multiplication.
k! = k * (k-1) * ... * 2 * 1

For small 'k', compute 'k' factorial by iterative multiplication.
k! = k * (k-1) * ... * 2 * 1

Value parameters

k

the nonnegative integer-valued argument to the factorial function

Attributes

def mortici(k: Int): Double

Compute 'k!' using Mortici's Factorial Approximation (more accurate than Stirling's 2nd Order Factorial Approximation).

Compute 'k!' using Mortici's Factorial Approximation (more accurate than Stirling's 2nd Order Factorial Approximation).

Value parameters

k

the nonnegative integer-valued argument to the factorial function

Attributes

See also
def perm(n: Int, k: Int): Long

Compute permutations of 'k' items selected from 'n' total items.

Compute permutations of 'k' items selected from 'n' total items.

Value parameters

k

the of items selected

n

the total number of items

Attributes

def rBetaC(z: Double, a: Double, b: Double): Double

Compute the complement of the regularized (incomplete) beta function '1.0 - I(z; a, b) = I(1.0 - z; b, a)'.

Compute the complement of the regularized (incomplete) beta function '1.0 - I(z; a, b) = I(1.0 - z; b, a)'.

Value parameters

a

the first parameter, a real/complex number > 0

b

the second parameter, a real/complex number > 0

z

the variable, a real/complex number s.t. 0 <= |z| <= 1

Attributes

def rBetaF(z: Double, a: Double, b: Double): Double

Compute the regularized (incomplete) beta function 'I(z; a, b)'.

Compute the regularized (incomplete) beta function 'I(z; a, b)'.

Value parameters

a

the first parameter, a real/complex number > 0

b

the second parameter, a real/complex number > 0

z

the variable, a real/complex number s.t. 0 <= |z| <= 1

Attributes

See also
def ramanujan(k: Int): Double

Compute 'k!' using Ramanujan's Factorial Approximation (more accurate than Mortici's Factorial Approximation).

Compute 'k!' using Ramanujan's Factorial Approximation (more accurate than Mortici's Factorial Approximation).

Value parameters

k

the nonnegative integer-valued argument to the factorial function

Attributes

See also
def rfac(k: Int, x: Double): Double

Compute the 'k'th degree rising factorial of 'x'. When 'x = 1', this is the regular factorial function 'k!'. Also known as Pochhammer's symbol. Caveat: only works when 'k' is a nonnegative integer

Compute the 'k'th degree rising factorial of 'x'. When 'x = 1', this is the regular factorial function 'k!'. Also known as Pochhammer's symbol. Caveat: only works when 'k' is a nonnegative integer

Value parameters

k

the number of factors in the product

x

the base number to start the product

Attributes

def stirling(k: Int): Double

Compute 'k!' using Stirling's 2-nd Order Factorial Approximation.

Compute 'k!' using Stirling's 2-nd Order Factorial Approximation.

Value parameters

k

the nonnegative integer-valued argument to the factorial function

Attributes

See also

Concrete fields

val lfac: Array[Long]

Table of all factorial numbers that can be represented as a long (64-bit) integer

Table of all factorial numbers that can be represented as a long (64-bit) integer

Attributes

val pascalTet: Array[Array[Array[Int]]]

Initial part of Pascal's Tetrahedron, precomputed to speed calculations (Trinomial Coefficients)

Initial part of Pascal's Tetrahedron, precomputed to speed calculations (Trinomial Coefficients)

Attributes

See also
val pascalTri: Array[Array[Int]]

Initial part of Pascal's Triangle, precomputed to speed calculations (Binomial Coefficients)

Initial part of Pascal's Triangle, precomputed to speed calculations (Binomial Coefficients)

Attributes