Maths

This document is auto-generated for Owl’s APIs. #163 entries have been extracted.

Github: {Signature} {Implementation}

Basic functions

val add : float -> float -> float

add x y returns \(x + y\).

source code

val sub : float -> float -> float

sub x y returns \(x - y\).

source code

val mul : float -> float -> float

mul x y returns \(x * y\).

source code

val div : float -> float -> float

div x y returns \(x / y\).

source code

val fmod : float -> float -> float

fmod x y returns \(x % y\).

source code

val atan2 : float -> float -> float
atan2 y x returns \(\arctan(y/x)\), accounting for the sign of the arguments;
this is the angle to the vector \((x, y)\) counting from the x-axis.

source code

val abs : float -> float

abs x returns \(|x|\).

source code

val neg : float -> float

neg x returns \(-x\).

source code

val reci : float -> float

reci x returns \(1/x\).

source code

val floor : float -> float

floor x returns the largest integer \(\leq x\).

source code

val ceil : float -> float

ceil x returns the smallest integer \(\geq x\).

source code

val round : float -> float

round x rounds, towards the bigger integer when on the fence.

source code

val trunc : float -> float

trunc x integer part.

source code

val sqr : float -> float

sqr x square.

source code

val sqrt : float -> float

sqrt x square root.

source code

val pow : float -> float -> float

pow x y returns \(x^y\).

source code

val exp : float -> float

exp x exponential.

source code

val exp2 : float -> float

exp2 x exponential.

source code

val exp10 : float -> float

exp10 x exponential.

source code

val expm1 : float -> float

expm1 x returns \(\exp(x) - 1\) but more accurate for \(x \sim 0\).

source code

val log : float -> float

log x natural logarithm

source code

val log2 : float -> float

log2 x base-2 logarithm.

source code

val log10 : float -> float

log10 x base-10 logarithm.

source code

val logn : float -> float -> float

logn x base-n logarithm.

source code

val log1p : float -> float
log1p x returns \(\log (x + 1)\) but more accurate for \(x \sim 0\).
Inverse of expm1.

source code

val logabs : float -> float

logabs x returns \(\log(|x|)\).

source code

val sigmoid : float -> float

sigmoid x returns the logistic sigmoid function \(1 / (1 + \exp(-x))\).

source code

val signum : float -> float

signum x returns the sign of \(x\): -1, 0 or 1.

source code

val softsign : float -> float

Smoothed sign function.

source code

val softplus : float -> float

softplus x returns \(\log(1 + \exp(x))\).

source code

val relu : float -> float

relu x returns \(\max(0, x)\).

source code

val sin : float -> float

sin x returns \(\sin(x)\).

source code

val cos : float -> float

cos x returns \(\cos(x)\).

source code

val tan : float -> float

tan x returns \(\tan(x)\).

source code

val cot : float -> float

cot x returns \(1/\tan(x)\).

source code

val sec : float -> float

sec x returns \(1/\cos(x)\).

source code

val csc : float -> float

csc x returns \(1/\sin(x)\).

source code

val asin : float -> float

asin x returns \(\arcsin(x)\).

source code

val acos : float -> float

acos x returns \(\arccos(x)\).

source code

val atan : float -> float

atan x returns \(\arctan(x)\).

source code

val acot : float -> float

Inverse function of cot.

source code

val asec : float -> float

Inverse function of sec.

source code

val acsc : float -> float

Inverse function of csc.

source code

val sinh : float -> float

Returns \(\sinh(x)\).

source code

val cosh : float -> float

cosh x returns \(\cosh(x)\).

source code

val tanh : float -> float

tanh x returns \(\tanh(x)\).

source code

val coth : float -> float

coth x returns \(\coth(x)\).

source code

val sech : float -> float

sech x returns \(1/\cosh(x)\).

source code

val csch : float -> float

csch x returns \(1/\sinh(x)\).

source code

val asinh : float -> float

Inverse function of sinh.

source code

val acosh : float -> float

Inverse function of cosh.

source code

val atanh : float -> float

Inverse function of tanh.

source code

val acoth : float -> float

Inverse function of coth.

source code

val asech : float -> float

