Skip to content

math.special

factorials of any number, bell curve areas and logistic curves, plus step, ramp and pulse shapes

Functions that come up in statistics, probability and signal processing. They include the factorial extended to any number, and the area under the bell curve.

Tags: numbers

  • gamma the gamma function, which extends the factorial: gamma(n + 1) is n!, and it works between whole numbers too
  • lgamma the natural log of the gamma function, which stays finite where gamma itself is too large
  • beta the beta function, gamma(a) × gamma(b) / gamma(a + b)
  • erf the error function: the chance a normal variable lands within x√2 standard deviations of its mean
  • erfc the complementary error function, 1 - erf(x), accurate even where that would round to 0
  • digamma the digamma function, the slope of lgamma: the derivative of ln(gamma(x))
  • zeta the Riemann zeta function, the sum of 1 / n^s over every whole number n from 1
  • erf_inv the inverse of the error function: the x where erf(x) is y, for y between -1 and 1
  • probit the normal quantile: the z where a standard normal variable falls below z with chance p
  • gamma_inc the regularized lower incomplete gamma function: the share of gamma(a) accumulated up to x, from 0 to 1
  • beta_inc the regularized incomplete beta function: the share of beta(a, b) accumulated up to x, for x from 0 to 1
  • sigmoid the logistic curve 1 / (1 + e^-x): an S shape from 0 to 1
  • logit the inverse of sigmoid, ln(p / (1 - p)), for p between 0 and 1
  • heaviside the step function: 0 below zero, 1 above, and 1/2 at zero
  • ramp the ramp function: 0 below zero, and x above
  • rect the rectangle pulse: 1 for x within 1/2 of zero, 1/2 at the edges, 0 beyond
  • tri the triangle pulse: 1 at zero, falling in straight lines to 0 at 1 and -1
gamma(x: num) -> float

the gamma function, which extends the factorial: gamma(n + 1) is n!, and it works between whole numbers too

1
gamma(5)24
2
gamma(0.5) ** 23.14159
Example outputCtrl+Enter to run

See also lgamma, beta, factorial

lgamma(x: num) -> float

the natural log of the gamma function, which stays finite where gamma itself is too large

1
lgamma(1000)5905.22
Example outputCtrl+Enter to run

See also gamma

beta(a: num, b: num) -> float

the beta function, gamma(a) × gamma(b) / gamma(a + b)

1
beta(2, 3)0.0833333
Example outputCtrl+Enter to run

See also gamma

erf(x: num) -> float

the error function: the chance a normal variable lands within x√2 standard deviations of its mean

1
erf(1)0.842701
2
erf(1 / sqrt(2))0.682689
Example outputCtrl+Enter to run

See also erfc

erfc(x: num) -> float

the complementary error function, 1 - erf(x), accurate even where that would round to 0

1
erfc(1)0.157299
2
erfc(5)1.53746e-12
Example outputCtrl+Enter to run

See also erf

digamma(x: num) -> float

the digamma function, the slope of lgamma: the derivative of ln(gamma(x))

1
digamma(1)-0.577216
2
digamma(0.5)-1.96351
Example outputCtrl+Enter to run

See also gamma, lgamma

zeta(s: num) -> float

the Riemann zeta function, the sum of 1 / n^s over every whole number n from 1

1
zeta(2)1.64493
2
zeta(0.5)-1.46035
Example outputCtrl+Enter to run

See also gamma

erf_inv(y: num) -> float

the inverse of the error function: the x where erf(x) is y, for y between -1 and 1

1
erf_inv(0.5)0.476936
2
erf(erf_inv(0.3))0.3
Example outputCtrl+Enter to run

See also erf, probit

probit(p: num) -> float

the normal quantile: the z where a standard normal variable falls below z with chance p

1
probit(0.975)1.95996
2
probit(0.5)0
Example outputCtrl+Enter to run

See also erf_inv

gamma_inc(a: num, x: num) -> float

the regularized lower incomplete gamma function: the share of gamma(a) accumulated up to x, from 0 to 1

1
gamma_inc(1, 2)0.864665
2
gamma_inc(3, 3)0.57681
Example outputCtrl+Enter to run

See also gamma, beta_inc

beta_inc(x: num, a: num, b: num) -> float

the regularized incomplete beta function: the share of beta(a, b) accumulated up to x, for x from 0 to 1

1
beta_inc(0.5, 2, 2)0.5
2
beta_inc(0.25, 1, 3)0.578125
Example outputCtrl+Enter to run

See also beta, gamma_inc

sigmoid(x: num) -> float

the logistic curve 1 / (1 + e^-x): an S shape from 0 to 1

1
sigmoid(0)0.5
2
sigmoid(2)0.880797
Example outputCtrl+Enter to run

See also logit

logit(p: num) -> float

the inverse of sigmoid, ln(p / (1 - p)), for p between 0 and 1

1
logit(0.5)0
2
logit(sigmoid(2))2
Example outputCtrl+Enter to run

See also sigmoid

heaviside(x: num) -> float

the step function: 0 below zero, 1 above, and 1/2 at zero

1
heaviside(-2)0
2
heaviside(3)1
Example outputCtrl+Enter to run

See also ramp, rect

ramp(x: num) -> float

the ramp function: 0 below zero, and x above

1
ramp(-2)0
2
ramp(3)3
Example outputCtrl+Enter to run

See also heaviside

rect(x: num) -> float

the rectangle pulse: 1 for x within 1/2 of zero, 1/2 at the edges, 0 beyond

1
rect(0.2)1
2
rect(1)0
Example outputCtrl+Enter to run

See also tri, heaviside

tri(x: num) -> float

the triangle pulse: 1 at zero, falling in straight lines to 0 at 1 and -1

1
tri(0.25)0.75
2
tri(2)0
Example outputCtrl+Enter to run

See also rect

1
# the factorial of 4.5
2
gamma(5.5)52.3428
3
# the share of a normal distribution within 1.96 standard deviations
4
erf(1.96 / sqrt(2))0.950004
5
# an S-shaped curve from 0 to 1
6
sigmoid(2)0.880797
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.