--- layout: default ---

Function reference #

Core functions #

Function | Description ---- | ----------- [math.config(config: Object): Object](functions/config.html) | Set configuration options for math. [math.import(object, override)](functions/import.html) | Import functions from an object or a module. [math.typed(name, signatures) : function](functions/typed.html) | Create a typed-function which checks the types of the arguments and can match them against multiple provided signatures.

Construction functions #

Function | Description ---- | ----------- [math.bignumber(x)](functions/bignumber.html) | Create a BigNumber, which can store numbers with arbitrary precision. [math.boolean(x)](functions/boolean.html) | Create a boolean or convert a string or number to a boolean. [math.chain(value)](functions/chain.html) | Wrap any value in a chain, allowing to perform chained operations on the value. [math.complex(re, im)](functions/complex.html) | Create a complex value or convert a value to a complex value. [math.createUnit(units)](functions/createUnit.html) | Create a user-defined unit and register it with the Unit type. [math.fraction(numerator, denominator)](functions/fraction.html) | Create a fraction convert a value to a fraction. [math.index(range1, range2, ...)](functions/index.html) | Create an index. [math.matrix(x)](functions/matrix.html) | Create a Matrix. [math.number(value)](functions/number.html) | Create a number or convert a string, boolean, or unit to a number. [math.sparse(x)](functions/sparse.html) | Create a Sparse Matrix. [math.splitUnit(unit, parts)](functions/splitUnit.html) | Split a unit in an array of units whose sum is equal to the original unit. [math.string(value)](functions/string.html) | Create a string or convert any object into a string. [math.unit(x)](functions/unit.html) | Create a unit.

Expression functions #

Function | Description ---- | ----------- [math.compile(expr)](functions/compile.html) | Parse and compile an expression. [math.eval(expr [, scope])](functions/eval.html) | Evaluate an expression. [math.help(search)](functions/help.html) | Retrieve help on a function or data type. [math.parse(expr [, scope])](functions/parse.html) | Parse an expression. [math.parser()](functions/parser.html) | Create a parser.

Algebra functions #

Function | Description ---- | ----------- [derivative(expr, variable)](functions/derivative.html) | Takes the derivative of an expression expressed in parser Nodes. [math.lsolve(L, b)](functions/lsolve.html) | Solves the linear equation system by forwards substitution. [math.lup(A)](functions/lup.html) | Calculate the Matrix LU decomposition with partial pivoting. [math.lusolve(A, b)](functions/lusolve.html) | Solves the linear system `A * x = b` where `A` is an [n x n] matrix and `b` is a [n] column vector. [math.qr(A)](functions/qr.html) | Calculate the Matrix QR decomposition. [rationalize(expr)](functions/rationalize.html) | Transform a rationalizable expression in a rational fraction. [simplify(expr)](functions/simplify.html) | Simplify an expression tree. [math.slu(A, order, threshold)](functions/slu.html) | Calculate the Sparse Matrix LU decomposition with full pivoting. [math.usolve(U, b)](functions/usolve.html) | Solves the linear equation system by backward substitution.

Arithmetic functions #