Inverse function of sech.

source code

val acsch : float -> float

Inverse function of csch.

source code

val sinc : float -> float

sinc x returns \(\sin(x)/x\) and \(1\) for \(x=0\).

source code

val logsinh : float -> float

logsinh x returns \(\log(\sinh(x))\) but handles large \(|x|\).

source code

val logcosh : float -> float

logcosh x returns \(\log(\cosh(x))\) but handles large \(|x|\).

source code

val sindg : float -> float

Sine of angle given in degrees.

source code

val cosdg : float -> float

Cosine of the angle given in degrees.

source code

val tandg : float -> float

Tangent of angle given in degrees.

source code

val cotdg : float -> float

Cotangent of the angle given in degrees.

source code

val hypot : float -> float -> float

hypot x y returns \(\sqrt{x^2 + y^2}\).

source code

val xlogy : float -> float -> float

xlogy(x, y) returns \(x \log(y)\).

source code

val xlog1py : float -> float -> float

xlog1py(x, y) returns \(x \log(y+1)\).

source code

val logit : float -> float

logit(x) returns \(\log[p/(1-p)]\).

source code

val expit : float -> float

expit(x) returns \(1/(1+\exp(-x))\).

source code

val log1mexp : float -> float

log1mexp(x) returns \(log(1-exp(x))\).

source code

val log1pexp : float -> float

log1pexp(x) returns \(log(1+exp(x))\).

source code

Airy functions

val airy : float -> float * float * float * float

Airy function airy x returns (Ai, Ai', Bi, Bi') evaluated at \(x\). Ai' is the derivative of Ai whilst Bi' is the derivative of Bi.

source code

Bessel functions

val j0 : float -> float

Bessel function of the first kind of order 0.

source code

val j1 : float -> float

Bessel function of the first kind of order 1.

source code

val jv : float -> float -> float

Bessel function of real order.

source code

val y0 : float -> float

Bessel function of the second kind of order 0.

source code

val y1 : float -> float

Bessel function of the second kind of order 1.

source code

val yv : float -> float -> float

Bessel function of the second kind of real order.

source code

val yn : int -> float -> float

Bessel function of the second kind of integer order.

source code

val i0 : float -> float

Modified Bessel function of order 0.

source code

val i0e : float -> float

Exponentially scaled modified Bessel function of order 0.

source code

val i1 : float -> float

Modified Bessel function of order 1.

source code

val i1e : float -> float

Exponentially scaled modified Bessel function of order 1.

source code

val iv : float -> float -> float

Modified Bessel function of the first kind of real order.

source code

val k0 : float -> float

Modified Bessel function of the second kind of order 0, \(K_0\).

source code

val k0e : float -> float

Exponentially scaled modified Bessel function K of order 0.

source code

val k1 : float -> float

Modified Bessel function of the second kind of order 1, \(K_1(x)\).

source code

val k1e : float -> float

Exponentially scaled modified Bessel function K of order 1.

source code

Elliptic functions

val ellipj : float -> float -> float * float * float * float

Jacobian Elliptic function ellipj u m returns (sn, cn, dn, phi).

source code

val ellipk : float -> float

ellipk m returns the complete elliptic integral of the first kind.

source code

val ellipkm1 : float -> float

FIXME. Complete elliptic integral of the first kind around \(m = 1\).

source code

val ellipkinc : float -> float -> float

ellipkinc phi m incomplete elliptic integral of the first kind.

source code

val ellipe : float -> float

ellipe m complete elliptic integral of the second kind.

source code

val ellipeinc : float -> float -> float

ellipeinc phi m incomplete elliptic integral of the second kind.

source code

Gamma Functions

val gamma : float -> float

gamma z returns the value of the Gamma function

\[\Gamma(z) = \int_0^\infty x^{z-1} e^{-x} dx = (z - 1)! .\]

The gamma function is often referred to as the generalized factorial since \(z\ gamma(z) = \gamma(z+1)\) and \(gamma(n+1) = n!\) for natural number \(n\).

source code

val rgamma : float -> float

Reciprocal Gamma function.

source code

val loggamma : float -> float

Logarithm of the gamma function.

source code

