Supported functions of .math()
Construction functions
| Function | Description |
|---|---|
| bignumber(x) | Create a BigNumber, which can store numbers with arbitrary precision. |
| boolean(x) | Create a boolean or convert a string or number to a boolean. |
| chain(value) | Wrap any value in a chain, allowing to perform chained operations on the value. |
| complex(re, im) | Create a complex value or convert a value to a complex value. |
| createUnit(units) | Create a user-defined unit and register it with the Unit type. |
| fraction(numerator, denominator) | Create a fraction convert a value to a fraction. |
| matrix(x) | Create a Matrix. |
| number(value) | Create a number or convert a string, boolean, or unit to a number. |
| sparse(x) | Create a Sparse Matrix. |
| splitUnit(unit, parts) | Returns an array of units whose sum is equal to this unit. |
| string(value) | Create a string or convert any object into a string. |
| unit(x) | Create a unit. |
Algebra functions
| Function | Description |
|---|---|
| lsolve(L, b) | Solves the linear equation system by forwards substitution. |
| lup(A) | Calculate the Matrix LU decomposition with partial pivoting. |
| lusolve(A, b) | Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector. |
| slu(A, order, threshold) | Calculate the Sparse Matrix LU decomposition with full pivoting. |
| usolve(U, b) | Solves the linear equation system by backward substitution. |
Arithmetic functions
| Function | Description |
|---|---|
| abs(x) | Calculate the absolute value of a number. |
| add(x, y) | Add two values, x + y. |
| cbrt(x [, allRoots]) | Calculate the cubic root of a value. |
| ceil(x) | Round a value towards plus infinity If x is complex, both real and imaginary part are rounded towards plus infinity. |
| cube(x) | Compute the cube of a value, x * x * x. |
| divide(x, y) | Divide two values, x / y. |
| dotDivide(x, y) | Divide two matrices element wise. |
| dotMultiply(x, y) | Multiply two matrices element wise. |
| dotPow(x, y) | Calculates the power of x to y element wise. |
| exp(x) | Calculate the exponent of a value. |
| fix(x) | Round a value towards zero. |
| floor(x) | Round a value towards minus infinity. |
| gcd(a, b) | Calculate the greatest common divisor for two or more values or arrays. |
| hypot(a, b, ...) | Calculate the hypotenusa of a list with values. |
| lcm(a, b) | Calculate the least common multiple for two or more values or arrays. |
| log(x [, base]) | Calculate the logarithm of a value. |
| log10(x) | Calculate the 10-base logarithm of a value. |
| mod(x, y) | Calculates the modulus, the remainder of an integer division. |
| multiply(x, y) | Multiply two values, x * y. |
| norm(x [, p]) | Calculate the norm of a number, vector or matrix. |
| nthRoot(a) | Calculate the nth root of a value. |
| pow(x, y) | Calculates the power of x to y, x ^ y. |
| round(x [, n]) | Round a value towards the nearest integer. |
| sign(x) | Compute the sign of a value. |
| sqrt(x) | Calculate the square root of a value. |
| square(x) | Compute the square of a value, x * x. |
| subtract(x, y) | Subtract two values, x - y. |
| unaryMinus(x) | Inverse the sign of a value, apply a unary minus operation. |
| unaryPlus(x) | Unary plus operation. |
| xgcd(a, b) | Calculate the extended greatest common divisor for two values. |
Bitwise functions
| Function | Description |
|---|---|
| bitAnd(x, y) | Bitwise AND two values, x & y. |
| bitNot(x) | Bitwise NOT value, ~x. |
| bitOr(x, y) | Bitwise OR two values, x | y. |
| bitXor(x, y) | Bitwise XOR two values, x ^ y. |
| leftShift(x, y) | Bitwise left logical shift of a value x by y number of bits, x << y. |
| rightArithShift(x, y) | Bitwise right arithmetic shift of a value x by y number of bits, x >> y. |
| rightLogShift(x, y) | Bitwise right logical shift of value x by y number of bits, x >>> y. |
Combinatorics functions
| Function | Description |
|---|---|
| bellNumbers(n) | The Bell Numbers count the number of partitions of a set. |
| catalan(n) | The Catalan Numbers enumerate combinatorial structures of many different types. |
| composition(n, k) | The composition counts of n into k parts. |
| stirlingS2(n, k) | 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 |
|---|---|
| arg(x) | Compute the argument of a complex value. |
| conj(x) | Compute the complex conjugate of a complex value. |
| im(x) | Get the imaginary part of a complex number. |
| re(x) | Get the real part of a complex number. |
Geometry functions
| Function | Description |
|---|---|
| [distance([x1, y1], [x2, y2])](functions/distance.md) | Calculates: The eucledian distance between two points in 2 and 3 dimensional spaces. |
| intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2) | 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 |
|---|---|
| and(x, y) | Logical and. |
| not(x) | Logical not. |
| or(x, y) | Logical or. |
| xor(x, y) | Logical xor. |
Matrix functions
| Function | Description |
|---|---|
| concat(a, b, c, ... [, dim]) | Concatenate two or more matrices. |
| cross(x, y) | Calculate the cross product for two vectors in three dimensional space. |
| det(x) | Calculate the determinant of a matrix. |
| diag(X) | 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. |
| dot(x, y) | Calculate the dot product of two vectors. |
| eye(n) | Create a 2-dimensional identity matrix with size m x n or n x n. |
| filter(x, test) | Filter the items in an array or one dimensional matrix. |
| flatten(x) | Flatten a multi dimensional matrix into a single dimensional matrix. |
| inv(x) | Calculate the inverse of a square matrix. |
| ones(m, n, p, ...) | Create a matrix filled with ones. |
| partitionSelect(x, k) | Partition-based selection of an array or 1D matrix. |
| range(start, end [, step]) | Create an array from a range. |
| resize(x, size [, defaultValue]) | Resize a matrix. |
| size(x) | Calculate the size of a matrix or scalar. |
| sort(x) | Sort the items in a matrix. |
| squeeze(x) | Squeeze a matrix, remove inner and outer singleton dimensions from a matrix. |
| subset(x, index [, replacement]) | Get or set a subset of a matrix or string. |
| trace(x) | Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix. |
| transpose(x) | Transpose a matrix. |
| zeros(m, n, p, ...) | Create a matrix filled with zeros. |
Probability functions
| Function | Description |
|---|---|
| combinations(n, k) | Compute the number of ways of picking k unordered outcomes from n possibilities. |
| factorial(n) | Compute the factorial of a value Factorial only supports an integer value as argument. |
| gamma(n) | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values. |
| kldivergence(x, y) | Calculate the Kullback-Leibler (KL) divergence between two distributions. |
| multinomial(a) | Multinomial Coefficients compute the number of ways of picking a1, a2, . |
| permutations(n [, k]) | Compute the number of ways of obtaining an ordered subset of k elements from a set of n elements. |
| pickRandom(array) | Random pick a value from a one dimensional array. |
| random([min, max]) | Return a random number larger or equal to min and smaller than max using a uniform distribution. |
| randomInt([min, max]) | Return a random integer number larger or equal to min and smaller than max using a uniform distribution. |
Relational functions
| Function | Description |
|---|---|
| compare(x, y) | Compare two values. |
| deepEqual(x, y) | Test element wise whether two matrices are equal. |
| equal(x, y) | Test whether two values are equal. |
| larger(x, y) | Test whether value x is larger than y. |
| largerEq(x, y) | Test whether value x is larger or equal to y. |
| smaller(x, y) | Test whether value x is smaller than y. |
| smallerEq(x, y) | Test whether value x is smaller or equal to y. |
| unequal(x, y) | Test whether two values are unequal. |
Statistics functions
| Function | Description |
|---|---|
| max(a, b, c, ...) | Compute the maximum value of a matrix or a list with values. |
| mean(a, b, c, ...) | Compute the mean value of matrix or a list with values. |
| median(a, b, c, ...) | Compute the median of a matrix or a list with values. |
| min(a, b, c, ...) | Compute the maximum value of a matrix or a list of values. |
| mode(a, b, c, ...) | Computes the mode of a set of numbers or a list with values(numbers or characters). |
| prod(a, b, c, ...) | Compute the product of a matrix or a list with values. |
| quantileSeq(A, prob[, sorted]) | Compute the prob order quantile of a matrix or a list with values. |
| std(a, b, c, ...) | Compute the standard deviation of a matrix or a list with values. |
| sum(a, b, c, ...) | Compute the sum of a matrix or a list with values. |
| var(a, b, c, ...) | Compute the variance of a matrix or a list with values. |
Trigonometry functions
| Function | Description |
|---|---|
| acos(x) | Calculate the inverse cosine of a value. |
| acosh(x) | Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x). |
| acot(x) | Calculate the inverse cotangent of a value, defined as acot(x) = atan(1/x). |
| acoth(x) | Calculate the hyperbolic arccotangent of a value, defined as acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2. |
| acsc(x) | Calculate the inverse cosecant of a value, defined as acsc(x) = asin(1/x). |
| acsch(x) | Calculate the hyperbolic arccosecant of a value, defined as acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1)). |
| asec(x) | Calculate the inverse secant of a value. |
| asech(x) | Calculate the hyperbolic arcsecant of a value, defined as asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x). |
| asin(x) | Calculate the inverse sine of a value. |
| asinh(x) | Calculate the hyperbolic arcsine of a value, defined as asinh(x) = ln(x + sqrt(x^2 + 1)). |
| atan(x) | Calculate the inverse tangent of a value. |
| atan2(y, x) | Calculate the inverse tangent function with two arguments, y/x. |
| atanh(x) | Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2. |
| cos(x) | Calculate the cosine of a value. |
| cosh(x) | Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 * (exp(x) + exp(-x)). |
| cot(x) | Calculate the cotangent of a value. |
| coth(x) | Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x). |
| csc(x) | Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). |
| csch(x) | Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x). |
| sec(x) | Calculate the secant of a value, defined as sec(x) = 1/cos(x). |
| sech(x) | Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x). |
| sin(x) | Calculate the sine of a value. |
| sinh(x) | Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * (exp(x) - exp(-x)). |
| tan(x) | Calculate the tangent of a value. |
| tanh(x) | Calculate the hyperbolic tangent of a value, defined as tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1). |
Unit functions
| Function | Description |
|---|---|
| to(x, unit) | Change the unit of a value. |
Utils functions
| Function | Description |
|---|---|
| isInteger(x) | Test whether a value is an integer number. |
| isNaN(x) | Test whether a value is NaN (not a number). |
| isNegative(x) | Test whether a value is negative: smaller than zero. |
| isNumeric(x) | Test whether a value is an numeric value. |
| isPositive(x) | Test whether a value is positive: larger than zero. |
| isPrime(x) | Test whether a value is prime: has no divisors other than itself and one. |
| isZero(x) | Test whether a value is zero. |