Function | Description ---- | ----------- [math.abs(x)](functions/abs.html) | Calculate the absolute value of a number. [math.add(x, y)](functions/add.html) | Add two or more values, `x + y`. [math.cbrt(x [, allRoots])](functions/cbrt.html) | Calculate the cubic root of a value. [math.ceil(x)](functions/ceil.html) | Round a value towards plus infinity If `x` is complex, both real and imaginary part are rounded towards plus infinity. [math.cube(x)](functions/cube.html) | Compute the cube of a value, `x * x * x`. [math.divide(x, y)](functions/divide.html) | Divide two values, `x / y`. [math.dotDivide(x, y)](functions/dotDivide.html) | Divide two matrices element wise. [math.dotMultiply(x, y)](functions/dotMultiply.html) | Multiply two matrices element wise. [math.dotPow(x, y)](functions/dotPow.html) | Calculates the power of x to y element wise. [math.exp(x)](functions/exp.html) | Calculate the exponent of a value. [math.expm1(x)](functions/expm1.html) | Calculate the value of subtracting 1 from the exponential value. [math.fix(x)](functions/fix.html) | Round a value towards zero. [math.floor(x)](functions/floor.html) | Round a value towards minus infinity. [math.gcd(a, b)](functions/gcd.html) | Calculate the greatest common divisor for two or more values or arrays. [math.hypot(a, b, ...)](functions/hypot.html) | Calculate the hypotenusa of a list with values. [math.lcm(a, b)](functions/lcm.html) | Calculate the least common multiple for two or more values or arrays. [math.log(x [, base])](functions/log.html) | Calculate the logarithm of a value. [math.log10(x)](functions/log10.html) | Calculate the 10-base logarithm of a value. [math.log1p(x)](functions/log1p.html) | Calculate the logarithm of a `value+1`. [math.log2(x)](functions/log2.html) | Calculate the 2-base of a value. [math.mod(x, y)](functions/mod.html) | Calculates the modulus, the remainder of an integer division. [math.multiply(x, y)](functions/multiply.html) | Multiply two or more values, `x * y`. [math.norm(x [, p])](functions/norm.html) | Calculate the norm of a number, vector or matrix. [math.nthRoot(a)](functions/nthRoot.html) | Calculate the nth root of a value. [math.nthRoots(x)](functions/nthRoots.html) | Calculate the nth roots of a value. [math.pow(x, y)](functions/pow.html) | Calculates the power of x to y, `x ^ y`. [math.round(x [, n])](functions/round.html) | Round a value towards the nearest integer. [math.sign(x)](functions/sign.html) | Compute the sign of a value. [math.sqrt(x)](functions/sqrt.html) | Calculate the square root of a value. [math.square(x)](functions/square.html) | Compute the square of a value, `x * x`. [math.subtract(x, y)](functions/subtract.html) | Subtract two values, `x - y`. [math.unaryMinus(x)](functions/unaryMinus.html) | Inverse the sign of a value, apply a unary minus operation. [math.unaryPlus(x)](functions/unaryPlus.html) | Unary plus operation. [math.xgcd(a, b)](functions/xgcd.html) | Calculate the extended greatest common divisor for two values.

Bitwise functions #