val gammainc : float -> float -> float

Incomplete gamma function.

source code

val gammaincinv : float -> float -> float

Inverse function of gammainc.

source code

val gammaincc : float -> float -> float

Complemented incomplete gamma integral.

source code

val gammainccinv : float -> float -> float

Inverse function of gammaincc.

source code

val psi : float -> float

The digamma function.

source code

Beta functions

val beta : float -> float -> float

Beta function.

\[\mathrm{B}(a, b) = \frac{\Gamma(a) \Gamma(b)}{\Gamma(a+b)}\]

source code

val betainc : float -> float -> float -> float

Incomplete beta integral.

source code

val betaincinv : float -> float -> float -> float

Inverse function of betainc.

source code

Factorials

val fact : int -> float

Factorial function fact n calculates \(n!\).

source code

val log_fact : int -> float

Logarithm of factorial function log_fact n calculates \(\log n!\).

source code

val doublefact : int -> float

Double factorial function doublefact n calculates \(n!! = n(n-2)(n-4)\dots 2\) or \(\dots 1\)

source code

val log_doublefact : int -> float

Logarithm of double factorial function.

source code

val permutation : int -> int -> int
permutation n k returns the number \(n!/(n-k)!\) of ordered subsets
  • of length \(k\), taken from a set of \(n\) elements.

source code

val permutation_float : int -> int -> float

permutation_float is like permutation but deals with larger range.

source code

val combination : int -> int -> int
combination n k returns the number \(n!/(k!(n-k)!)\) of subsets of k elements
of a set of n elements. This is the binomial coefficient \(\binom{n}{k}\)

source code

val combination_float : int -> int -> float

combination_float is like combination but can deal with a larger range.

source code

val log_combination : int -> int -> float

log_combination n k returns the logarithm of \(\binom{n}{k}\).

source code

Error functions

val erf : float -> float

Error function. \(\int_{-\infty}^x \frac{1}{\sqrt(2\pi)} \exp(-(1/2) y^2) dy\)

source code

val erfc : float -> float

Complementary error function, \(\int^{\infty}_x \frac{1}{\sqrt(2\pi)} \exp(-(1/2) y^2) dy\)

source code

val erfcx : float -> float

Scaled complementary error function, \(\exp(x^2) \mathrm{erfc}(x)\).

source code

val erfinv : float -> float

Inverse function of erf.

source code

val erfcinv : float -> float

Inverse function of erfc.

source code

Dawson & Fresnel integrals

val dawsn : float -> float

Dawson’s integral.

source code

val fresnel : float -> float * float

Fresnel trigonometric integrals. fresnel x returns a tuple consisting of (Fresnel sin integral, Fresnel cos integral).

source code

Struve functions

val struve : float -> float -> float

struve v x returns the value of the Struve function of order \(v\) at \(x\). The Struve function is defined as,

\[H_v(x) = (z/2)^{v + 1} \sum_{n=0}^\infty \frac{(-1)^n (z/2)^{2n}}{\Gamma(n + \frac{3}{2}) \Gamma(n + v + \frac{3}{2})},\]

where \(\Gamma\) is the gamma function. \(x\) must be positive unless \(v\) is an integer

source code

Other special functions

val expn : int -> float -> float

Exponential integral \(E_n\).

source code

