Probability & Combinatorics Functions
Last updated
Last updated
CalcTree includes built-in support for common statistical counting functions and probability-related tools via . These functions help with uncertainty analysis, risk assessment, and combinatorial calculations.
These functions return counts of arrangements, selections, and partitions.
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
These functions support basic probability distributions and randomness.
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
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 . For a full list of available functions, visit the . Most functions listed there are supported in CalcTree unless otherwise noted.