|
|
@@ -1,83 +1,87 @@
|
|
|
# Mathematical functions
|
|
|
|
|
|
-Jump to: [Basics](#basics) · [Trigonometry](#trigonometry) · [Random numbers](#random-numbers) · [Numerical methods](#numerical-methods) · [Algebra](#algebra)
|
|
|
+[Basics](#basics) · [Transcendental functions](#transcendental-functions) · [Trigonometry](#trigonometry) · [Statistics](#statistics) · [Random sampling, distributions](#random-sampling,-distributions) · [Number theory](#number-theory) · [Numerical methods](#numerical-methods) · [Geometry](#geometry) · [Algebra](#algebra) · [Trigonometry (extra)](#trigonometry-(extra))
|
|
|
|
|
|
## Basics
|
|
|
|
|
|
Defined in: `core::functions`
|
|
|
|
|
|
### `id` (Identity function)
|
|
|
+Return the input value.
|
|
|
|
|
|
```nbt
|
|
|
fn id<A>(x: A) -> A
|
|
|
```
|
|
|
|
|
|
### `abs` (Absolute value)
|
|
|
+Return the absolute value of the input, \\( |x| \\). This works for quantities, too: `abs(-5 m) = 5 m`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.abs).
|
|
|
|
|
|
```nbt
|
|
|
fn abs<T: Dim>(x: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `round` (Round)
|
|
|
-Round to the nearest integer.
|
|
|
-More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.round).
|
|
|
+### `sqrt` (Square root)
|
|
|
+Return the square root of the input, \\( \sqrt{x} \\): `sqrt(121 m^2) = 11 m`.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Square_root).
|
|
|
|
|
|
```nbt
|
|
|
-fn round<T: Dim>(x: T) -> T
|
|
|
+fn sqrt<D: Dim>(x: D^2) -> D
|
|
|
```
|
|
|
|
|
|
-### `floor` (Floor function)
|
|
|
-More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.floor).
|
|
|
+### `cbrt` (Cube root)
|
|
|
+Return the cube root of the input, \\( \sqrt[3]{x} \\): `cbrt(8 m^3) = 2 m`.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Cube_root).
|
|
|
|
|
|
```nbt
|
|
|
-fn floor<T: Dim>(x: T) -> T
|
|
|
+fn cbrt<D: Dim>(x: D^3) -> D
|
|
|
```
|
|
|
|
|
|
-### `ceil` (Ceil function)
|
|
|
-More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.ceil).
|
|
|
+### `sqr` (Square function)
|
|
|
+Return the square of the input, \\( x^2 \\): `sqr(5 m) = 25 m^2`.
|
|
|
|
|
|
```nbt
|
|
|
-fn ceil<T: Dim>(x: T) -> T
|
|
|
+fn sqr<D: Dim>(x: D) -> D^2
|
|
|
```
|
|
|
|
|
|
-### `mod` (Modulo)
|
|
|
-More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.rem_euclid).
|
|
|
+### `round` (Rounding)
|
|
|
+Round to the nearest integer. If the value is half-way between two integers, round away from 0.
|
|
|
+More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.round).
|
|
|
|
|
|
```nbt
|
|
|
-fn mod<T: Dim>(a: T, b: T) -> T
|
|
|
+fn round<T: Dim>(x: T) -> T
|
|
|
```
|
|
|
|
|
|
-## Trigonometry
|
|
|
-
|
|
|
-Defined in: `math::functions`, `math::trigonometry_extra`
|
|
|
-
|
|
|
-### `is_nan`
|
|
|
+### `floor` (Floor function)
|
|
|
+Returns the largest integer less than or equal to `x`.
|
|
|
+More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.floor).
|
|
|
|
|
|
```nbt
|
|
|
-fn is_nan<T: Dim>(n: T) -> Bool
|
|
|
+fn floor<T: Dim>(x: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `is_infinite`
|
|
|
+### `ceil` (Ceil function)
|
|
|
+Returns the smallest integer greater than or equal to `x`.
|
|
|
+More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.ceil).
|
|
|
|
|
|
```nbt
|
|
|
-fn is_infinite<T: Dim>(n: T) -> Bool
|
|
|
+fn ceil<T: Dim>(x: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `sqrt` (Square root)
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Square_root).
|
|
|
+### `mod` (Modulo)
|
|
|
+Calculates the least nonnegative remainder of `a (mod b)`.
|
|
|
+More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.rem_euclid).
|
|
|
|
|
|
```nbt
|
|
|
-fn sqrt<D: Dim>(x: D^2) -> D
|
|
|
+fn mod<T: Dim>(a: T, b: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `sqr` (Square function)
|
|
|
+## Transcendental functions
|
|
|
|
|
|
-```nbt
|
|
|
-fn sqr<D: Dim>(x: D) -> D^2
|
|
|
-```
|
|
|
+Defined in: `math::transcendental`
|
|
|
|
|
|
### `exp` (Exponential function)
|
|
|
+The exponential function, \\( e^x \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Exponential_function).
|
|
|
|
|
|
```nbt
|
|
|
@@ -85,6 +89,7 @@ fn exp(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
### `ln` (Natural logarithm)
|
|
|
+The natural logarithm with base \\( e \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
|
|
|
```nbt
|
|
|
@@ -92,6 +97,7 @@ fn ln(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
### `log` (Natural logarithm)
|
|
|
+The natural logarithm with base \\( e \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
|
|
|
```nbt
|
|
|
@@ -99,6 +105,7 @@ fn log(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
### `log10` (Common logarithm)
|
|
|
+The common logarithm with base \\( 10 \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Common_logarithm).
|
|
|
|
|
|
```nbt
|
|
|
@@ -106,12 +113,25 @@ fn log10(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
### `log2` (Binary logarithm)
|
|
|
+The binary logarithm with base \\( 2 \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Binary_logarithm).
|
|
|
|
|
|
```nbt
|
|
|
fn log2(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+### `gamma` (Gamma function)
|
|
|
+The gamma function, \\( \Gamma(x) \\).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Gamma_function).
|
|
|
+
|
|
|
+```nbt
|
|
|
+fn gamma(x: Scalar) -> Scalar
|
|
|
+```
|
|
|
+
|
|
|
+## Trigonometry
|
|
|
+
|
|
|
+Defined in: `math::trigonometry`
|
|
|
+
|
|
|
### `sin` (Sine)
|
|
|
More information [here](https://en.wikipedia.org/wiki/Trigonometric_functions).
|
|
|
|
|
|
@@ -203,28 +223,26 @@ More information [here](https://en.wikipedia.org/wiki/Hyperbolic_functions).
|
|
|
fn atanh(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `gamma` (Gamma function)
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Gamma_function).
|
|
|
+## Statistics
|
|
|
|
|
|
-```nbt
|
|
|
-fn gamma(x: Scalar) -> Scalar
|
|
|
-```
|
|
|
+Defined in: `math::statistics`
|
|
|
|
|
|
### `maximum` (Maxmimum)
|
|
|
-Get the largest element of a list.
|
|
|
+Get the largest element of a list: `maximum([30 cm, 2 m]) = 2 m`.
|
|
|
|
|
|
```nbt
|
|
|
fn maximum<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
### `minimum` (Minimum)
|
|
|
-Get the smallest element of a list.
|
|
|
+Get the smallest element of a list: `minimum([30 cm, 2 m]) = 30 cm`.
|
|
|
|
|
|
```nbt
|
|
|
fn minimum<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
### `mean` (Arithmetic mean)
|
|
|
+Calculate the arithmetic mean of a list of quantities: `mean([1 m, 2 m, 300 cm]) = 2 m`.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Arithmetic_mean).
|
|
|
|
|
|
```nbt
|
|
|
@@ -255,268 +273,261 @@ More information [here](https://en.wikipedia.org/wiki/Median).
|
|
|
fn median<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
-### `gcd` (Greatest common divisor)
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
|
|
|
+## Random sampling, distributions
|
|
|
|
|
|
-```nbt
|
|
|
-fn gcd(a: Scalar, b: Scalar) -> Scalar
|
|
|
-```
|
|
|
+Defined in: `core::random`, `math::distributions`
|
|
|
|
|
|
-### `lcm` (Least common multiple)
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Least_common_multiple).
|
|
|
+### `random` (Standard uniform distribution sampling)
|
|
|
+Uniformly samples the interval \\( [0,1) \\).
|
|
|
|
|
|
```nbt
|
|
|
-fn lcm(a: Scalar, b: Scalar) -> Scalar
|
|
|
+fn random() -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `hypot2`
|
|
|
+### `rand_uniform` (Continuous uniform distribution sampling)
|
|
|
+Uniformly samples the interval \\( [a,b) \\) if \\( a \le b \\) or \\( [b,a) \\) if \\( b<a \\) using inversion sampling.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn hypot2<T: Dim>(x: T, y: T) -> T
|
|
|
+fn rand_uniform<T: Dim>(a: T, b: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `hypot3`
|
|
|
+### `rand_int` (Discrete uniform distribution sampling)
|
|
|
+Uniformly samples the integers in the interval \\( [a, b] \\).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Discrete_uniform_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn hypot3<T: Dim>(x: T, y: T, z: T) -> T
|
|
|
+fn rand_int(a: Scalar, b: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `circle_area`
|
|
|
+### `rand_bernoulli` (Bernoulli distribution sampling)
|
|
|
+Samples a Bernoulli random variable, that is, \\( 1 \\) with probability \\( p \\), \\( 0 \\) with probability \\( 1-p \\). The parameter \\( p \\) must be a probability (\\( 0 \le p \le 1 \\)).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Bernoulli_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn circle_area<L: Dim>(radius: L) -> L^2
|
|
|
+fn rand_bernoulli(p: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `circle_circumference`
|
|
|
+### `rand_binom` (Binomial distribution sampling)
|
|
|
+Samples a binomial distribution by doing \\( n \\) Bernoulli trials with probability \\( p \\).
|
|
|
+ The parameter \\( n \\) must be a positive integer, the parameter \\( p \\) must be a probability (\\( 0 \le p \le 1 \\)).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Binomial_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn circle_circumference<L: Dim>(radius: L) -> L
|
|
|
+fn rand_binom(n: Scalar, p: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `sphere_area`
|
|
|
+### `rand_norm` (Normal distribution sampling)
|
|
|
+Samples a normal distribution with mean \\( \mu \\) and standard deviation \\( \sigma \\) using the Box-Muller transform.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Normal_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn sphere_area<L: Dim>(radius: L) -> L^2
|
|
|
+fn rand_norm<T: Dim>(μ: T, σ: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `sphere_volume`
|
|
|
+### `rand_geom` (Geometric distribution sampling)
|
|
|
+Samples a geometric distribution (the distribution of the number of Bernoulli trials with probability \\( p \\) needed to get one success) by inversion sampling. The parameter \\( p \\) must be a probability (\\( 0 \le p \le 1 \\)).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Geometric_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn sphere_volume<L: Dim>(radius: L) -> L^3
|
|
|
+fn rand_geom(p: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `cot`
|
|
|
+### `rand_poisson` (Poisson distribution sampling)
|
|
|
+Sampling a poisson distribution with rate \\( \lambda \\), that is, the distribution of the number of events occurring in a fixed interval if these events occur with mean rate \\( \lambda \\). The rate parameter \\( \lambda \\) must be non-negative.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Poisson_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn cot(x: Scalar) -> Scalar
|
|
|
+fn rand_poisson(λ: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `acot`
|
|
|
+### `rand_expon` (Exponential distribution sampling)
|
|
|
+Sampling an exponential distribution (the distribution of the distance between events in a Poisson process with rate \\( \lambda \\)) using inversion sampling. The rate parameter \\( \lambda \\) must be positive.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Exponential_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn acot(x: Scalar) -> Scalar
|
|
|
+fn rand_expon<T: Dim>(λ: T) -> 1 / T
|
|
|
```
|
|
|
|
|
|
-### `coth`
|
|
|
+### `rand_lognorm` (Log-normal distribution sampling)
|
|
|
+Sampling a log-normal distribution, that is, a distribution whose logarithm is a normal distribution with mean \\( \mu \\) and standard deviation \\( \sigma \\).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Log-normal_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn coth(x: Scalar) -> Scalar
|
|
|
+fn rand_lognorm(μ: Scalar, σ: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `acoth`
|
|
|
+### `rand_pareto` (Pareto distribution sampling)
|
|
|
+Sampling a Pareto distribution with minimum value `min` and shape parameter \\( \alpha \\) using inversion sampling. Both parameters must be positive.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Pareto_distribution).
|
|
|
|
|
|
```nbt
|
|
|
-fn acoth(x: Scalar) -> Scalar
|
|
|
+fn rand_pareto<T: Dim>(α: Scalar, min: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `secant`
|
|
|
+## Number theory
|
|
|
+
|
|
|
+Defined in: `core::number_theory`
|
|
|
+
|
|
|
+## Numerical methods
|
|
|
+
|
|
|
+Defined in: `numerics::diff`, `numerics::solve`
|
|
|
+
|
|
|
+### `diff` (Numerical differentiation)
|
|
|
+Compute the numerical derivative of the function \\( f \\) at point \\( x \\) using the central difference method.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Numerical_differentiation).
|
|
|
|
|
|
```nbt
|
|
|
-fn secant(x: Scalar) -> Scalar
|
|
|
+fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X) -> Y / X
|
|
|
```
|
|
|
|
|
|
-### `arcsecant`
|
|
|
+### `root_bisect` (Bisection method)
|
|
|
+Find the root of the function \\( f \\) in the interval \\( [x_1, x_2] \\) using the bisection method. The function \\( f \\) must be continuous and \\( f(x_1) \cdot f(x_2) < 0 \\).
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Bisection_method).
|
|
|
|
|
|
```nbt
|
|
|
-fn arcsecant(x: Scalar) -> Scalar
|
|
|
+fn root_bisect<A: Dim, B: Dim>(f: Fn[(A) -> B], x1: A, x2: A, x_tol: A, y_tol: B) -> A
|
|
|
```
|
|
|
|
|
|
-### `cosecant`
|
|
|
+### `root_newton` (Newton's method)
|
|
|
+Find the root of the function \\( f(x) \\) and its derivative \\( f'(x) \\) using Newton's method.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Newton%27s_method).
|
|
|
|
|
|
```nbt
|
|
|
-fn cosecant(x: Scalar) -> Scalar
|
|
|
+fn root_newton<A: Dim, B: Dim>(f: Fn[(A) -> B], f_prime: Fn[(A) -> B / A], x0: A, y_tol: B) -> A
|
|
|
```
|
|
|
|
|
|
-### `csc`
|
|
|
+## Geometry
|
|
|
+
|
|
|
+Defined in: `math::geometry`
|
|
|
+
|
|
|
+### `hypot2`
|
|
|
|
|
|
```nbt
|
|
|
-fn csc(x: Scalar) -> Scalar
|
|
|
+fn hypot2<T: Dim>(x: T, y: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `acsc`
|
|
|
+### `hypot3`
|
|
|
|
|
|
```nbt
|
|
|
-fn acsc(x: Scalar) -> Scalar
|
|
|
+fn hypot3<T: Dim>(x: T, y: T, z: T) -> T
|
|
|
```
|
|
|
|
|
|
-### `sech`
|
|
|
+### `circle_area`
|
|
|
|
|
|
```nbt
|
|
|
-fn sech(x: Scalar) -> Scalar
|
|
|
+fn circle_area<L: Dim>(radius: L) -> L^2
|
|
|
```
|
|
|
|
|
|
-### `asech`
|
|
|
+### `circle_circumference`
|
|
|
|
|
|
```nbt
|
|
|
-fn asech(x: Scalar) -> Scalar
|
|
|
+fn circle_circumference<L: Dim>(radius: L) -> L
|
|
|
```
|
|
|
|
|
|
-### `csch`
|
|
|
+### `sphere_area`
|
|
|
|
|
|
```nbt
|
|
|
-fn csch(x: Scalar) -> Scalar
|
|
|
+fn sphere_area<L: Dim>(radius: L) -> L^2
|
|
|
```
|
|
|
|
|
|
-### `acsch`
|
|
|
+### `sphere_volume`
|
|
|
|
|
|
```nbt
|
|
|
-fn acsch(x: Scalar) -> Scalar
|
|
|
+fn sphere_volume<L: Dim>(radius: L) -> L^3
|
|
|
```
|
|
|
|
|
|
-## Random numbers
|
|
|
+## Algebra
|
|
|
|
|
|
-Defined in: `core::random`, `math::statistics`
|
|
|
+Defined in: `extra::algebra`
|
|
|
|
|
|
-### `random` (Standard uniform distribution sampling)
|
|
|
-Uniformly samples the interval [0,1).
|
|
|
+### `quadratic_equation` (Solve quadratic equations)
|
|
|
+Returns the solutions of the equation a x² + b x + c = 0.
|
|
|
+More information [here](https://en.wikipedia.org/wiki/Quadratic_equation).
|
|
|
|
|
|
```nbt
|
|
|
-fn random() -> Scalar
|
|
|
+fn quadratic_equation<A: Dim, B: Dim>(a: A, b: B, c: B^2 / A) -> List<B / A>
|
|
|
```
|
|
|
|
|
|
-### `rand_uniform` (Continuous uniform distribution sampling)
|
|
|
-Uniformly samples the interval [a,b) if a<=b or [b,a) if b<a using inversion sampling.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
|
|
|
+## Trigonometry (extra)
|
|
|
|
|
|
-```nbt
|
|
|
-fn rand_uniform<T: Dim>(a: T, b: T) -> T
|
|
|
-```
|
|
|
+Defined in: `math::trigonometry_extra`
|
|
|
|
|
|
-### `rand_int` (Discrete uniform distribution sampling)
|
|
|
-Uniformly samples the integers in the interval [a, b].
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Discrete_uniform_distribution).
|
|
|
+### `cot`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_int(a: Scalar, b: Scalar) -> Scalar
|
|
|
+fn cot(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_bernoulli` (Bernoulli distribution sampling)
|
|
|
-Samples a Bernoulli random variable, that is, 1 with probability p, 0 with probability 1-p.
|
|
|
- Parameter p must be a probability (0 <= p <= 1).
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Bernoulli_distribution).
|
|
|
+### `acot`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_bernoulli(p: Scalar) -> Scalar
|
|
|
+fn acot(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_binom` (Binomial distribution sampling)
|
|
|
-Samples a binomial distribution by doing n Bernoulli trials with probability p.
|
|
|
- Parameter n must be a positive integer, parameter p must be a probability (0 <= p <= 1).
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Binomial_distribution).
|
|
|
+### `coth`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_binom(n: Scalar, p: Scalar) -> Scalar
|
|
|
+fn coth(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_norm` (Normal distribution sampling)
|
|
|
-Samples a normal distribution with mean μ and standard deviation σ using the Box-Muller transform.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Normal_distribution).
|
|
|
+### `acoth`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_norm<T: Dim>(μ: T, σ: T) -> T
|
|
|
+fn acoth(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_geom` (Geometric distribution sampling)
|
|
|
-Samples a geometric distribution (the distribution of the number of Bernoulli trials with probability p needed to get one success) by inversion sampling.
|
|
|
- Parameter p must be a probability (0 <= p <= 1).
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Geometric_distribution).
|
|
|
+### `secant`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_geom(p: Scalar) -> Scalar
|
|
|
+fn secant(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_poisson` (Poisson distribution sampling)
|
|
|
-Sampling a poisson distribution with rate λ, that is, the distribution of the number of events occurring in a fixed interval if these events occur with mean rate λ.
|
|
|
- The rate parameter λ must not be negative.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Poisson_distribution).
|
|
|
+### `arcsecant`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_poisson(λ: Scalar) -> Scalar
|
|
|
+fn arcsecant(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_expon` (Exponential distribution sampling)
|
|
|
-Sampling an exponential distribution (the distribution of the distance between events in a Poisson process with rate λ) using inversion sampling.
|
|
|
- The rate parameter λ must be positive.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Exponential_distribution).
|
|
|
+### `cosecant`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_expon<T: Dim>(λ: T) -> 1 / T
|
|
|
+fn cosecant(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_lognorm` (Log-normal distribution sampling)
|
|
|
-Sampling a log-normal distribution, that is, a distribution whose log is a normal distribution with mean μ and standard deviation σ.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Log-normal_distribution).
|
|
|
+### `csc`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_lognorm(μ: Scalar, σ: Scalar) -> Scalar
|
|
|
+fn csc(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `rand_pareto` (Pareto distribution sampling)
|
|
|
-Sampling a Pareto distribution with minimum value min and shape parameter α using inversion sampling.
|
|
|
- Both parameters α and min must be positive.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Pareto_distribution).
|
|
|
+### `acsc`
|
|
|
|
|
|
```nbt
|
|
|
-fn rand_pareto<T: Dim>(α: Scalar, min: T) -> T
|
|
|
+fn acsc(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-## Numerical methods
|
|
|
-
|
|
|
-Defined in: `numerics::diff`, `numerics::solve`
|
|
|
-
|
|
|
-### `diff` (Numerical differentiation)
|
|
|
-Compute the numerical derivative of a function at a point using the central difference method.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Numerical_differentiation).
|
|
|
+### `sech`
|
|
|
|
|
|
```nbt
|
|
|
-fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X) -> Y / X
|
|
|
+fn sech(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `root_bisect` (Bisection method)
|
|
|
-Find the root of the function f in the interval [x1, x2] using the bisection method. The function f must be continuous and f(x1) × f(x2) < 0.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Bisection_method).
|
|
|
+### `asech`
|
|
|
|
|
|
```nbt
|
|
|
-fn root_bisect<A: Dim, B: Dim>(f: Fn[(A) -> B], x1: A, x2: A, x_tolerance: A, y_tolerance: B) -> A
|
|
|
+fn asech(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-### `root_newton` (Newton's method)
|
|
|
-Find the root of the function f(x) and its derivative f'(x) using Newton's method.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Newton%27s_method).
|
|
|
+### `csch`
|
|
|
|
|
|
```nbt
|
|
|
-fn root_newton<A: Dim, B: Dim>(f: Fn[(A) -> B], f_prime: Fn[(A) -> B / A], x0: A, y_tolerance: B) -> A
|
|
|
+fn csch(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
-## Algebra
|
|
|
-
|
|
|
-Defined in: `extra::algebra`
|
|
|
-
|
|
|
-### `quadratic_equation` (Solve quadratic equations)
|
|
|
-Returns the solutions of the equation a x² + b x + c = 0.
|
|
|
-More information [here](https://en.wikipedia.org/wiki/Quadratic_equation).
|
|
|
+### `acsch`
|
|
|
|
|
|
```nbt
|
|
|
-fn quadratic_equation<A: Dim, B: Dim>(a: A, b: B, c: B^2 / A) -> List<B / A>
|
|
|
+fn acsch(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|