# Sci.Math: Special Math Functions

This module extends the math module of the standard Lua distribution (meaning that it's guaranteed to include everything which is in it) by adding the special mathematical functions listed below. In the following we always refer to math for sci.math. It is always preferable to select the most specialized function for any task, for instance by calling math.loggamma() instead of math.log(math.gamma()).

## API

##### v = math.gamma(x)

Gamma function, defined as: $$\Gamma(x) = \int_{0}^{\infty}e^{-t}t^{x-1}dt$$ where x must be different from 0 and any negative integer.

##### v = math.loggamma(x)

Natural logarithm of the the absolute value of gamma function (the absolute value is relevant only for negative x). The domain of this function is the same of the gamma function.

##### v = math.beta(x, y)

Beta function, defined as: $$\text{B}(x, y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}$$ where x and y must be strictly positive.

##### v = math.logbeta(x, y)

Natural logarithm of the beta function. The domain of this function is the same of the beta function.

##### v = math.phi(x)

Phi function, or cumulative distribution function of a standard normal random variable, defined as: $$\Phi(x) = \int_{-\infty}^{x}\frac{1}{\sqrt{2\pi}}\exp{\{-\frac{t^2}{2}\}}dt$$ for any x.

##### v = math.iphi(x)

Mathematical inverse of the Phi function, or quantile function of a standard normal random variable: $$(I\Phi)(x) = \Phi^{-1}(x)$$ where x is between 0 and 1 (extremes included).

##### v = math.step(x)

Step function, defined as: $$\begin{eqnarray} step(x) = \left\{ \begin{array}{ll} 1 & x \geq 0 \\ 0 & x \lt 0 \end{array} \right. \end{eqnarray}$$

##### v = math.sign(x)

Sign function, defined as: $$\begin{eqnarray} sign(x) = \left\{ \begin{array}{ll} +1 & x \geq 0 \\ -1 & x \lt 0 \end{array} \right. \end{eqnarray}$$

##### v = math.round(x)

Round function, round x to the closest integer. Halfway cases are rounded away from zero regardless of the sign.

##### math.generic

This table contains the same keys of math (this module). The mathematical functions defined in math.generic call the corresponding functions in math whenever all the arguments are Lua numbers. When this is not the case the following rules apply. For function of 1 argument the member function with the same name gets called with the object as single argument. For functions of 2 arguments the same happens and order of the arguments is preserved (the 1st argument might be a Lua number if the second is not). For max(), min() which accept a variable number of arguments a recursive version is implemented which calls the :max(), :min() member functions with 2 arguments only.