bernoulli
The nth Bernoulli number
Parameters
Name Type Description
n number | BigNumber | bigint | Fraction
Returns
number | BigNumber | Fraction —
Examples
bernoulli(4) bernoulli(fraction(12))
combinations
Compute the number of combinations of n items taken k at a time
Syntax
combinations(n | k)
Type Signatures
BigNumber, BigNumber
Parameters
Name Type Description
n number | BigNumber Total number of objects in the set
k number | BigNumber Number of objects in the subset
Returns
number | BigNumber — Number of possible combinations.
Examples
combinations(7 5)
combinationsWithRep
Compute the number of combinations of n items taken k at a time with replacements.
Syntax
combinationsWithRep(n | k)
Type Signatures
number, number, BigNumber, BigNumber
Parameters
Name Type Description
n number | BigNumber Total number of objects in the set
k number | BigNumber Number of objects in the subset
Returns
number | BigNumber — Number of possible combinations with replacement.
Examples
combinationsWithRep(7 5)
factorial
Compute the factorial of a value
Parameters
Name Type Description
n number | BigNumber | Array | Matrix An integer number
Returns
number | BigNumber | Array | Matrix — The factorial of `n`
Examples
5! 5 * 4 * 3 * 2 * 1 3!
gamma
Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.
Parameters
Name Type Description
n number | BigNumber | Complex A real or complex number
Returns
number | BigNumber | Complex — The gamma of `n`
Examples
gamma(4) 3! gamma(1/2) sqrt(pi)
kldivergence
Calculate the Kullback-Leibler (KL) divergence between two distributions.
Syntax
kldivergence(x | y)
Type Signatures
Array, Array, Matrix, Array, Array, Matrix, Matrix, Matrix
Parameters
Name Type Description
q Array | Matrix First vector
p Array | Matrix Second vector
Returns
number — Returns distance between q and p
Examples
kldivergence([0.7 0.5 0.4
lgamma
Logarithm of the gamma function for real, positive numbers and complex numbers,
Examples
lgamma(4) lgamma(1/2) lgamma(i) lgamma(complex(1.1 2))
multinomial
Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities. multinomial takes one array of integers as an argument. The following condition must be enforced: every ai > 0.
Type Signatures
Array | Matrix
Parameters
Name Type Description
a number[] | BigNumber[] Integer numbers of objects in the subset
Returns
Number | BigNumber — Multinomial coefficient.
Examples
multinomial([1 2 1
permutations
Compute the number of permutations of n items taken k at a time
Syntax
permutations(n) | permutations(n | k)
Type Signatures
number, number, BigNumber, BigNumber
Parameters
Name Type Description
n number | BigNumber The number of objects in total
k number | BigNumber The number of objects in the subset
Returns
number | BigNumber — The number of permutations
Examples
permutations(5) permutations(5 3)
pickRandom
Pick a random entry from a given array.
Syntax
pickRandom(array) | pickRandom(array | number)
Type Signatures
Array | Matrix, Array | Matrix, Object, Array | Matrix, number, Array | Matrix, Array | Matrix, Array | Matrix, Array | Matrix, number, Array | Matrix, number, Array | Matrix
Parameters
Name Type Description
array Array | Matrix A one dimensional array
number Int An int or float
weights Array | Matrix An array of ints or floats
Returns
number | Array — Returns a single random value from array when number is undefined.
Examples
pickRandom(0:10) pickRandom([1 3 1 6
random
Return a random number.
Syntax
random() | random(max) | random(min
Parameters
Name Type Description
size Array | Matrix If provided, an array or matrix with given
min number Minimum boundary for the random value, included
max number Maximum boundary for the random value, excluded
Returns
number | Array | Matrix — A random number
Examples
random() random(10 20) random([2 3
randomInt
Return a random integer number
Syntax
randomInt(max) | randomInt(min | max)
Parameters
Name Type Description
size Array | Matrix If provided, an array or matrix with given
min number Minimum boundary for the random value, included
max number Maximum boundary for the random value, excluded
Returns
number | Array | Matrix — A random integer value
Examples
randomInt(10 20) randomInt([2 3