val shichi : float -> float * float
Hyperbolic sine and cosine integrals, shichi x returns
  • \((\mathrm{shi}, \mathrm{chi})`\).

source code

val shi : float -> float

Hyperbolic sine integral.

source code

val chi : float -> float

Hyperbolic cosine integral.

source code

val sici : float -> float * float

Sine and cosine integrals, sici x returns \((\mathrm{si}, \mathrm{ci})\).

source code

val si : float -> float

Sine integral.

val ci : float -> float

Cosine integral.

val zeta : float -> float -> float
zeta x q returns the Hurwitz zeta function \(\zeta(x, q)\), which
reduces to the Riemann zeta function \(\zeta(x)\) when \(q=1\).

source code

val zetac : float -> float

Riemann zeta function minus 1.

source code

Raw statistical functions

val bdtr : int -> int -> float -> float

Binomial distribution cumulative distribution function.

bdtr k n p calculates the sum of the terms \(0\) through \(k\) of the Binomial probability density.

\[\mathrm{bdtr}(k, n, p) = \sum_{j=0}^k {{n}\choose{j}} p^j (1-p)^{n-j}\]
Parameters:
  • k: Number of successes.
  • n: Number of events.
  • p: Probability of success in a single event.
Returns:
  • Probability of \(k\) or fewer successes in \(n\) independent events with success probability \(p\).

source code

val bdtrc : int -> int -> float -> float

Binomial distribution survival function.

bdtrc k n p calculates the sum of the terms \(k + 1\) through \(n\) of the binomial probability density,

\[\mathrm{bdtrc}(k, n, p) = \sum_{j=k+1}^n {{n}\choose{j}} p^j (1-p)^{n-j}\]

source code

val bdtri : int -> int -> float -> float

Inverse function to bdtr with respect to \(p\).

Finds the event probability \(p\) such that the sum of the terms 0 through \(k\) of the binomial probability density is equal to the given cumulative probability \(y\).

source code

val btdtr : float -> float -> float -> float

Cumulative density function of the beta distribution.

btdtr a b x returns the integral from 0 to \(x\) of the beta probability density function,

\[I = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt\]

where \(\Gamma\) is the gamma function.

Parameters:
  • a: Shape parameter (\(a > 0\)).
  • b: Shape parameter (\(a > 0\)).
  • x: Upper limit of integration, in \([0, 1]\).
Returns:
  • Cumulative density function of the beta distribution with \(a\) and \(b\) at \(x\).

source code

val btdtri : float -> float -> float -> float

The \(p\)-th quantile of the Beta distribution.

This function is the inverse of the beta cumulative distribution function,
btdtr, returning the value of \(x\) for which \(\mathrm{btdtr}(a, b, x) = p\),
\[p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt\]

where \(\Gamma\) is the gamma function.

Parameters:
  • a: Shape parameter (\(a > 0\)).
  • b: Shape parameter (\(a > 0\)).
  • x: Cumulative probability, in \([0, 1]\).
Returns:
  • The quantile corresponding to \(p\).

source code

Helper functions

val is_nan : float -> bool

is_nan x returns true exactly if x is nan.

source code

val is_inf : float -> bool

is_inf x returns true exactly if x is infinity or neg_infinity.

source code

val is_normal : float -> bool

is_normal x returns true if x is a normal float number.

source code

val is_subnormal : float -> bool

is_nan x returns true if x is subnormal float number.

source code

val is_odd : int -> bool

is_odd x returns true exactly if x is odd.

source code

val is_even : int -> bool

is_even x returns true exactly if x is even.

source code

val is_pow2 : int -> bool

is_pow2 x return true exactly if x is an integer power of 2, e.g. 32, 64, etc.

source code

val same_sign : float -> float -> bool

same_sign x y returns true if x and y have the same sign, otherwise it returns false. Positive and negative zeros are special cases and always returns true.

source code

val is_simplex : float array -> bool

is_simplex x checks whether the vector \(x\) lies on a simplex. In other words, \(\sum_i^K x_i = 1\) and \(x_i \ge 0, \forall i \in [1,K]\), where \(K\) is the dimension of \(x\).

source code

val is_sqr : int -> bool

is_sqr x checks if x is the square of an integer.

source code

val mulmod : int -> int -> int -> int

mulmod a b m computes (a*b) mod m.

source code

val powmod : int -> int -> int -> int

powmod a b m computes (a^b) mod m.

source code

val is_prime : int -> bool

is_prime x returns true if x is a prime number. The function is deterministic for all numbers representable by an int. The function uses the Rabin–Miller primality test.

source code

val fermat_fact : int -> int * int

fermat_fact x performs Fermat factorisation over x, i.e. into two roughly equal factors. x must be an odd number.

source code

val nextafter : float -> float -> float

nextafter from to returns the next representable double precision value of from in the direction of to. If from equals to, this value is returned.

source code

val nextafterf : float -> float -> float

nextafter from to returns the next representable single precision value of from in the direction of to. If from equals to, this value is returned.

source code