math.dist
probability distributions: how likely values are, chances of at most a value, the value for a chance, random draws and t-tests
How probable values are for the common distributions, and how to test whether two sets of measurements really differ.
writing
Section titled “writing”Each distribution has the same set of functions, named after it: one ending in _pdf for how dense the probability is at a value (for counts like the binomial, _pmf is the chance of exactly that count), one ending in _cdf for the chance of a value at most that big, and one ending in _inv that goes the other way, from a chance to the value. Parameters come after the value, and the ones with a usual setting can be left out.
good to know
Section titled “good to know”The _inv functions are quantiles, so the value below which 95% of a normal distribution lies is the inverse at 0.95. The random draws take the same parameters as the distribution, and repeat after seed.
Tags: statistics
normal_pdfthe probability density of a normal distribution at x, how likely values near x arenormal_cdfthe chance that a normal variable is at most xnormal_invthe value that a normal variable falls below with chance p, the reverse of normal_cdft_pdfthe probability density of a Student’s t distribution at x, how likely values near x aret_cdfthe chance that a Student’s t variable is at most xt_invthe value that a Student’s t variable falls below with chance p, the reverse of t_cdfchi2_pdfthe probability density of a chi-squared distribution at x, how likely values near x arechi2_cdfthe chance that a chi-squared variable is at most xchi2_invthe value that a chi-squared variable falls below with chance p, the reverse of chi2_cdff_pdfthe probability density of an F distribution at x, how likely values near x aref_cdfthe chance that an F variable is at most xf_invthe value that an F variable falls below with chance p, the reverse of f_cdfexp_pdfthe probability density of an exponential distribution at x, how likely values near x areexp_cdfthe chance that an exponential variable is at most xexp_invthe value that an exponential variable falls below with chance p, the reverse of exp_cdfgamma_pdfthe probability density of a gamma distribution at x, how likely values near x aregamma_cdfthe chance that a gamma variable is at most xgamma_invthe value that a gamma variable falls below with chance p, the reverse of gamma_cdfbeta_pdfthe probability density of a beta distribution at x, how likely values near x arebeta_cdfthe chance that a beta variable is at most xbeta_invthe value that a beta variable falls below with chance p, the reverse of beta_cdfweibull_pdfthe probability density of a Weibull distribution at x, how likely values near x areweibull_cdfthe chance that a Weibull variable is at most xweibull_invthe value that a Weibull variable falls below with chance p, the reverse of weibull_cdfcauchy_pdfthe probability density of a Cauchy distribution at x, how likely values near x arecauchy_cdfthe chance that a Cauchy variable is at most xcauchy_invthe value that a Cauchy variable falls below with chance p, the reverse of cauchy_cdflogistic_pdfthe probability density of a logistic distribution at x, how likely values near x arelogistic_cdfthe chance that a logistic variable is at most xlogistic_invthe value that a logistic variable falls below with chance p, the reverse of logistic_cdfpareto_pdfthe probability density of a Pareto distribution at x, how likely values near x arepareto_cdfthe chance that a Pareto variable is at most xpareto_invthe value that a Pareto variable falls below with chance p, the reverse of pareto_cdfrayleigh_pdfthe probability density of a Rayleigh distribution at x, how likely values near x arerayleigh_cdfthe chance that a Rayleigh variable is at most xrayleigh_invthe value that a Rayleigh variable falls below with chance p, the reverse of rayleigh_cdfbinom_pmfthe chance of exactly k successes in n tries that each succeed with chance pbinom_cdfthe chance of at most k successes in n tries that each succeed with chance pbinom_invthe fewest successes in n tries with chance p each that are at least as likely as q to be reached, the reverse of binom_cdfpoisson_pmfthe chance of exactly k events when rate of them are expected on averagepoisson_cdfthe chance of at most k events when rate of them are expected on averagepoisson_invthe fewest events that are at least as likely as q to be reached when rate are expected, the reverse of poisson_cdfrand_normala random number from a normal distribution with that mean and sd, or a list of n of themrand_expa random wait from an exponential distribution with that rate, or a list of n of themrand_poissona random event count from a Poisson distribution with that rate, or a list of n of themt_testwhether two groups of measurements really differ, as a map with t, df and the two-sided ppaired_t_testwhether paired measurements, like before and after, really differ, as a map with t, df and the two-sided p
Functions
Section titled “Functions”normal_pdf
Section titled “normal_pdf”normal_pdf(x: num, mean?: num, sd?: num) -> float
the probability density of a normal distribution at x, how likely values near x are
Mean and sd default to 0 and 1, the standard bell curve
1normal_pdf(0)0.398942See also normal_cdf, normal_inv
normal_cdf
Section titled “normal_cdf”normal_cdf(x: num, mean?: num, sd?: num) -> float
the chance that a normal variable is at most x
1normal_cdf(1.96)0.975002See also normal_pdf, normal_inv
normal_inv
Section titled “normal_inv”normal_inv(p: num, mean?: num, sd?: num) -> float
the value that a normal variable falls below with chance p, the reverse of normal_cdf
1normal_inv(0.975)1.95996See also normal_pdf, normal_cdf
t_pdf(x: num, df: num) -> float
the probability density of a Student’s t distribution at x, how likely values near x are
Df is the degrees of freedom
1t_pdf(0, 5)0.379607t_cdf(x: num, df: num) -> float
the chance that a Student’s t variable is at most x
1t_cdf(2.0, 10)0.963306t_inv(p: num, df: num) -> float
the value that a Student’s t variable falls below with chance p, the reverse of t_cdf
1t_inv(0.975, 10)2.22814chi2_pdf
Section titled “chi2_pdf”chi2_pdf(x: num, df: num) -> float
the probability density of a chi-squared distribution at x, how likely values near x are
Df is the degrees of freedom
1chi2_pdf(2, 3)0.207554chi2_cdf
Section titled “chi2_cdf”chi2_cdf(x: num, df: num) -> float
the chance that a chi-squared variable is at most x
1chi2_cdf(3.84, 1)0.949956chi2_inv
Section titled “chi2_inv”chi2_inv(p: num, df: num) -> float
the value that a chi-squared variable falls below with chance p, the reverse of chi2_cdf
1chi2_inv(0.95, 1)3.84146f_pdf(x: num, d1: num, d2: num) -> float
the probability density of an F distribution at x, how likely values near x are
D1 and d2 are the two degrees of freedom
1f_pdf(1, 5, 10)0.49548f_cdf(x: num, d1: num, d2: num) -> float
the chance that an F variable is at most x
1f_cdf(3, 5, 10)0.934442f_inv(p: num, d1: num, d2: num) -> float
the value that an F variable falls below with chance p, the reverse of f_cdf
1f_inv(0.95, 5, 10)3.32583exp_pdf
Section titled “exp_pdf”exp_pdf(x: num, rate: num) -> float
the probability density of an exponential distribution at x, how likely values near x are
Rate is how many events happen per unit of time, so the mean wait is 1 / rate
1exp_pdf(1, 2)0.270671exp_cdf
Section titled “exp_cdf”exp_cdf(x: num, rate: num) -> float
the chance that an exponential variable is at most x
1exp_cdf(1, 2)0.864665exp_inv
Section titled “exp_inv”exp_inv(p: num, rate: num) -> float
the value that an exponential variable falls below with chance p, the reverse of exp_cdf
1exp_inv(0.5, 2)0.346574gamma_pdf
Section titled “gamma_pdf”gamma_pdf(x: num, shape: num, rate?: num) -> float
the probability density of a gamma distribution at x, how likely values near x are
Rate defaults to 1
1gamma_pdf(2, 2)0.270671gamma_cdf
Section titled “gamma_cdf”gamma_cdf(x: num, shape: num, rate?: num) -> float
the chance that a gamma variable is at most x
1gamma_cdf(2, 3, 2)0.761897gamma_inv
Section titled “gamma_inv”gamma_inv(p: num, shape: num, rate?: num) -> float
the value that a gamma variable falls below with chance p, the reverse of gamma_cdf
1gamma_inv(0.5, 3)2.67406beta_pdf
Section titled “beta_pdf”beta_pdf(x: num, a: num, b: num) -> float
the probability density of a beta distribution at x, how likely values near x are
A and b are the two shape numbers, and x runs from 0 to 1
1beta_pdf(0.5, 2, 2)1.5beta_cdf
Section titled “beta_cdf”beta_cdf(x: num, a: num, b: num) -> float
the chance that a beta variable is at most x
1beta_cdf(0.25, 2, 5)0.466064beta_inv
Section titled “beta_inv”beta_inv(p: num, a: num, b: num) -> float
the value that a beta variable falls below with chance p, the reverse of beta_cdf
1beta_inv(0.5, 2, 5)0.26445weibull_pdf
Section titled “weibull_pdf”weibull_pdf(x: num, shape: num, scale?: num) -> float
the probability density of a Weibull distribution at x, how likely values near x are
Scale defaults to 1
1weibull_pdf(1, 1.5)0.551819See also weibull_cdf, weibull_inv
weibull_cdf
Section titled “weibull_cdf”weibull_cdf(x: num, shape: num, scale?: num) -> float
the chance that a Weibull variable is at most x
1weibull_cdf(1, 1.5, 2)0.297811See also weibull_pdf, weibull_inv
weibull_inv
Section titled “weibull_inv”weibull_inv(p: num, shape: num, scale?: num) -> float
the value that a Weibull variable falls below with chance p, the reverse of weibull_cdf
1weibull_inv(0.5, 1.5, 2)1.56644See also weibull_pdf, weibull_cdf
cauchy_pdf
Section titled “cauchy_pdf”cauchy_pdf(x: num, loc?: num, scale?: num) -> float
the probability density of a Cauchy distribution at x, how likely values near x are
Loc and scale default to 0 and 1
1cauchy_pdf(0)0.31831See also cauchy_cdf, cauchy_inv
cauchy_cdf
Section titled “cauchy_cdf”cauchy_cdf(x: num, loc?: num, scale?: num) -> float
the chance that a Cauchy variable is at most x
1cauchy_cdf(1)0.75See also cauchy_pdf, cauchy_inv
cauchy_inv
Section titled “cauchy_inv”cauchy_inv(p: num, loc?: num, scale?: num) -> float
the value that a Cauchy variable falls below with chance p, the reverse of cauchy_cdf
1cauchy_inv(0.75)1See also cauchy_pdf, cauchy_cdf
logistic_pdf
Section titled “logistic_pdf”logistic_pdf(x: num, loc?: num, scale?: num) -> float
the probability density of a logistic distribution at x, how likely values near x are
Loc and scale default to 0 and 1
1logistic_pdf(0)0.25See also logistic_cdf, logistic_inv
logistic_cdf
Section titled “logistic_cdf”logistic_cdf(x: num, loc?: num, scale?: num) -> float
the chance that a logistic variable is at most x
1logistic_cdf(2)0.880797See also logistic_pdf, logistic_inv
logistic_inv
Section titled “logistic_inv”logistic_inv(p: num, loc?: num, scale?: num) -> float
the value that a logistic variable falls below with chance p, the reverse of logistic_cdf
1logistic_inv(0.9)2.19722See also logistic_pdf, logistic_cdf
pareto_pdf
Section titled “pareto_pdf”pareto_pdf(x: num, shape: num, scale?: num) -> float
the probability density of a Pareto distribution at x, how likely values near x are
Scale is the smallest possible value and defaults to 1
1pareto_pdf(2, 3)0.1875See also pareto_cdf, pareto_inv
pareto_cdf
Section titled “pareto_cdf”pareto_cdf(x: num, shape: num, scale?: num) -> float
the chance that a Pareto variable is at most x
1pareto_cdf(2, 3)0.875See also pareto_pdf, pareto_inv
pareto_inv
Section titled “pareto_inv”pareto_inv(p: num, shape: num, scale?: num) -> float
the value that a Pareto variable falls below with chance p, the reverse of pareto_cdf
1pareto_inv(0.5, 3)1.25992See also pareto_pdf, pareto_cdf
rayleigh_pdf
Section titled “rayleigh_pdf”rayleigh_pdf(x: num, scale?: num) -> float
the probability density of a Rayleigh distribution at x, how likely values near x are
Scale defaults to 1
1rayleigh_pdf(1)0.606531See also rayleigh_cdf, rayleigh_inv
rayleigh_cdf
Section titled “rayleigh_cdf”rayleigh_cdf(x: num, scale?: num) -> float
the chance that a Rayleigh variable is at most x
1rayleigh_cdf(1, 2)0.117503See also rayleigh_pdf, rayleigh_inv
rayleigh_inv
Section titled “rayleigh_inv”rayleigh_inv(p: num, scale?: num) -> float
the value that a Rayleigh variable falls below with chance p, the reverse of rayleigh_cdf
1rayleigh_inv(0.5, 2)2.35482See also rayleigh_pdf, rayleigh_cdf
binom_pmf
Section titled “binom_pmf”binom_pmf(k: int, n: int, p: num) -> float
the chance of exactly k successes in n tries that each succeed with chance p
1binom_pmf(5, 10, 0.5)0.246094binom_cdf
Section titled “binom_cdf”binom_cdf(k: int, n: int, p: num) -> float
the chance of at most k successes in n tries that each succeed with chance p
1binom_cdf(3, 10, 0.5)0.171875binom_inv
Section titled “binom_inv”binom_inv(q: num, n: int, p: num) -> int
the fewest successes in n tries with chance p each that are at least as likely as q to be reached, the reverse of binom_cdf
1binom_inv(0.5, 10, 0.5)5poisson_pmf
Section titled “poisson_pmf”poisson_pmf(k: int, rate: num) -> float
the chance of exactly k events when rate of them are expected on average
1poisson_pmf(2, 3)0.224042See also poisson_cdf, poisson_inv
poisson_cdf
Section titled “poisson_cdf”poisson_cdf(k: int, rate: num) -> float
the chance of at most k events when rate of them are expected on average
1poisson_cdf(2, 3)0.42319See also poisson_pmf, poisson_inv
poisson_inv
Section titled “poisson_inv”poisson_inv(q: num, rate: num) -> int
the fewest events that are at least as likely as q to be reached when rate are expected, the reverse of poisson_cdf
1poisson_inv(0.5, 3)3See also poisson_pmf, poisson_cdf
rand_normal
Section titled “rand_normal”rand_normal(mean: num, sd: num, n?: int) -> float|list
a random number from a normal distribution with that mean and sd, or a list of n of them
1rand_normal(100, 15)74.40712rand_normal(0, 1, 3)[1.52739, -0.644269, -1.03496]Tags: random
See also normal_pdf, normal_cdf, normal_inv
rand_exp
Section titled “rand_exp”rand_exp(rate: num, n?: int) -> float|list
a random wait from an exponential distribution with that rate, or a list of n of them
1rand_exp(2)1.739792rand_exp(0.5, 3)[3.98627, 5.12684, 0.638952]Tags: random
See also exp_pdf, exp_cdf, exp_inv
rand_poisson
Section titled “rand_poisson”rand_poisson(rate: num, n?: int) -> float|list
a random event count from a Poisson distribution with that rate, or a list of n of them
1rand_poisson(4)32rand_poisson(2.5, 3)[3, 6, 3]Tags: random
See also poisson_pmf, poisson_cdf, poisson_inv
t_test
Section titled “t_test”t_test(xs: list, ys: list) -> map
whether two groups of measurements really differ, as a map with t, df and the two-sided p
Welch’s test, which doesn’t assume the groups spread equally. A small p, like under 0.05, means a difference this big would be rare by chance alone
1t_test([5.1, 4.9, 5.6, 5.8, 5.0], [6.1, 6.4, 5.9, 6.8, 6.2]){t: -4.27179, df: 7.83306, p: 0.00285238}See also paired_t_test, t_cdf
paired_t_test
Section titled “paired_t_test”paired_t_test(xs: list, ys: list) -> map
whether paired measurements, like before and after, really differ, as a map with t, df and the two-sided p
The lists must be the same length, with item i of each from the same subject
1paired_t_test([200, 190, 210, 205], [195, 185, 207, 198]){t: 6.12372, df: 3, p: 0.00875441}More examples
Section titled “More examples”distributions
Section titled “distributions”1# the share of a bell curve within 1.96 deviations2normal_cdf(1.96) - normal_cdf(-1.96)0.9500043# the 95% cutoff for a t distribution with 10 degrees of freedom4t_inv(0.975, 10)2.228145# heads in 10 fair coin tosses, at most 36binom_cdf(3, 10, 0.5)0.1718757# do these two groups differ?8t_test([5.1, 4.9, 5.6, 5.8, 5.0], [6.1, 6.4, 5.9, 6.8, 6.2]).p0.00285238Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.