Open
Description
Math.js Function Reference
We should support all functions from Math.js to aid user migration.
For reference: https://mathjs.org/docs/reference/functions.html
Expression Functions
-
math.compile(expr)
- Parse and compile an expression for repeated evaluation -
math.evaluate(expr [, scope])
- Evaluate an expression with optional variable scope -
math.help(search)
- Get help documentation for functions or data types -
math.parser()
- Create an expression parser with a variable scope
Algebra Functions
-
math.derivative(expr, variable)
- Calculate symbolic derivative of expression -
math.leafCount(expr)
- Count leaf nodes in an expression parse tree -
math.lsolve(L, b)
- Solve linear system with forward substitution -
math.lsolveAll(L, b)
- Find all solutions using forward substitution -
math.lup(A)
- Calculate LU decomposition with partial pivoting -
math.lusolve(A, b)
- Solve linear system using LU decomposition -
math.lyap(A, Q)
- Solve Continuous-time Lyapunov equation -
math.polynomialRoot(...)
- Find roots of polynomial equations -
math.qr(A)
- Calculate QR decomposition of matrix -
math.rationalize(expr)
- Convert expression to rational fraction form -
math.resolve(expr, scope)
- Replace variable nodes with their values -
math.schur(A)
- Perform real Schur decomposition -
math.simplify(expr)
- Simplify an expression tree -
math.simplifyConstant(expr)
- Replace constant subexpressions with computed values -
math.simplifyCore(expr)
- Perform single-pass simplification for performance -
math.slu(A, order, threshold)
- Calculate sparse matrix LU decomposition -
math.sylvester(A, B, C)
- Solve Sylvester equation AX+XB=C -
math.symbolicEqual(expr1, expr2)
- Check if expressions are symbolically equal -
math.usolve(U, b)
- Solve using backward substitution -
math.usolveAll(U, b)
- Find all solutions using backward substitution
Arithmetic Functions
-
math.abs(x)
- Calculate absolute value -
math.add(x, y)
- Add two or more values -
math.cbrt(x [, allRoots])
- Calculate cubic root -
math.ceil(x)
- Round toward positive infinity -
math.cube(x)
- Compute x³ -
math.divide(x, y)
- Division operation -
math.dotDivide(x, y)
- Element-wise division of matrices -
math.dotMultiply(x, y)
- Element-wise multiplication of matrices -
math.dotPow(x, y)
- Element-wise power operation -
math.exp(x)
- Calculate e^x -
math.expm1(x)
- Calculate e^x-1 with higher precision for small x -
math.fix(x)
- Round toward zero -
math.floor(x)
- Round toward negative infinity -
math.gcd(a, b)
- Greatest common divisor -
math.hypot(a, b, …)
- Calculate hypotenuse length -
math.invmod(a, b)
- Calculate modular multiplicative inverse -
math.lcm(a, b)
- Least common multiple -
math.log(x [, base])
- Logarithm with optional base -
math.log10(x)
- Base-10 logarithm -
math.log1p(x)
- Calculate ln(1+x) with higher precision -
math.log2(x)
- Base-2 logarithm -
math.mod(x, y)
- Modulus operation (remainder) -
math.multiply(x, y)
- Multiplication operation -
math.norm(x [, p])
- Calculate vector/matrix norm -
math.nthRoot(a)
- Calculate nth root -
math.nthRoots(x)
- Calculate all nth roots -
math.pow(x, y)
- Power operation x^y -
math.round(x [, n])
- Round to nearest integer or decimal place -
math.sign(x)
- Get sign of value (-1, 0, or 1) -
math.sqrt(x)
- Square root -
math.square(x)
- Calculate x² -
math.subtract(x, y)
- Subtraction operation -
math.unaryMinus(x)
- Negate a value -
math.unaryPlus(x)
- Convert to number -
math.xgcd(a, b)
- Extended greatest common divisor
Bitwise Functions
-
math.bitAnd(x, y)
- Bitwise AND operation -
math.bitNot(x)
- Bitwise NOT operation -
math.bitOr(x, y)
- Bitwise OR operation -
math.bitXor(x, y)
- Bitwise XOR operation -
math.leftShift(x, y)
- Left shift bits -
math.rightArithShift(x, y)
- Right arithmetic shift (sign-preserving) -
math.rightLogShift(x, y)
- Right logical shift (zero-fill)
Combinatorics Functions
-
math.bellNumbers(n)
- Calculate Bell numbers (count of partitions) -
math.catalan(n)
- Calculate Catalan numbers -
math.composition(n, k)
- Count compositions of n into k parts -
math.stirlingS2(n, k)
- Calculate Stirling numbers of second kind
Complex Functions
-
math.arg(x)
- Get argument (phase) of complex number -
math.conj(x)
- Complex conjugate -
math.im(x)
- Get imaginary part -
math.re(x)
- Get real part
Geometry Functions
-
math.distance([x1,y1], [x2,y2])
- Calculate Euclidean distance -
math.intersect(...)
- Find intersection point of lines or line and plane
Logical Functions
-
math.and(x, y)
- Logical AND -
math.not(x)
- Logical NOT -
math.or(x, y)
- Logical OR -
math.xor(x, y)
- Logical XOR
Matrix Functions
-
math.column(value, index)
- Extract column from matrix -
math.concat(a, b, c, … [, dim])
- Concatenate matrices along dimension -
math.count(x)
- Count elements in array or matrix -
math.cross(x, y)
- Calculate cross product of vectors -
math.ctranspose(x)
- Complex conjugate transpose -
math.det(x)
- Calculate matrix determinant -
math.diag(X)
- Create diagonal matrix or extract diagonal -
math.diff(arr)
- Calculate differences between array elements -
math.dot(x, y)
- Calculate dot product of vectors -
math.eigs(x, [prec])
- Compute eigenvalues and eigenvectors -
math.expm(x)
- Matrix exponential -
math.fft(arr)
- Fast Fourier Transform -
math.filter(x, test)
- Filter array elements -
math.flatten(x)
- Flatten multi-dimensional array -
math.forEach(x, callback)
- Iterate through all elements -
math.getMatrixDataType(x)
- Get data type of matrix elements -
math.identity(n)
- Create identity matrix -
math.ifft(arr)
- Inverse Fast Fourier Transform -
math.inv(x)
- Matrix inverse -
math.kron(x, y)
- Kronecker product of matrices -
math.map(x, callback)
- Apply function to each element -
math.mapSlices(A, dim, callback)
- Apply function to slices -
math.matrixFromColumns(…arr)
- Create matrix from column vectors -
math.matrixFromFunction(size, fn)
- Create matrix using generator function -
math.matrixFromRows(…arr)
- Create matrix from row vectors -
math.ones(m, n, p, …)
- Create matrix filled with ones -
math.partitionSelect(x, k)
- Select kth smallest element -
math.pinv(x)
- Moore–Penrose pseudoinverse -
math.range(start, end [, step])
- Create array with range of values -
math.reshape(x, sizes)
- Reshape array to new dimensions -
math.resize(x, size [, defaultValue])
- Resize array with padding -
math.rotate(w, theta)
- Rotate vector by angle -
math.rotationMatrix(theta)
- Create 2D rotation matrix -
math.row(value, index)
- Extract row from matrix -
math.size(x)
- Get dimensions of matrix -
math.sort(x)
- Sort array elements -
math.sqrtm(A)
- Matrix square root -
math.squeeze(x)
- Remove singleton dimensions -
math.subset(x, index [, replacement])
- Get or set matrix subset -
math.trace(x)
- Sum of diagonal elements -
math.transpose(x)
- Matrix transpose -
math.zeros(m, n, p, …)
- Create matrix filled with zeros
Numeric Functions
-
math.solveODE(func, tspan, y0)
- Solve ordinary differential equations
Probability Functions
-
math.combinations(n, k)
- Number of ways to choose k items from n -
math.combinationsWithRep(n, k)
- Combinations with repetition allowed -
math.factorial(n)
- Calculate n! -
math.gamma(n)
- Gamma function (generalized factorial) -
math.kldivergence(x, y)
- Kullback-Leibler divergence between distributions -
math.lgamma(n)
- Natural logarithm of gamma function -
math.multinomial(a)
- Multinomial coefficient -
math.permutations(n [, k])
- Number of permutations -
math.pickRandom(array)
- Random sampling from array -
math.random([min, max])
- Generate random number -
math.randomInt([min, max])
- Generate random integer
Relational Functions
-
math.compare(x, y)
- Compare values (-1, 0, or 1) -
math.compareNatural(x, y)
- Compare values naturally -
math.compareText(x, y)
- Compare strings lexically -
math.deepEqual(x, y)
- Test if matrices are elementwise equal -
math.equal(x, y)
- Test if values are equal -
math.equalText(x, y)
- Test if strings are equal -
math.larger(x, y)
- Test if x > y -
math.largerEq(x, y)
- Test if x ≥ y -
math.smaller(x, y)
- Test if x < y -
math.smallerEq(x, y)
- Test if x ≤ y -
math.unequal(x, y)
- Test if values are not equal
Set Functions
-
math.setCartesian(set1, set2)
- Calculate Cartesian product -
math.setDifference(set1, set2)
- Set difference (set1 - set2) -
math.setDistinct(set)
- Create set with distinct elements -
math.setIntersect(set1, set2)
- Set intersection -
math.setIsSubset(set1, set2)
- Test if set1 is subset of set2 -
math.setMultiplicity(element, set)
- Count occurrences in multiset -
math.setPowerset(set)
- Generate all possible subsets -
math.setSize(set)
- Count elements in set -
math.setSymDifference(set1, set2)
- Symmetric difference of sets -
math.setUnion(set1, set2)
- Set union
Signal Functions
-
math.freqz(b, a)
- Calculate frequency response of filter -
math.zpk2tf(z, p, k)
- Convert zero-pole-gain model to transfer function
Special Functions
-
math.erf(x)
- Error function -
math.zeta(n)
- Riemann Zeta function
Statistics Functions
-
math.corr(A, B)
- Correlation coefficient -
math.cumsum(a, b, c, …)
- Cumulative sum -
math.mad(a, b, c, …)
- Median absolute deviation -
math.max(a, b, c, …)
- Maximum value -
math.mean(a, b, c, …)
- Average value -
math.median(a, b, c, …)
- Median value -
math.min(a, b, c, …)
- Minimum value -
math.mode(a, b, c, …)
- Most frequent value -
math.prod(a, b, c, …)
- Product of values -
math.quantileSeq(A, prob[, sorted])
- Calculate quantile -
math.std(a, b, c, …)
- Standard deviation -
math.sum(a, b, c, …)
- Sum of values -
math.variance(a, b, c, …)
- Variance
String Functions
-
math.bin(value)
- Format number as binary string -
math.format(value [, precision])
- Format value as string -
math.hex(value)
- Format number as hexadecimal -
math.oct(value)
- Format number as octal -
math.print(template, values [, precision])
- Format string with values
Trigonometry Functions
-
math.acos(x)
- Inverse cosine -
math.acosh(x)
- Hyperbolic inverse cosine -
math.acot(x)
- Inverse cotangent -
math.acoth(x)
- Hyperbolic inverse cotangent -
math.acsc(x)
- Inverse cosecant -
math.acsch(x)
- Hyperbolic inverse cosecant -
math.asec(x)
- Inverse secant -
math.asech(x)
- Hyperbolic inverse secant -
math.asin(x)
- Inverse sine -
math.asinh(x)
- Hyperbolic inverse sine -
math.atan(x)
- Inverse tangent -
math.atan2(y, x)
- Two-argument inverse tangent -
math.atanh(x)
- Hyperbolic inverse tangent -
math.cos(x)
- Cosine -
math.cosh(x)
- Hyperbolic cosine -
math.cot(x)
- Cotangent -
math.coth(x)
- Hyperbolic cotangent -
math.csc(x)
- Cosecant -
math.csch(x)
- Hyperbolic cosecant -
math.sec(x)
- Secant -
math.sech(x)
- Hyperbolic secant -
math.sin(x)
- Sine -
math.sinh(x)
- Hyperbolic sine -
math.tan(x)
- Tangent -
math.tanh(x)
- Hyperbolic tangent
Unit Functions
-
math.to(x, unit)
- Convert value to different unit
Utils Functions
-
math.clone(x)
- Create deep copy of value -
math.hasNumericValue(x)
- Check if value is numeric -
math.isInteger(x)
- Check if value is integer -
math.isNaN(x)
- Check if value is NaN -
math.isNegative(x)
- Check if value is negative -
math.isNumeric(x)
- Check if value is numeric -
math.isPositive(x)
- Check if value is positive -
math.isPrime(x)
- Check if value is prime number -
math.isZero(x)
- Check if value is zero -
math.numeric(x)
- Convert to specific numeric type -
math.typeOf(x)
- Get type of value