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
val add : float -> float -> floatval sub : float -> float -> floatval mul : float -> float -> floatval div : float -> float -> floatval fmod : float -> float -> floatval atan2 : float -> float -> floatatan2 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.
val reci : float -> floatval floor : float -> floatfloor x returns the largest integer \leq x.
val ceil : float -> floatceil x returns the smallest integer \geq x.
val round : float -> floatround x rounds, towards the bigger integer when on the fence.
val trunc : float -> floatval sqrt : float -> floatval pow : float -> float -> floatval exp2 : float -> floatval exp10 : float -> floatval expm1 : float -> floatexpm1 x returns \exp(x) - 1 but more accurate for x \sim 0.
val log2 : float -> floatval log10 : float -> floatlog10 x base-10 logarithm.
val logn : float -> float -> floatval log1p : float -> floatlog1p x returns \log (x + 1) but more accurate for x \sim 0. Inverse of expm1.
val logabs : float -> floatlogabs x returns \log(|x|).
val sigmoid : float -> floatsigmoid x returns the logistic sigmoid function 1 / (1 + \exp(-x)).
val signum : float -> floatsignum x returns the sign of x -1, 0 or 1.
val softsign : float -> floatval softplus : float -> floatsoftplus x returns \log(1 + \exp(x)).
val relu : float -> floatrelu x returns \max(0, x).
val asin : float -> floatasin x returns \arcsin(x).
val acos : float -> floatacos x returns \arccos(x).
val atan : float -> floatval acot : float -> floatval asec : float -> floatval acsc : float -> floatval sinh : float -> floatval cosh : float -> floatval tanh : float -> floatval coth : float -> floatval sech : float -> floatsech x returns 1/\cosh(x).
val csch : float -> floatcsch x returns 1/\sinh(x).
val asinh : float -> floatInverse function of sinh.
val acosh : float -> floatInverse function of cosh.
val atanh : float -> floatInverse function of tanh.
val acoth : float -> floatInverse function of coth.
val asech : float -> floatInverse function of sech.
val acsch : float -> floatInverse function of csch.
val sinc : float -> floatsinc x returns \sin(x)/x and 1 for x=0.
val logsinh : float -> floatlogsinh x returns \log(\sinh(x)) but handles large |x|.
val logcosh : float -> floatlogcosh x returns \log(\cosh(x)) but handles large |x|.
val sindg : float -> floatSine of angle given in degrees.
val cosdg : float -> floatCosine of the angle given in degrees.
val tandg : float -> floatTangent of angle given in degrees.
val cotdg : float -> floatCotangent of the angle given in degrees.
val hypot : float -> float -> floathypot x y returns \sqrt{x^2 + y^2}.
val xlogy : float -> float -> floatxlogy(x, y) returns x \log(y).
val xlog1py : float -> float -> floatxlog1py(x, y) returns x \log(y+1).
val logit : float -> floatlogit(x) returns \log\left(\frac{p}{1-p}\right).
val expit : float -> floatexpit(x) returns \frac{1}{1+\exp(-x)}.
val log1mexp : float -> floatlog1mexp(x) returns \log(1-\exp(x)).
val log1pexp : float -> floatlog1pexp(x) returns \log(1+\exp(x)).
Airy functions
val airy : float -> float * float * float * floatAiry 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
Bessel function of the first kind of order 0.
Bessel function of the first kind of order 1.
val jv : float -> float -> floatBessel function of real order.
Bessel function of the second kind of order 0.
Bessel function of the second kind of order 1.
val yv : float -> float -> floatBessel function of the second kind of real order.
val yn : int -> float -> floatBessel function of the second kind of integer order.
Modified Bessel function of order 0.
Exponentially scaled modified Bessel function of order 0.
Modified Bessel function of order 1.
Exponentially scaled modified Bessel function of order 1.
val iv : float -> float -> floatModified Bessel function of the first kind of real order.
Modified Bessel function of the second kind of order 0, K_0.
Exponentially scaled modified Bessel function K of order 0.
Modified Bessel function of the second kind of order 1, K_1(x).
Exponentially scaled modified Bessel function K of order 1.
Elliptic functions
val ellipj : float -> float -> float * float * float * floatJacobian Elliptic function ellipj u m returns (sn, cn, dn, phi).
val ellipk : float -> floatellipk m returns the complete elliptic integral of the first kind.
val ellipkm1 : float -> floatFIXME. Complete elliptic integral of the first kind around m = 1.
val ellipkinc : float -> float -> floatellipkinc phi m incomplete elliptic integral of the first kind.
val ellipe : float -> floatellipe m complete elliptic integral of the second kind.
val ellipeinc : float -> float -> floatellipeinc phi m incomplete elliptic integral of the second kind.
Gamma Functions
val gamma : float -> floatgamma 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.
val rgamma : float -> floatReciprocal Gamma function.
val loggamma : float -> floatLogarithm of the gamma function.
val gammainc : float -> float -> floatIncomplete gamma function.
val gammaincinv : float -> float -> floatInverse function of gammainc.
val gammaincc : float -> float -> floatComplemented incomplete gamma integral.
val gammainccinv : float -> float -> floatInverse function of gammaincc.
Beta functions
val beta : float -> float -> floatBeta function.
\mathrm{B}(a, b) = \frac{\Gamma(a) \Gamma(b)}{\Gamma(a+b)}val betainc : float -> float -> float -> floatIncomplete beta integral.
val betaincinv : float -> float -> float -> floatInverse function of betainc.
Factorials
Factorial function fact n calculates n!.
val log_fact : int -> floatLogarithm of factorial function log_fact n calculates \log n!.
val doublefact : int -> floatDouble factorial function doublefact n calculates n!! = n(n-2)(n-4)\dots 2 or \dots 1.
val log_doublefact : int -> floatLogarithm of double factorial function.
val permutation : int -> int -> intpermutation n k returns the number \frac{n!}{(n-k)!} of ordered subsets of length k, taken from a set of n elements.
val permutation_float : int -> int -> floatpermutation_float is like permutation but deals with larger range.
val combination : int -> int -> intcombination 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}
val combination_float : int -> int -> floatcombination_float is like combination but can deal with a larger range.
val log_combination : int -> int -> floatlog_combination n k returns the logarithm of \binom{n}{k}.
Error functions
Error function. \int_{-\infty}^x \frac{1}{\sqrt(2\pi)} \exp(-(1/2) y^2) dy
val erfc : float -> floatComplementary error function, \int^{\infty}_x \frac{1}{\sqrt(2\pi)} \exp(-(1/2) y^2) dy
val erfcx : float -> floatScaled complementary error function, \exp(x^2) \mathrm{erfc}(x).
val erfinv : float -> floatval erfcinv : float -> floatInverse function of erfc.
Dawson & Fresnel integrals
val dawsn : float -> floatval fresnel : float -> float * floatFresnel trigonometric integrals. fresnel x returns a tuple consisting of (Fresnel sin integral, Fresnel cos integral).
Struve functions
val struve : float -> float -> floatstruve 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
val expn : int -> float -> floatExponential integral E_n.
val shichi : float -> float * floatHyperbolic sine and cosine integrals, shichi x returns * (\mathrm{shi}, \mathrm{chi}).
Hyperbolic sine integral.
Hyperbolic cosine integral.
val sici : float -> float * floatSine and cosine integrals, sici x returns (\mathrm{si}, \mathrm{ci}).
val zeta : float -> float -> floatzeta x q returns the Hurwitz zeta function \zeta(x, q), which reduces to the Riemann zeta function \zeta(x) when q=1.
val zetac : float -> floatRiemann zeta function minus 1.
Raw statistical functions
val bdtr : int -> int -> float -> floatBinomial 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.
val bdtrc : int -> int -> float -> floatBinomial 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}
val bdtri : int -> int -> float -> floatInverse 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.
val btdtr : float -> float -> float -> floatCumulative 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.
val btdtri : float -> float -> float -> floatThe 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}\,dtwhere \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
val is_nan : float -> boolis_nan x returns true exactly if x is nan.
val is_inf : float -> boolis_inf x returns true exactly if x is infinity or neg_infinity.
val is_normal : float -> boolis_normal x returns true if x is a normal float number.
val is_subnormal : float -> boolis_nan x returns true if x is subnormal float number.
is_odd x returns true exactly if x is odd.
val is_even : int -> boolis_even x returns true exactly if x is even.
val is_pow2 : int -> boolis_pow2 x return true exactly if x is an integer power of 2, e.g. 32, 64, etc.
val same_sign : float -> float -> boolsame_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.
val is_simplex : float array -> boolis_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.
val is_int : float -> boolis_sqr x checks if x is the square of an integer.
val mulmod : int -> int -> int -> intmulmod a b m computes (a*b) mod m.
val powmod : int -> int -> int -> intpowmod a b m computes (a^b) mod m.
val is_prime : int -> boolis_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.
val fermat_fact : int -> int * intfermat_fact x performs Fermat factorisation over x, i.e. into two roughly equal factors. x must be an odd number.
val nextafter : float -> float -> floatnextafter from to returns the next representable double precision value of from in the direction of to. If from equals to, this value is returned.
val nextafterf : float -> float -> floatnextafter from to returns the next representable single precision value of from in the direction of to. If from equals to, this value is returned.