Probability & Combinatorics Functions

CalcTree includes built-in support for common statistical counting functions and probability-related tools via MathJS. These functions help with uncertainty analysis, risk assessment, and combinatorial calculations.

Combinatorics Functions

These functions return counts of arrangements, selections, and partitions.

Function
Description
CalcTree Example

factorial(n)

n! β€” factorial of a number

factorial(5) β†’ 120

combinations(n, k)

Ways to choose k unordered items from n (no repetition)

combinations(5, 2) β†’ 10

combinationsWithRep(n, k)

Choose k unordered items with repetition

combinationsWithRep(3, 2) β†’ 6

permutations(n [, k])

Ordered subsets of length k (default is n!)

permutations(4, 2) β†’ 12

multinomial([a1, a2, …])

Ways to divide a set into subgroups of given sizes

multinomial([2, 1]) β†’ 3

bellNumbers(n)

Count of set partitions

bellNumbers(3) β†’ 5

catalan(n)

Number of valid bracketings, rooted trees, etc.

catalan(3) β†’ 5

composition(n, k)

Ways to write n as a sum of k positive integers

composition(5, 2) β†’ 4

stirlingS2(n, k)

Stirling numbers of the second kind β€” set partitions

stirlingS2(4, 2) β†’ 7

Probability Functions

These functions support basic probability distributions and randomness.

Function
Description
CalcTree Example

gamma(n)

Gamma function (generalization of factorial)

gamma(6) β†’ 120

lgamma(n)

Logarithm of gamma function

lgamma(6) β†’ ~4.787...

kldivergence(x, y)

Kullback-Leibler divergence between two distributions

kldivergence([0.4, 0.6], [0.5, 0.5])

random()

Random number between 0 and 1 (uniform)

random() β†’ varies

random(min, max)

Random number in given range

random(10, 20) β†’ varies

randomInt(min, max)

Random integer in range

randomInt(1, 6) β†’ like a dice roll

pickRandom(arr)

Randomly select one or more values from a list

pickRandom([1, 2, 3]) β†’ 2

Notes for CalcTree

  • You can use random() in param formulas, but values will refresh on each evaluation.

  • Combinatoric functions return exact values, useful for reliability and arrangement modeling.

  • Use gamma(n + 1) as an alternative to factorial(n) for non-integers.

πŸ“˜ Looking for more functions? CalcTree’s expression engine is powered by MathJS. For a full list of available functions, visit the MathJS Function Reference. Most functions listed there are supported in CalcTree unless otherwise noted.

Last updated