package owl

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Owl_mathsSource

Maths: fundamental and advanced mathematical functions.

This module contains some basic and advanced mathematical operations. If you cannot find some function in this module, try Stats module.

Please refer to Scipy documentation.

Basic functions
Sourceval add : float -> float -> float

add x y returns x + y.

Sourceval sub : float -> float -> float

sub x y returns x - y.

Sourceval mul : float -> float -> float

mul x y returns x * y.

Sourceval div : float -> float -> float

div x y returns x / y.

Sourceval fmod : float -> float -> float

fmod x y returns x % y.

Sourceval 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.

Sourceval abs : float -> float

abs x returns =|x|.

Sourceval neg : float -> float

neg x returns -x.

Sourceval reci : float -> float

reci x returns 1/x.

Sourceval floor : float -> float

floor x returns the largest integer \leq x.

Sourceval ceil : float -> float

ceil x returns the smallest integer \geq x.

Sourceval round : float -> float

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

Sourceval trunc : float -> float

trunc x integer part.

Sourceval sqr : float -> float

sqr x square.

Sourceval sqrt : float -> float

sqrt x square root.

Sourceval pow : float -> float -> float

pow x y returns x^y.

Sourceval exp : float -> float

exp x exponential.

Sourceval exp2 : float -> float

exp2 x exponential.

Sourceval exp10 : float -> float

exp10 x exponential.

Sourceval expm1 : float -> float

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

Sourceval log : float -> float

log x natural logarithm

Sourceval log2 : float -> float

log2 x base-2 logarithm.

Sourceval log10 : float -> float

log10 x base-10 logarithm.

Sourceval logn : float -> float -> float

logn x base-n logarithm.

Sourceval log1p : float -> float

log1p x returns \log (x + 1) but more accurate for x \sim 0. Inverse of expm1.

Sourceval logabs : float -> float

logabs x returns \log(|x|).

Sourceval sigmoid : float -> float

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

Sourceval signum : float -> float

signum x returns the sign of x -1, 0 or 1.

Sourceval softsign : float -> float

Smoothed sign function.

Sourceval softplus : float -> float

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

Sourceval relu : float -> float

relu x returns \max(0, x).

Sourceval sin : float -> float

sin x returns \sin(x).

Sourceval cos : float -> float

cos x returns \cos(x).

Sourceval tan : float -> float

tan x returns \tan(x).

Sourceval cot : float -> float

cot x returns 1/\tan(x).

Sourceval sec : float -> float

sec x returns 1/\cos(x).

Sourceval csc : float -> float

csc x returns 1/\sin(x).

Sourceval asin : float -> float

asin x returns \arcsin(x).

Sourceval acos : float -> float

acos x returns \arccos(x).

Sourceval atan : float -> float
Sourceval acot : float -> float

Inverse function of cot.

Sourceval asec : float -> float

Inverse function of sec.

Sourceval acsc : float -> float

Inverse function of csc.

Sourceval sinh : float -> float

Returns \sinh(x).

Sourceval cosh : float -> float

cosh x returns \cosh(x).

Sourceval tanh : float -> float

tanh x returns \tanh(x).

Sourceval coth : float -> float

coth x returns \coth(x).

Sourceval sech : float -> float

sech x returns 1/\cosh(x).

Sourceval csch : float -> float

csch x returns 1/\sinh(x).

Sourceval asinh : float -> float

Inverse function of sinh.

Sourceval acosh : float -> float

Inverse function of cosh.

Sourceval atanh : float -> float

Inverse function of tanh.

Sourceval acoth : float -> float

Inverse function of coth.

Sourceval asech : float -> float

Inverse function of sech.

Sourceval acsch : float -> float

Inverse function of csch.

Sourceval sinc : float -> float

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

Sourceval logsinh : float -> float

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

Sourceval logcosh : float -> float

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

Sourceval sindg : float -> float

Sine of angle given in degrees.

Sourceval cosdg : float -> float

Cosine of the angle given in degrees.

Sourceval tandg : float -> float

Tangent of angle given in degrees.

Sourceval cotdg : float -> float

Cotangent of the angle given in degrees.

Sourceval hypot : float -> float -> float

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

Sourceval xlogy : float -> float -> float

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

Sourceval xlog1py : float -> float -> float

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

Sourceval logit : float -> float

logit(x) returns \log\left(\frac{p}{1-p}\right).

Sourceval expit : float -> float

expit(x) returns \frac{1}{1+\exp(-x)}.

Sourceval log1mexp : float -> float

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

Sourceval log1pexp : float -> float

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

Airy functions
Sourceval 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.

Bessel functions
Sourceval j0 : float -> float

Bessel function of the first kind of order 0.

Sourceval j1 : float -> float

Bessel function of the first kind of order 1.

Sourceval jv : float -> float -> float

Bessel function of real order.

Sourceval y0 : float -> float

Bessel function of the second kind of order 0.

Sourceval y1 : float -> float

Bessel function of the second kind of order 1.

Sourceval yv : float -> float -> float

Bessel function of the second kind of real order.

