Maths

This document is auto-generated for Owl’s APIs. #150 entries have been extracted. timestamp: 2018-04-16 13:12:53

Github: {Signature} {Implementation}

Basic functions

val add : float -> float -> float

add x y gives x + y.

source code

val sub : float -> float -> float

sub x y gives x - y.

source code

val mul : float -> float -> float

mul x y gives x * y.

source code

val div : float -> float -> float

div x y gives x / y.

source code

val atan2 : float -> float -> float
atan2 y x gives 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 gives |x|.

source code

val neg : float -> float

neg x gives -x.

source code

val reci : float -> float

reci x gives 1/x.

source code

val floor : float -> float

floor x gives the largest integer <= x.

source code

val ceil : float -> float

ceil x gives the smallest integer >= 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 gives x^y.

source code

val exp : float -> float

exp x exponential.

source code

val expm1 : float -> float

expm1 x gives exp(x) - 1 but more accurate for x ~ 0.

source code

val log : float -> float

log x natural logarithm

source code

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

source code

val logabs : float -> float

logabs x gives log(abs(x)).

source code

val log2 : float -> float

log2 x gives the base-2 logarithm of x.

source code

val log10 : float -> float

log10 x gives the base-10 logarithm of x.

source code

val logn : float -> float -> float

logn x gives the base-n logarithm of x.

source code

val sigmoid : float -> float

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

source code

val signum : float -> float

signum x gives the sign of x: -1, 0 or 1.

source code

val softsign : float -> float

softsign x smoothed sign function.

source code

val softplus : float -> float

softplus x gives log(1+exp(x)).

source code

val relu : float -> float

relu x gives max(0, x).

source code

val sin : float -> float

sin x gives sin(x).

source code

val cos : float -> float

cos x gives cos(x).

source code

val tan : float -> float

tan x gives tan(x).

source code

val cot : float -> float

cot x gives 1/tan(x).

source code

val sec : float -> float

sec x gives 1/cos(x).

source code

val csc : float -> float

csc x gives 1/sin(x).

source code

val asin : float -> float

asin x gives arcsin(x).

source code

val acos : float -> float

acos x gives arccos(x).

source code

val atan : float -> float

atan x gives arctan(x).

source code

val acot : float -> float

acot x gives arccotan(x).

source code

val asec : float -> float

asec x gives arcsec(x).

source code

val acsc : float -> float

acsc x gives arccosec(x).

source code

val sinh : float -> float

sinh x gives sinh(x).

source code

val cosh : float -> float

cosh x gives cosh(x).

source code

val tanh : float -> float

tanh x gives tanh(x).

source code

val coth : float -> float

coth x gives coth(x).

source code

val sech : float -> float

sech x gives sech(x).

source code

val csch : float -> float

csch x gives cosech(x).

source code

val asinh : float -> float

asinh x gives arcsinh(x).

source code

val acosh : float -> float

acosh x gives arccosh(x).

source code

val atanh : float -> float

atanh x gives arctanh(x).

source code

val acoth : float -> float

acoth x gives arccoth(x).

source code

val asech : float -> float

asech x gives arcsech(x).

source code

val acsch : float -> float

acsch x gives arccosech(x).

source code

val sinc : float -> float

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

source code

val logsinh : float -> float

logsinh x gives log(sinh(x)) but handles large |x|.

source code

val logcosh : float -> float

logcosh x gives 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 x given in degrees.

source code

val tandg : float -> float

Tangent of angle x given in degrees.

source code

val cotdg : float -> float

Cotangent of the angle x given in degrees.

source code

val hypot : float -> float -> float

Calculate the length of the hypotenuse.

source code

val xlogy : float -> float -> float

xlogy(x, y) gives x*log(y).

source code

val xlog1py : float -> float -> float

xlog1py(x, y) gives x*log(y+1).

source code

val logit : float -> float

logit(x) gives log(p/(1-p)).

source code

val expit : float -> float

expit(x) gives 1/(1+exp(-x)).

source code

Airy functions

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

Airy function airy x returns (Ai, Aip, Bi, Bip). Aip is the derivative of Ai whilst Bip 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

Complete elliptic integral of the first kind ellipk m.

source code

val ellipkm1 : float -> float

Complete elliptic integral of the first kind around m = 1.

source code

val ellipkinc : float -> float -> float

Incomplete elliptic integral of the first kind ellipkinc phi m.

source code

val ellipe : float -> float

Complete elliptic integral of the second kind ellipe m.

source code

val ellipeinc : float -> float -> float

Incomplete elliptic integral of the second kind ellipeinc phi m.

source code

Gamma Functions

val gamma : float -> float

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.

Parameters:
  • z
Returns:
  • The value of gamma(z).

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 funciton of beta integral.

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)…

source code

val log_doublefact : int -> float
Logarithm of double factorial function. log_doublefact n calculates
log(n!!)

source code

val permutation : int -> int -> int
permutation n k gives 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 deal with larger range.

source code

val combination : int -> int -> int
combination n k gives the number n!/(k!(n-k)!) of subsets of k elements
of a set of n elements. This is the binomial coefficient ‘n choose 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 gives the logarithm of ‘n choose 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, 1 - erf(x).

source code

val erfcx : float -> float

Scaled complementary error function, exp(x^2) * erfc(x).

source code

val erfinv : float -> float

Inverse of erf.

source code

val erfcinv : float -> float

Inverse of erfc.

source code

Dawson & Fresnel integrals

val dawsn : float -> float

Dawson’s integral.

source code

val fresnel : float -> float * float

Fresnel sin and cos 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.

Parameters:
  • v: order of the Struve function (float).
  • x: Argument of the Struve function (float; 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 (shi, 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 (si, ci).

source code

val si : float -> float

Sine integral.

val ci : float -> float

Cosine integral.

val zeta : float -> float -> float
zeta x q gives 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 probabilities of 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 zero 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 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 if x is nan.

source code

val is_inf : float -> bool

is_inf x returns true if x is infinity or neg_infinity.

source code

val is_odd : int -> bool

is_odd x returns true if x is odd.

source code

val is_even : int -> bool

is_even x returns true if x is even.

source code

val is_pow2 : int -> bool

is_pow2 x return true if x is 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 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