Skip to content

Normal distribution

Nautilus.Distributions provides the normal PDF, CDF, inverse CDF, and sampler. The CDF appears in Black-Scholes pricing; the inverse CDF gives normal quantiles for value-at-risk and hypothesis tests.

Signature: (x: f32, mean: f32, std: f32) -> f32

Computes (1 / (std * sqrt(2*pi))) * exp(-0.5 * ((x - mean) / std)^2).

import Nautilus.Distributions (normal_pdf)
p = normal_pdf(cast(0.0, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 0.3989

Signature: (x: f32, mean: f32, std: f32) -> f32

Computes P(X <= x) via the error function: 0.5 * (1 + erf(z / sqrt(2))) where z = (x - mean) / std.

import Nautilus.Distributions (normal_cdf)
p = normal_cdf(cast(1.96, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 0.975

Signature: (q: f32, mean: f32, std: f32) -> f32

Returns x such that normal_cdf(x, mean, std) = q. Uses the Acklam rational approximation via erfinv, with separate branches for central and tail regions.

  • Domain: q in (0, 1)
  • At q = 0: returns -inf
  • At q = 1: returns +inf
  • Outside [0, 1]: returns NaN
import Nautilus.Distributions (normal_inv_cdf)
x = normal_inv_cdf(cast(0.975, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 1.96

Signature: [n](k: key, template: tensor[n, f32], mean: f32, std: f32) -> tensor[n, f32]

Generates n samples from Normal(mean, std) using the Box-Muller transform. The template tensor determines the output shape; its values are ignored. The key is consumed and split for two uniform draws.

import Nautilus.Distributions (normal_sample)
-- template shape determines output length
samples = normal_sample(key_from_seed(42i64), zeros, cast(0.0, f32), cast(1.0, f32))
Inputnormal_pdfnormal_cdfnormal_inv_cdf
x = mean1/(stdsqrt(2pi))0.5mean
x = +inf0.01.0n/a
x = -inf0.00.0n/a
q = 0n/an/a-inf
q = 1n/an/a+inf
q outside [0,1]n/an/aNaN