Sourceval yn : int -> float -> float

Bessel function of the second kind of integer order.

Sourceval i0 : float -> float

Modified Bessel function of order 0.

Sourceval i0e : float -> float

Exponentially scaled modified Bessel function of order 0.

Sourceval i1 : float -> float

Modified Bessel function of order 1.

Sourceval i1e : float -> float

Exponentially scaled modified Bessel function of order 1.

Sourceval iv : float -> float -> float

Modified Bessel function of the first kind of real order.

Sourceval k0 : float -> float

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

Sourceval k0e : float -> float

Exponentially scaled modified Bessel function K of order 0.

Sourceval k1 : float -> float

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

Sourceval k1e : float -> float

Exponentially scaled modified Bessel function K of order 1.

Elliptic functions
Sourceval ellipj : float -> float -> float * float * float * float

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

Sourceval ellipk : float -> float

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

Sourceval ellipkm1 : float -> float

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

Sourceval ellipkinc : float -> float -> float

ellipkinc phi m incomplete elliptic integral of the first kind.

Sourceval ellipe : float -> float

ellipe m complete elliptic integral of the second kind.

Sourceval ellipeinc : float -> float -> float

ellipeinc phi m incomplete elliptic integral of the second kind.

Gamma Functions
Sourceval 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.

Sourceval rgamma : float -> float

Reciprocal Gamma function.

Sourceval loggamma : float -> float

Logarithm of the gamma function.

Sourceval gammainc : float -> float -> float

Incomplete gamma function.

Sourceval gammaincinv : float -> float -> float

Inverse function of gammainc.

Sourceval gammaincc : float -> float -> float

Complemented incomplete gamma integral.

Sourceval gammainccinv : float -> float -> float

Inverse function of gammaincc.

Sourceval psi : float -> float

The digamma function.

Beta functions
Sourceval beta : float -> float -> float

Beta function.

  \mathrm{B}(a, b) =  \frac{\Gamma(a) \Gamma(b)}{\Gamma(a+b)}
Sourceval betainc : float -> float -> float -> float

Incomplete beta integral.

Sourceval betaincinv : float -> float -> float -> float

Inverse function of betainc.

Factorials
Sourceval fact : int -> float

Factorial function fact n calculates n!.

Sourceval log_fact : int -> float

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

Sourceval doublefact : int -> float

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

Sourceval log_doublefact : int -> float

Logarithm of double factorial function.

Sourceval permutation : int -> int -> int

permutation n k returns the number \frac{n!}{(n-k)!} of ordered subsets of length k, taken from a set of n elements.

Sourceval permutation_float : int -> int -> float

permutation_float is like permutation but deals with larger range.

Sourceval 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}

Sourceval combination_float : int -> int -> float

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

Sourceval log_combination : int -> int -> float

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

Error functions
Sourceval erf : float -> float

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

Sourceval erfc : float -> float

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

Sourceval erfcx : float -> float

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

Sourceval erfinv : float -> float

Inverse function of erf.

Sourceval erfcinv : float -> float

Inverse function of erfc.

Dawson & Fresnel integrals
Sourceval dawsn : float -> float

Dawson’s integral.

Sourceval fresnel : float -> float * float

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

Struve functions
Sourceval 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

Other special functions
Sourceval expn : int -> float -> float

Exponential integral E_n.

Sourceval shichi : float -> float * float

Hyperbolic sine and cosine integrals, shichi x returns * (\mathrm{shi}, \mathrm{chi}).

Sourceval shi : float -> float

Hyperbolic sine integral.

Sourceval chi : float -> float

Hyperbolic cosine integral.

Sourceval sici : float -> float * float

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

Sourceval si : float -> float

Sine integral.

Sourceval ci : float -> float

Cosine integral.

Sourceval 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.

Sourceval zetac : float -> float

Riemann zeta function minus 1.

Raw statistical functions
Sourceval 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 \binom{n}{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.

Sourceval 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 \binom{n}{j} p^j (1-p)^{n-j}

Sourceval 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.

Sourceval 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 (b > 0). * x: Upper limit of integration, in [0, 1].

Returns: * Cumulative density function of the beta distribution with a and b at x.

Sourceval 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 (b > 0). * x: Cumulative probability, in [0, 1].

Returns: * The quantile corresponding to p.

Helper functions
Sourceval is_nan : float -> bool

is_nan x returns true exactly if x is nan.

Sourceval is_inf : float -> bool

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

Sourceval is_normal : float -> bool

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

Sourceval is_subnormal : float -> bool

is_nan x returns true if x is subnormal float number.

Sourceval is_odd : int -> bool

is_odd x returns true exactly if x is odd.

Sourceval is_even : int -> bool

is_even x returns true exactly if x is even.

Sourceval is_pow2 : int -> bool

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

Sourceval 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.

Sourceval 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.

Sourceval is_int : float -> bool
Sourceval is_sqr : int -> bool

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

Sourceval mulmod : int -> int -> int -> int

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

Sourceval powmod : int -> int -> int -> int

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

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

OCaml

Innovation. Community. Security.