Function | Description ---- | ----------- [math.bitAnd(x, y)](functions/bitAnd.html) | Bitwise AND two values, `x & y`. [math.bitNot(x)](functions/bitNot.html) | Bitwise NOT value, `~x`. [math.bitOr(x, y)](functions/bitOr.html) | Bitwise OR two values, `x | y`. [math.bitXor(x, y)](functions/bitXor.html) | Bitwise XOR two values, `x ^ y`. [math.leftShift(x, y)](functions/leftShift.html) | Bitwise left logical shift of a value x by y number of bits, `x << y`. [math.rightArithShift(x, y)](functions/rightArithShift.html) | Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`. [math.rightLogShift(x, y)](functions/rightLogShift.html) | Bitwise right logical shift of value x by y number of bits, `x >>> y`.

Combinatorics functions #

Function | Description ---- | ----------- [math.bellNumbers(n)](functions/bellNumbers.html) | The Bell Numbers count the number of partitions of a set. [math.catalan(n)](functions/catalan.html) | The Catalan Numbers enumerate combinatorial structures of many different types. [math.composition(n, k)](functions/composition.html) | The composition counts of n into k parts. [math.stirlingS2(n, k)](functions/stirlingS2.html) | The Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets.

Complex functions #

Function | Description ---- | ----------- [math.arg(x)](functions/arg.html) | Compute the argument of a complex value. [math.conj(x)](functions/conj.html) | Compute the complex conjugate of a complex value. [math.im(x)](functions/im.html) | Get the imaginary part of a complex number. [math.re(x)](functions/re.html) | Get the real part of a complex number.

Geometry functions #

Function | Description ---- | ----------- [math.distance([x1, y1], [x2, y2])](functions/distance.html) | Calculates: The eucledian distance between two points in 2 and 3 dimensional spaces. [math.intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)](functions/intersect.html) | Calculates the point of intersection of two lines in two or three dimensions and of a line and a plane in three dimensions.

Logical functions #

Function | Description ---- | ----------- [math.and(x, y)](functions/and.html) | Logical `and`. [math.not(x)](functions/not.html) | Logical `not`. [math.or(x, y)](functions/or.html) | Logical `or`. [math.xor(x, y)](functions/xor.html) | Logical `xor`.

Matrix functions #

Function | Description ---- | ----------- [math.concat(a, b, c, ... [, dim])](functions/concat.html) | Concatenate two or more matrices. [math.cross(x, y)](functions/cross.html) | Calculate the cross product for two vectors in three dimensional space. [math.ctranspose(x)](functions/ctranspose.html) | Transpose and complex conjugate a matrix. [math.det(x)](functions/det.html) | Calculate the determinant of a matrix. [math.diag(X)](functions/diag.html) | Create a diagonal matrix or retrieve the diagonal of a matrix When `x` is a vector, a matrix with vector `x` on the diagonal will be returned. [math.dot(x, y)](functions/dot.html) | Calculate the dot product of two vectors. [math.expm(x)](functions/expm.html) | Compute the matrix exponential, expm(A) = e^A. [math.filter(x, test)](functions/filter.html) | Filter the items in an array or one dimensional matrix. [math.flatten(x)](functions/flatten.html) | Flatten a multi dimensional matrix into a single dimensional matrix. [math.forEach(x, callback)](functions/forEach.html) | Iterate over all elements of a matrix/array, and executes the given callback function. [math.getMatrixDataType(x)](functions/getMatrixDataType.html) | Find the data type of all elements in a matrix or array, for example 'number' if all items are a number and 'Complex' if all values are complex numbers. [math.identity(n)](functions/identity.html) | Create a 2-dimensional identity matrix with size m x n or n x n. [math.inv(x)](functions/inv.html) | Calculate the inverse of a square matrix. [math.kron(x, y)](functions/kron.html) | Calculates the kronecker product of 2 matrices or vectors. [math.map(x, callback)](functions/map.html) | Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array. [math.ones(m, n, p, ...)](functions/ones.html) | Create a matrix filled with ones. [math.partitionSelect(x, k)](functions/partitionSelect.html) | Partition-based selection of an array or 1D matrix. [math.range(start, end [, step])](functions/range.html) | Create an array from a range. [math.reshape(x, sizes)](functions/reshape.html) | Reshape a multi dimensional array to fit the specified dimensions. [math.resize(x, size [, defaultValue])](functions/resize.html) | Resize a matrix. [math.size(x)](functions/size.html) | Calculate the size of a matrix or scalar. [math.sort(x)](functions/sort.html) | Sort the items in a matrix. [X = math.sqrtm(A)](functions/sqrtm.html) | Calculate the principal square root of a square matrix. [math.squeeze(x)](functions/squeeze.html) | Squeeze a matrix, remove inner and outer singleton dimensions from a matrix. [math.subset(x, index [, replacement])](functions/subset.html) | Get or set a subset of a matrix or string. [math.trace(x)](functions/trace.html) | Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix. [math.transpose(x)](functions/transpose.html) | Transpose a matrix. [math.zeros(m, n, p, ...)](functions/zeros.html) | Create a matrix filled with zeros.

Probability functions #

Function | Description ---- | ----------- [math.combinations(n, k)](functions/combinations.html) | Compute the number of ways of picking `k` unordered outcomes from `n` possibilities. [math.factorial(n)](functions/factorial.html) | Compute the factorial of a value Factorial only supports an integer value as argument. [math.gamma(n)](functions/gamma.html) | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values. [math.kldivergence(x, y)](functions/kldivergence.html) | Calculate the Kullback-Leibler (KL) divergence between two distributions. [math.multinomial(a)](functions/multinomial.html) | Multinomial Coefficients compute the number of ways of picking a1, a2, . [math.permutations(n [, k])](functions/permutations.html) | Compute the number of ways of obtaining an ordered subset of `k` elements from a set of `n` elements. [math.pickRandom(array)](functions/pickRandom.html) | Random pick one or more values from a one dimensional array. [math.random([min, max])](functions/random.html) | Return a random number larger or equal to `min` and smaller than `max` using a uniform distribution. [math.randomInt([min, max])](functions/randomInt.html) | Return a random integer number larger or equal to `min` and smaller than `max` using a uniform distribution.

Relational functions #

Function | Description ---- | ----------- [math.compare(x, y)](functions/compare.html) | Compare two values. [math.compareNatural(x, y)](functions/compareNatural.html) | Compare two values of any type in a deterministic, natural way. [math.compareText(x, y)](functions/compareText.html) | Compare two strings lexically. [math.deepEqual(x, y)](functions/deepEqual.html) | Test element wise whether two matrices are equal. [math.equal(x, y)](functions/equal.html) | Test whether two values are equal. [math.equalText(x, y)](functions/equalText.html) | Check equality of two strings. [math.larger(x, y)](functions/larger.html) | Test whether value x is larger than y. [math.largerEq(x, y)](functions/largerEq.html) | Test whether value x is larger or equal to y. [math.smaller(x, y)](functions/smaller.html) | Test whether value x is smaller than y. [math.smallerEq(x, y)](functions/smallerEq.html) | Test whether value x is smaller or equal to y. [math.unequal(x, y)](functions/unequal.html) | Test whether two values are unequal.

Set functions #

Function | Description ---- | ----------- [math.setCartesian(set1, set2)](functions/setCartesian.html) | Create the cartesian product of two (multi)sets. [math.setDifference(set1, set2)](functions/setDifference.html) | Create the difference of two (multi)sets: every element of set1, that is not the element of set2. [math.setDistinct(set)](functions/setDistinct.html) | Collect the distinct elements of a multiset. [math.setIntersect(set1, set2)](functions/setIntersect.html) | Create the intersection of two (multi)sets. [math.setIsSubset(set1, set2)](functions/setIsSubset.html) | Check whether a (multi)set is a subset of another (multi)set. [math.setMultiplicity(element, set)](functions/setMultiplicity.html) | Count the multiplicity of an element in a multiset. [math.setPowerset(set)](functions/setPowerset.html) | Create the powerset of a (multi)set. [math.setSize(set)](functions/setSize.html) | Count the number of elements of a (multi)set. [math.setSymDifference(set1, set2)](functions/setSymDifference.html) | Create the symmetric difference of two (multi)sets. [math.setUnion(set1, set2)](functions/setUnion.html) | Create the union of two (multi)sets.

Special functions #

Function | Description ---- | ----------- [math.erf(x)](functions/erf.html) | Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x.

Statistics functions #

Function | Description ---- | ----------- [math.mad(a, b, c, ...)](functions/mad.html) | Compute the median absolute deviation of a matrix or a list with values. [math.max(a, b, c, ...)](functions/max.html) | Compute the maximum value of a matrix or a list with values. [math.mean(a, b, c, ...)](functions/mean.html) | Compute the mean value of matrix or a list with values. [math.median(a, b, c, ...)](functions/median.html) | Compute the median of a matrix or a list with values. [math.min(a, b, c, ...)](functions/min.html) | Compute the maximum value of a matrix or a list of values. [math.mode(a, b, c, ...)](functions/mode.html) | Computes the mode of a set of numbers or a list with values(numbers or characters). [math.prod(a, b, c, ...)](functions/prod.html) | Compute the product of a matrix or a list with values. [math.quantileSeq(A, prob[, sorted])](functions/quantileSeq.html) | Compute the prob order quantile of a matrix or a list with values. [math.std(a, b, c, ...)](functions/std.html) | Compute the standard deviation of a matrix or a list with values. [math.sum(a, b, c, ...)](functions/sum.html) | Compute the sum of a matrix or a list with values. [math.var(a, b, c, ...)](functions/var.html) | Compute the variance of a matrix or a list with values.

String functions #

Function | Description ---- | ----------- [math.format(value [, precision])](functions/format.html) | Format a value of any type into a string. [math.print(template, values [, precision])](functions/print.html) | Interpolate values into a string template.

Trigonometry functions #

Function | Description ---- | ----------- [math.acos(x)](functions/acos.html) | Calculate the inverse cosine of a value. [math.acosh(x)](functions/acosh.html) | Calculate the hyperbolic arccos of a value, defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`. [math.acot(x)](functions/acot.html) | Calculate the inverse cotangent of a value, defined as `acot(x) = atan(1/x)`. [math.acoth(x)](functions/acoth.html) | Calculate the hyperbolic arccotangent of a value, defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`. [math.acsc(x)](functions/acsc.html) | Calculate the inverse cosecant of a value, defined as `acsc(x) = asin(1/x)`. [math.acsch(x)](functions/acsch.html) | Calculate the hyperbolic arccosecant of a value, defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`. [math.asec(x)](functions/asec.html) | Calculate the inverse secant of a value. [math.asech(x)](functions/asech.html) | Calculate the hyperbolic arcsecant of a value, defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`. [math.asin(x)](functions/asin.html) | Calculate the inverse sine of a value. [math.asinh(x)](functions/asinh.html) | Calculate the hyperbolic arcsine of a value, defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`. [math.atan(x)](functions/atan.html) | Calculate the inverse tangent of a value. [math.atan2(y, x)](functions/atan2.html) | Calculate the inverse tangent function with two arguments, y/x. [math.atanh(x)](functions/atanh.html) | Calculate the hyperbolic arctangent of a value, defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`. [math.cos(x)](functions/cos.html) | Calculate the cosine of a value. [math.cosh(x)](functions/cosh.html) | Calculate the hyperbolic cosine of a value, defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`. [math.cot(x)](functions/cot.html) | Calculate the cotangent of a value. [math.coth(x)](functions/coth.html) | Calculate the hyperbolic cotangent of a value, defined as `coth(x) = 1 / tanh(x)`. [math.csc(x)](functions/csc.html) | Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`. [math.csch(x)](functions/csch.html) | Calculate the hyperbolic cosecant of a value, defined as `csch(x) = 1 / sinh(x)`. [math.sec(x)](functions/sec.html) | Calculate the secant of a value, defined as `sec(x) = 1/cos(x)`. [math.sech(x)](functions/sech.html) | Calculate the hyperbolic secant of a value, defined as `sech(x) = 1 / cosh(x)`. [math.sin(x)](functions/sin.html) | Calculate the sine of a value. [math.sinh(x)](functions/sinh.html) | Calculate the hyperbolic sine of a value, defined as `sinh(x) = 1/2 * (exp(x) - exp(-x))`. [math.tan(x)](functions/tan.html) | Calculate the tangent of a value. [math.tanh(x)](functions/tanh.html) | Calculate the hyperbolic tangent of a value, defined as `tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1)`.

Unit functions #

Function | Description ---- | ----------- [math.to(x, unit)](functions/to.html) | Change the unit of a value.

Utils functions #

Function | Description ---- | ----------- [math.clone(x)](functions/clone.html) | Clone an object. [math.isInteger(x)](functions/isInteger.html) | Test whether a value is an integer number. [math.isNaN(x)](functions/isNaN.html) | Test whether a value is NaN (not a number). [math.isNegative(x)](functions/isNegative.html) | Test whether a value is negative: smaller than zero. [math.isNumeric(x)](functions/isNumeric.html) | Test whether a value is an numeric value. [math.isPositive(x)](functions/isPositive.html) | Test whether a value is positive: larger than zero. [math.isPrime(x)](functions/isPrime.html) | Test whether a value is prime: has no divisors other than itself and one. [math.isZero(x)](functions/isZero.html) | Test whether a value is zero. [math.typeof(x)](functions/typeof.html) | Determine the type of a variable.