Algebra Functions (92)

Symbolic algebra, CAS operations, polynomial manipulation, equation solving, simplification

apart
Perform partial fraction decomposition on a rational expression. Decomposes p(x)/q(x) into a sum of simpler fractions when the denominator factors into distinct linear terms.
Syntax
apart(expr | variable) | apart(expr
Type Signatures
Node, string, string, string
Parameters
NameTypeDescription
exprNode|stringThe rational expression to decompose
variablestringThe variable name
Returns
string — Partial fraction decomposition as a string
Examples
apart("1 / (x^2 - 1)
x")
apart("(x + 1) / (x^2 - 1)
x")
assume
Declare an assumption about a symbolic variable. Valid properties: positive, negative, integer, real, complex, nonnegative, nonzero. Assumptions are stored globally and can be used by reduce().
Syntax
assume(variable | property)
Type Signatures
string, string
Parameters
NameTypeDescription
variablestring
Returns
string|undefined —
Examples
assume("x
positive")
assume("n
integer")
assume("z
asymptotic
Find the asymptotic (leading) behavior of an expression as a variable approaches a point. For rational functions, returns the leading term ratio. For polynomials, returns the leading monomial. For other expressions, falls back to computing the limit.
Syntax
asymptotic(expr | variable | point)
Type Signatures
string | Node, string, number
Parameters
NameTypeDescription
exprstring | NodeThe expression
variablestringThe variable name
pointnumberThe point to approach (use Infinity for infinity)
Returns
string | number — The leading behavior as a string or number
Examples
asymptotic("3*x^4 + 2*x^2 + 1
x
Infinity)
asymptotic("x + 1
x
cancel
Cancel common factors in a rational expression. Simplifies a fraction by cancelling common factors between the numerator and denominator.
Syntax
cancel(expr)
Parameters
NameTypeDescription
exprNode|stringThe rational expression to cancel
Returns
string — The cancelled expression as a string
Examples
cancel("(x^2 - 1) / (x - 1)")
cancel("(2*x^2 + 2*x) / (2*x)")
cancel("(x^3 - x) / x")
coefficientList
Extract polynomial coefficients of an expression with respect to a variable. Returns an array [c0, c1, c2, ...] where expr = c0 + c1*x + c2*x^2 + ...
Syntax
coefficientList(expr | variable) | coefficientList(expr
Type Signatures
Node, string, string, string
Parameters
NameTypeDescription
exprNode|stringThe polynomial expression
variablestringThe variable name
Returns
Array — Array of coefficients [c0, c1, ..., cn]
Examples
coefficientList("3*x^2 + 2*x + 1
x")
coefficientList("x^3 - x
x")
collect
Collect terms of a polynomial expression by powers of a variable. Groups like powers and combines their coefficients.
Syntax
collect(expr | variable)
Type Signatures
Node, string, string, string
Parameters
NameTypeDescription
exprNode|stringThe expression to collect
variablestringThe variable to collect by
Returns
string — The collected expression as a string
Examples
collect("3*x + 2*x^2 + x + 5
x")
collect("x^2 + x^2
x")
collect("2*x + x
See Also
simplify expand
combine
Combine like terms and apply logarithm/power product rules. Inverse of expand for patterns like log(a)+log(b)->log(a*b), a^n*a^m->a^(n+m).
Syntax
combine(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to combine
Returns
Node|string — The combined expression (same type as input)
Examples
combine("log(a) + log(b)")
combine("log(a) - log(b)")
combine("x^2 * x^3")
combine("2 * log(x)")
complexExpand
Expand an expression treating the listed variables as complex numbers. Substitutes each variable x with x_re + i*x_im, expands, and separates into real and imaginary parts.
Syntax
complexExpand(expr | variables)
Type Signatures
string, Array, Node, Array
Parameters
NameTypeDescription
exprNode|stringThe expression to expand
variablesstring[]List of variable names to treat as complex
Returns
Object — Object with 're' and 'im' string properties
Examples
complexExpand("z^2
["z
See Also
expand simplify
csAmd
Approximate minimum degree ordering. The minimum degree algorithm is a widely used heuristic for finding a permutation P so that P*A*P' has fewer nonzeros in its factorization than A. It is a gready method that selects the sparsest pivot row and column during the course of a right looking sparse Cho
Parameters
NameTypeDescription
orderNumber0: Natural, 1: Cholesky, 2: LU, 3: QR
mMatrixSparse Matrix
csChol
Computes the Cholesky factorization of matrix A. It computes L and P so L * L' = P * A * P'
Parameters
NameTypeDescription
mMatrixThe A Matrix to factorize, only upper triangular part used
sObjectThe symbolic analysis from cs_schol()
Returns
Number — The numeric Cholesky factorization of A or null
csCounts
Computes the column counts using the upper triangular part of A. It transposes A internally, none of the input parameters are modified.
Parameters
NameTypeDescription
aMatrixThe sparse matrix A
ataMatrixCount the columns of A'A instead
csLu
Computes the numeric LU factorization of the sparse matrix A. Implements a Left-looking LU factorization algorithm that computes L and U one column at a tume. At the kth step, it access columns 1 to k-1 of L and column k of A. Given the fill-reducing column ordering q (see parameter s) computes L, U
Parameters
NameTypeDescription
mMatrixThe A Matrix to factorize
sObjectThe symbolic analysis from csSqr(). Provides the fill-reducing
tolNumberPartial pivoting threshold (1 for partial pivoting)
Returns
Number — The numeric LU factorization of A or null
csSpsolve
The function csSpsolve() computes the solution to G * x = bk, where bk is the kth column of B. When lo is true, the function assumes G = L is lower triangular with the diagonal entry as the first entry in each column. When lo is true, the function assumes G = U is upper triangular with the diagonal
Parameters
NameTypeDescription
gMatrixThe G matrix
bMatrixThe B matrix
kNumberThe kth column in B
xiArrayThe nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
xArrayThe soluton to the linear system G * x = b
pinvArrayThe inverse row permutation vector, must be null for L * x = b
lobooleanThe lower (true) upper triangular (false) flag
Returns
Number — The index for the nonzero pattern
csSqr
Symbolic ordering and analysis for QR and LU decompositions. symbolic ordering and analysis for LU decomposition (false)
Parameters
NameTypeDescription
orderNumberThe ordering strategy (see csAmd for more details)
aMatrixThe A matrix
qrbooleanSymbolic ordering and analysis for QR decomposition (true) or
Returns
Object — The Symbolic ordering and analysis for matrix A
csSymperm
Computes the symmetric permutation of matrix A accessing only the upper triangular part of A. C = P * A * P'
Parameters
NameTypeDescription
aMatrixThe A matrix
pinvArrayThe inverse of permutation vector
valuesbooleanProcess matrix values (true)
Returns
Matrix — The C matrix, C = P * A * P'
curl
Compute the symbolic curl of a 3D vector field. The curl is defined as [dF3/dy - dF2/dz, dF1/dz - dF3/dx, dF2/dx - dF1/dy]. Both field and variables must have exactly 3 elements.
Syntax
curl(field | variables)
Type Signatures
Array, Array
Parameters
NameTypeDescription
fieldArray.<string | Node>Array of 3 component expressions [F1, F2, F3]
variablesArray.<string>Array of 3 variable names [x, y, z]
Returns
Array.<string> — The curl as an array of 3 strings
degree
Find the degree of a polynomial expression in a specified variable. Walks the expression tree to find the highest power of the given variable. Returns 0 for constant expressions and -Infinity for non-polynomial expressions.
Syntax
degree(polynomial | variable)
Type Signatures
string | Node, string
Parameters
NameTypeDescription
polynomialstring | NodeThe polynomial expression
variablestringThe variable name
Returns
number — The degree (highest power) of the variable
Examples
degree("3*x^5 + 2*x^3 + 1
x")
degree("x^2 + x + 1
x")
degree("7
derivative
Takes the derivative of an expression expressed in parser Nodes. The derivative will be taken over the supplied variable in the second parameter. If there are multiple variables in the expression, it will return a partial derivative.
Syntax
derivative(expr | variable) | derivative(expr
Type Signatures
Node, SymbolNode, ConstantNode, Node, SymbolNode, Node, ConstantNode, Node, SymbolNode, ConstantNode, string, string, number, function, ConstantNode, string
Parameters
NameTypeDescription
exprNode | stringThe expression to differentiate
variableSymbolNode | stringThe variable over which to differentiate
Returns
ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode — The derivative of `expr`
Examples
derivative("2x^3
x")
derivative("2x^3
x
{simplify: false})
differences
Compute finite differences of a numeric sequence. First differences give the discrete analog of the derivative: Δa[i] = a[i+1] - a[i]. Higher-order differences are computed by applying the operator repeatedly.
Syntax
differences(sequence) | differences(sequence | order)
Type Signatures
Array, number
Parameters
NameTypeDescription
sequenceArray.<number>The input sequence (array of numbers)
Returns
Array.<number> — The finite differences
Examples
differences([1
4
9
16
25
directionalDerivative
Compute the directional derivative of a scalar expression in the given direction. D_v f = gradient(f) · (v / |v|). The direction vector is normalized before computing the dot product with the gradient.
Syntax
directionalDerivative(expr | variables | direction)
Type Signatures
string | Node, Array, Array
Parameters
NameTypeDescription
exprstring | NodeThe scalar expression
variablesArray.<string>Array of variable names
directionArray.<number>Direction vector components
Returns
string — The directional derivative as a string
Examples
directionalDerivative("x * y
["x
y
discriminant
Compute the discriminant of a polynomial. For quadratic ax^2+bx+c: disc = b^2-4ac. For cubic: disc = 18abcd-4b^3d+b^2c^2-4ac^3-27a^2d^2. For higher degrees, uses the resultant of p and its derivative.
Syntax
discriminant(polynomial | variable)
Type Signatures
string, string, Node, string
Parameters
NameTypeDescription
polynomialNode|stringThe polynomial expression
variablestringThe variable name
Returns
number — The discriminant value
Examples
discriminant("x^2 + 2*x + 1
x")
discriminant("x^2 - 4
x")
discriminant("x^2 - x - 6
divergence
Compute the symbolic divergence of a vector field. The divergence is the sum of partial derivatives: div F = dF1/dx1 + dF2/dx2 + ... The field and variables arrays must have the same length.
Syntax
divergence(field | variables)
Type Signatures
Array, Array
Parameters
NameTypeDescription
fieldArray.<string | Node>Array of component expressions
variablesArray.<string>Array of variable names (same length as field)
Returns
string — The divergence as a string
element
Assert that a variable belongs to a mathematical domain and record the assumption. Valid domains: Integer, Real, Rational, Complex, Positive, Negative. Returns true when the assumption is stored.
Syntax
element(variable | domain)
Type Signatures
string, string
Parameters
NameTypeDescription
variablestringThe variable name
domainstringThe domain name (case-insensitive)
Returns
boolean — true when the assumption is recorded
Examples
element("x
Integer")
element("y
Real")
element("z
eliminate
Eliminate specified variables from a system of polynomial equations using resultants. For each variable to eliminate, computes resultants between pairs of equations to produce equations in the remaining variables.
Syntax
eliminate(equations | variablesToEliminate)
Type Signatures
Array, Array
Parameters
NameTypeDescription
equationsstring[]Array of polynomial equations/expressions
variablesToEliminatestring[]Variables to eliminate
Returns
string[] — Remaining equations
Examples
eliminate(["x + y - 1
x - y
expToTrig
Convert exponential expressions to trigonometric or hyperbolic form using Euler\
Syntax
expToTrig(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to convert
Returns
Node|string — The converted expression (same type as input)
Examples
expToTrig("exp(i * x)")
expToTrig("(exp(x) + exp(-x)) / 2")
expToTrig("(exp(x) - exp(-x)) / 2")
See Also
trigToExp simplify
expand
Expand an algebraic expression by distributing multiplication over addition and expanding integer powers. Returns the expanded form of the expression.
Syntax
expand(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to expand
Returns
Node|string — The expanded expression (same type as input)
Examples
expand("(x + 1)^2")
expand("(x + 1) * (x - 1)")
expand("2 * (x + y)")
factor
Factor a polynomial expression into its irreducible factors. Uses the rational roots theorem to find rational roots, then performs synthetic division. Handles linear, quadratic, cubic, and higher-degree polynomials with rational roots.
Syntax
factor(expr) | factor(expr | variable)
Type Signatures
string, Node, string, string, Node, string
Parameters
NameTypeDescription
exprstring | NodeThe polynomial to factor
variablestringThe variable (auto-detected if omitted)
Returns
string — The factored expression
Examples
factor("x^2 - 4")
factor("x^2 + 2*x + 1")
factor("x^3 - x")
factor("x^2 - 5*x + 6")
fourierSeries
Compute the Fourier series coefficients of a periodic function using numeric integration (Simpson\
Syntax
fourierSeries(expr | variable | period)
Parameters
NameTypeDescription
exprstring | NodeThe periodic function expression
variablestringThe function variable
periodnumberThe period T
Returns
Object — { a0: number, an: number[], bn: number[] }
Examples
fourierSeries("x
x
2 * pi
3)
fourierSeries("x^2
See Also
evaluate integrate
fullSimplify
Aggressively simplify an expression by applying multiple strategies (basic simplify, trig identities, expand, rationalize) and returning the result with the fewest nodes.
Syntax
fullSimplify(expr) | fullSimplify(expr | options)
Type Signatures
string, Object, Node, Object
Parameters
NameTypeDescription
exprNode|stringThe expression to simplify
optionsObjectOptions passed through to simplify
Returns
Node|string — The simplified expression (same type as input)
Examples
fullSimplify("sin(x)^2 + cos(x)^2")
fullSimplify("(x^2 - 1) / (x - 1)")
fullSimplify("2*x + 3*x")
functionExpand
Expand special function identities: gamma recurrence gamma(n+1)->n*gamma(n), beta(a,b)->gamma(a)*gamma(b)/gamma(a+b), binomial coefficients, and evaluates gamma/factorial at integer arguments.
Syntax
functionExpand(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to expand
Returns
Node|string — The expanded expression (same type as input)
Examples
functionExpand("gamma(n + 1)")
functionExpand("beta(a
b)")
functionExpand("combinations(n
k)")
See Also
simplify
gradientSymbolic
Compute the symbolic gradient of a scalar expression with respect to a list of variables. Returns an array of strings, where each element is the partial derivative with respect to the corresponding variable.
Syntax
gradientSymbolic(expr | variables)
Type Signatures
string | Node, Array
Parameters
NameTypeDescription
exprstring | NodeThe scalar expression
variablesArray.<string>The variable names
Returns
Array.<string> — Array of partial derivative strings
groebnerBasis
Compute a Gröbner basis for a polynomial ideal. Supports 1-variable systems (via GCD) and 2-variable systems (via resultant-based reduction) with lexicographic ordering.
Syntax
groebnerBasis(polynomials | variables)
Type Signatures
Array, Array
Parameters
NameTypeDescription
polynomialsstring[]Array of polynomial strings
variablesstring[]Array of variable names (lex order)
Returns
string[] — Gröbner basis polynomials
Examples
groebnerBasis(["x^2 + y^2 - 1
x - y
implicitDiff
Compute the implicit derivative dy/dx of an equation F(x, y) = 0 using the formula dy/dx = -(dF/dx) / (dF/dy).
Syntax
implicitDiff(expr | y | x)
Type Signatures
string | Node, string, string
Parameters
NameTypeDescription
exprstring | NodeThe expression F(x,y) where F = 0
ystringThe dependent variable name
xstringThe independent variable name
Returns
string — The derivative dy/dx as a string
integrate
Compute the symbolic indefinite integral of an expression with respect to a variable. Handles polynomials (power rule), basic trigonometric functions (sin, cos), exponentials (exp), and 1/x. Uses linearity of integration for sums and constant multiples. Returns the integral without the constant of i
Syntax
integrate(expr | variable)
Type Signatures
Node, string, string, string
Parameters
NameTypeDescription
exprNode | stringThe expression to integrate
variablestringThe variable of integration
Returns
string — The integral (without +C)
Examples
integrate("x^2
x")
integrate("sin(x)
x")
integrate("exp(x)
See Also
derivative simplify
inverseLaplace
Convenience alias for inverseLaplaceTransform. Compute the inverse Laplace transform using a lookup table of known transform pairs. Supported: 1/s → 1, 1/s^2 → t, c/s^n → c*t^(n-1)/(n-1)!, 1/(s-a) → e^(at), s/(s^2+b^2) → cos(bt), b/(s^2+b^2) → sin(bt), and more.
Syntax
inverseLaplace(expr | sVar | tVar)
Parameters
NameTypeDescription
exprstring|NodeExpression in the s-domain
sVarstringThe s-domain variable (e.g. 's')
tVarstringThe time variable (e.g. 't')
Returns
string — Time-domain expression as a string
Examples
inverseLaplace("1/s
s
t")
inverseLaplace("1/s^2
s
inverseLaplaceTransform
Compute the inverse Laplace transform using a lookup table of known transform pairs. Supported patterns include: 1/s → 1, 1/s^2 → t, c/s^n → c*t^(n-1)/(n-1)!, 1/(s-a) → e^(at), s/(s^2+b^2) → cos(bt), b/(s^2+b^2) → sin(bt), s/(s^2-a^2) → cosh(at), a/(s^2-a^2) → sinh(at). Sums are handled term by term
Syntax
inverseLaplaceTransform(expr | sVar | tVar)
Type Signatures
string, string, string, Node, string, string
Parameters
NameTypeDescription
exprstring|NodeExpression in the s-domain
sVarstringName of the s-domain variable (e.g., 's')
tVarstringName of the time variable (e.g., 't')
Returns
string — Time-domain expression as a string
Examples
inverseLaplaceTransform("1/s
s
t")
inverseLaplaceTransform("1/s^2
s
See Also
apart simplify
jacobian
Compute the symbolic Jacobian matrix of a vector of expressions with respect to a list of variables. J[i][j] = d(exprs[i]) / d(variables[j]). Returns a 2D array of strings.
Syntax
jacobian(exprs | variables)
Type Signatures
Array, Array
Parameters
NameTypeDescription
exprsArray.<string | Node>Array of expressions
variablesArray.<string>Array of variable names
Returns
Array.<Array.<string>> — 2D array of partial derivatives
laplace
Compute the Laplace transform of an expression using a table-based approach. Supports: constants (1 -> 1/s), powers (t^n -> n!/s^(n+1)), exponentials (e^(at) -> 1/(s-a)), sine (sin(bt) -> b/(s^2+b^2)), cosine (cos(bt) -> s/(s^2+b^2)), and linearity for sums and scalar multiples.
Syntax
laplace(expr | tVar | sVar)
Type Signatures
string, string, string, Node, string, string
Parameters
NameTypeDescription
exprstring | NodeThe time-domain expression
tVarstringThe time variable name
sVarstringThe frequency variable name
Returns
string — The Laplace transform in s
Examples
laplace("1
t
s")
laplace("t^2
t
See Also
derivative simplify
laplacian
Compute the scalar Laplacian of an expression with respect to a list of variables. The Laplacian is the sum of second partial derivatives: Δf = ∂²f/∂x² + ∂²f/∂y² + ...
Syntax
laplacian(expr | variables)
Type Signatures
string | Node, Array
Parameters
NameTypeDescription
exprstring | NodeThe scalar expression
variablesArray.<string>The variable names
Returns
string — The Laplacian as a string
Examples
laplacian("x^2 + y^2
["x
y
leafCount
Computes the number of leaves in the parse tree of the given expression
Syntax
leafCount(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to count the leaves of
Returns
number — The number of leaves of `expr`
Examples
leafCount("e^(i*pi)-1")
leafCount(parse("{a: 22/7
b: 10^(1/2)}"))
See Also
simplify
limit
Compute the limit of an expression as a variable approaches a value. Uses direct substitution first; for indeterminate 0/0 forms, applies L\
Syntax
limit(expr | variable | value)
Type Signatures
string, string, number, Node, string, number
Parameters
NameTypeDescription
exprstringThe expression to evaluate the limit of
variablestringThe variable approaching the value
valuenumberThe value the variable approaches
Returns
number — The limit value
Examples
limit("sin(x) / x
x
0)
limit("(x^2 - 1) / (x - 1)
x
lsolve
Finds one solution of the linear system L * x = b where L is an [n x n] lower triangular matrix and b is a [n] column vector.
Syntax
x=lsolve(L | b)
Type Signatures
SparseMatrix, Array | Matrix, DenseMatrix, Array | Matrix, Array, Array | Matrix
Parameters
NameTypeDescription
LMatrix, ArrayA N x N matrix or array (L)
bMatrix, ArrayA column vector with the b values
Returns
DenseMatrix | Array — A column vector with the linear system solution (x)
Examples
a = [-2
3; 2
1
lsolveAll
Finds all solutions of the linear system L * x = b where L is an [n x n] lower triangular matrix and b is a [n] column vector.
Syntax
x=lsolveAll(L | b)
Type Signatures
SparseMatrix, Array | Matrix, DenseMatrix, Array | Matrix, Array, Array | Matrix
Parameters
NameTypeDescription
LMatrix, ArrayA N x N matrix or array (L)
bMatrix, ArrayA column vector with the b values
Returns
DenseMatrix[] | Array[] — An array of affine-independent column vectors (x) that solve the linear system
Examples
a = [-2
3; 2
1
lup
Calculate the Matrix LU decomposition with partial pivoting. Matrix A is decomposed in three matrices (L, U, P) where P * A = L * U
Syntax
lup(m)
Parameters
NameTypeDescription
AMatrix | ArrayA two dimensional matrix or array for which to get the LUP decomposition.
Returns
{L: Array | Matrix, U: Array | Matrix, P: Array.<number> — } The lower triangular matrix, the upper triangular matrix and the permutation matrix.
Examples
lup([[2
1
lusolve
Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.
Syntax
x=lusolve(A | b) | x=lusolve(lu
Type Signatures
Array, Array | Matrix, DenseMatrix, Array | Matrix, SparseMatrix, Array | Matrix, SparseMatrix, Array | Matrix, number, number, Object, Array | Matrix
Parameters
NameTypeDescription
AMatrix | Array | ObjectInvertible Matrix or the Matrix LU decomposition
bMatrix | ArrayColumn Vector
ordernumberThe Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
thresholdNumberPartial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
Returns
DenseMatrix | Array — Column vector with the solution to the linear system A * x = b
Examples
a = [-2
3; 2
1
lyap
Solves the Continuous-time Lyapunov equation AP+PA\
Syntax
lyap(A | Q)
Type Signatures
Matrix, Matrix, Array, Matrix, Matrix, Array, Array, Array
Parameters
NameTypeDescription
AMatrix | ArrayMatrix A
QMatrix | ArrayMatrix Q
Returns
Matrix | Array — Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
Examples
lyap([[-2
0
See Also
schur sylvester
minimalPolynomial
Find the minimal polynomial of a simple algebraic expression. The minimal polynomial is the monic polynomial with rational coefficients of lowest degree for which the expression is a root. Supports: sqrt(n), cbrt(n), nthRoot(n, k), sqrt(a) + sqrt(b), and rational constants.
Syntax
minimalPolynomial(expr | variable)
Type Signatures
string | Node, string
Parameters
NameTypeDescription
exprstring | NodeThe algebraic expression (a numeric constant)
variablestringThe polynomial variable name
Returns
string — The minimal polynomial as a string
Examples
minimalPolynomial("sqrt(2)
x")
minimalPolynomial("cbrt(3)
x")
minimalPolynomial("sqrt(2) + sqrt(3)
multivariateTaylor
Compute the multivariate Taylor series expansion of a scalar expression around a point. Uses mixed partial derivatives to build the polynomial: f + sum_alpha (partial^|alpha| f / alpha!) * prod (xi - ai)^ki, where the sum is over all multi-indices of total degree <= order.
Syntax
multivariateTaylor(expr | variables | points
Type Signatures
string | Node, Array, Array, number
Parameters
NameTypeDescription
exprstring | NodeThe scalar expression to expand
variablesArray.<string>Array of variable names
pointsArray.<number>Array of expansion points (same length as variables)
ordernumberThe order of the expansion
Returns
string — The Taylor polynomial as a string
Examples
multivariateTaylor("x * y
["x
y
normalForm
Convert an expression to canonical polynomial or rational normal form by expanding, combining fractions, cancelling common factors, and simplifying.
Syntax
normalForm(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to normalize
Returns
string — The normalized expression as a string
Examples
normalForm("(x + 1)^2 / (x + 1)")
normalForm("1/2 + 1/3")
normalForm("(x^2 - 1) / (x - 1)")
odeGeneral
Solve first-order ordinary differential equations (ODEs) symbolically. The expression is the right-hand side of dy/dx = expr. Handles separable ODEs (dy/dx = g(x)*h(y)) and linear first-order ODEs (dy/dx + P*y = Q(x)) using integrating factors. Returns the general solution with constant C.
Syntax
odeGeneral(expr | y | x)
Parameters
NameTypeDescription
exprstring | NodeRight-hand side of dy/dx = expr
ystringThe dependent variable name
xstringThe independent variable name
Returns
string — General solution as a string (with constant C)
Examples
odeGeneral("y
y
x")
odeGeneral("-y
y
partialDerivative
Compute higher-order and mixed partial derivatives of an expression. The variables argument specifies the differentiation order: a single string for first-order, or an array of strings for higher-order mixed partials.
Syntax
partialDerivative(expr | variable) | partialDerivative(expr
Type Signatures
string | Node, string, string | Node, Array
Parameters
NameTypeDescription
exprstring | NodeThe expression to differentiate
variablesstring | Array.<string>Variable(s) to differentiate with respect to (in order)
Returns
string — The partial derivative as a string
piecewise
Build and evaluate a piecewise-defined expression. Given an array of [condition, value] pairs and a default value, evaluates each condition in order and returns the value of the first matching condition, or the default if none match.
Syntax
piecewise(pairs | defaultValue) | piecewise(pairs
Type Signatures
Array, any, Array, any, Object
Parameters
NameTypeDescription
pairsArrayArray of [condition, value] pairs
defaultValuestring|numberValue when no condition matches
scopeObjectVariable scope for evaluation
Returns
number|string — The matched value or defaultValue
Examples
piecewise([["x > 0
x
polyadd
Add two polynomials element-wise. The shorter array is padded with zeros.
Syntax
polyadd(a | b)
Type Signatures
Array, Array
Parameters
NameTypeDescription
anumber[]First polynomial coefficients [a0, a1, ..., am] (ascending degree)
bnumber[]Second polynomial coefficients [b0, b1, ..., bn] (ascending degree)
Returns
number[] — Sum polynomial coefficients
Examples
polyadd([1
2
polyder
Compute the derivative of a polynomial given its coefficient array.
Syntax
polyder(coeffs)
Parameters
NameTypeDescription
coeffsnumber[]Coefficient array [c0, c1, ..., cn] (ascending degree)
Returns
number[] — Derivative coefficients [c1, 2*c2, ..., n*cn]
Examples
polyder([1
2
3
polymul
Multiply two polynomials by convolving their coefficient arrays.
Syntax
polymul(a | b)
Type Signatures
Array, Array
Parameters
NameTypeDescription
anumber[]First polynomial coefficients [a0, a1, ..., am] (ascending degree)
bnumber[]Second polynomial coefficients [b0, b1, ..., bn] (ascending degree)
Returns
number[] — Product polynomial coefficients (degree m+n)
Examples
polymul([1
1
polynomialGCD
Compute the Greatest Common Divisor (GCD) of two polynomials using the Euclidean algorithm. The result is normalized to be monic.
Syntax
polynomialGCD(p | q | variable)
Type Signatures
Node, Node, string, string, string, string, string, Node, string, Node, string, string
Parameters
NameTypeDescription
pNode|stringFirst polynomial
qNode|stringSecond polynomial
variablestringThe variable name
Returns
string — The GCD polynomial as a string (monic)
Examples
polynomialGCD("x^2 - 1
x^2 - 2*x + 1
x")
polynomialGCD("x^2 - 1
x + 1
polynomialLCM
Compute the Least Common Multiple (LCM) of two polynomials. Computed as p*q/GCD(p,q). The result is normalized to be monic (leading coefficient 1).
Syntax
polynomialLCM(p | q | variable)
Type Signatures
string, string, string, Node, Node, string, string, Node, string, Node, string, string
Parameters
NameTypeDescription
pNode|stringFirst polynomial
qNode|stringSecond polynomial
variablestringThe variable name
Returns
string — The LCM polynomial as a string (monic)
Examples
polynomialLCM("x^2 - 1
x^2 - 2*x + 1
x")
polynomialLCM("x^2 - 1
x + 1
polynomialQuotient
Compute the quotient of polynomial long division p / q. Returns the quotient polynomial.
Syntax
polynomialQuotient(p | q | variable)
Type Signatures
Node, Node, string, string, string, string, string, Node, string, Node, string, string
Parameters
NameTypeDescription
pNode|stringDividend polynomial
qNode|stringDivisor polynomial
variablestringThe variable name
Returns
string — The quotient polynomial as a string
Examples
polynomialQuotient("x^3 - 1
x - 1
x")
polynomialQuotient("x^2 + 3*x + 2
x + 1
polynomialRemainder
Compute the remainder of polynomial long division p / q. Returns the remainder polynomial.
Syntax
polynomialRemainder(p | q | variable)
Type Signatures
Node, Node, string, string, string, string, string, Node, string, Node, string, string
Parameters
NameTypeDescription
pNode|stringDividend polynomial
qNode|stringDivisor polynomial
variablestringThe variable name
Returns
string — The remainder polynomial as a string
Examples
polynomialRemainder("x^3 + 2*x + 1
x^2 + 1
x")
polynomialRemainder("x^3 - 1
x - 1
polynomialRoot
Finds the roots of a univariate polynomial given by its coefficients starting from constant, linear, and so on, increasing in degree.
Syntax
x=polynomialRoot(-6 | 3) | x=polynomialRoot(4
Parameters
NameTypeDescription
coeffs... number | Complex
Returns
Array — The distinct roots of the polynomial
Examples
a = polynomialRoot(-6
11
-6
1)
See Also
cbrt sqrt
polyval
Evaluate a polynomial at a value x using Horner\
Syntax
polyval(coeffs | x)
Type Signatures
Array, number
Parameters
NameTypeDescription
coeffsnumber[]Coefficient array [c0, c1, ..., cn] (ascending degree)
xnumberValue at which to evaluate the polynomial
Returns
number — p(x)
Examples
polyval([1
2
3
powerExpand
Expand powers and logarithms assuming arguments are positive real numbers. Distributes (a*b)^n->a^n*b^n, (a^m)^n->a^(m*n), log(a*b)->log(a)+log(b), and similar rules.
Syntax
powerExpand(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to expand
Returns
Node|string — The expanded expression (same type as input)
Examples
powerExpand("(x * y)^3")
powerExpand("(a^2)^3")
powerExpand("log(x * y)")
powerExpand("log(x / y)")
qr
Calculates the Matrix QR decomposition. Matrix `A` is decomposed in two matrices (`Q`, `R`) where `Q` is an orthogonal matrix and `R` is an upper triangular matrix.
Syntax
qr(A)
Parameters
NameTypeDescription
AMatrix | ArrayA two dimensional matrix or array
Returns
{Q: Array | Matrix, R: Array | Matrix — } Q: the orthogonal
Examples
qr([[1
-1
4
See Also
lup slu matrix
rationalize
Transform a rationalizable expression in a rational fraction. If rational fraction is one variable polynomial then converts the numerator and denominator in canonical form, with decreasing exponents, returning the coefficients of numerator.
Syntax
rationalize(expr) | rationalize(expr | scope)
Parameters
NameTypeDescription
exprNode|stringThe expression to check if is a polynomial expression
optionalObject|booleanscope of expression or true for already evaluated rational expression at input
detailedBooleanoptional True if return an object, false if return expression node (default)
Returns
Object | Node — The rational polynomial of `expr` or an object
Examples
rationalize("2x/y - y/(x+1)")
rationalize("2x/y - y/(x+1)
true)
See Also
simplify
reduce
Solve an equation with domain constraints. Calls solve() and filters solutions by the specified domain or by assumptions stored via assume(). Valid domains: Positive, Negative, Nonnegative, Nonzero, Integer, Real, Complex, Rational.
Syntax
reduce(expr | variable) | reduce(expr
Type Signatures
string, string, Node, string, string, string, string, Node, string, string
Parameters
NameTypeDescription
exprstring|NodeThe equation or expression
variablestringThe variable to solve for
domainstringDomain constraint (optional)
Returns
number[] — Solutions filtered by domain
Examples
reduce("x^2 - 1
x
Positive")
reduce("x^2 - 4
x
See Also
solve assume element
resolve
Recursively substitute variables in an expression tree.
Syntax
resolve(node | scope)
Parameters
NameTypeDescription
nodeNode | Node[]
scopeObject
Returns
Node | Node[] — Returns `node` with variables recursively substituted.
Examples
resolve(parse("1 + x")
{ x: 7 })
resolve(parse("size(text)")
{ text: "Hello World" })
resolve(parse("x + y")
See Also
simplify evaluate
resultant
Compute the resultant of two univariate polynomials as the determinant of their Sylvester matrix. The resultant is zero if and only if the polynomials share a common root. Used for polynomial elimination.
Syntax
resultant(p | q | variable)
Type Signatures
string, string, string, Node, Node, string, string, Node, string, Node, string, string
Parameters
NameTypeDescription
pNode|stringFirst polynomial
qNode|stringSecond polynomial
variablestringThe variable name
Returns
number — The resultant value
Examples
resultant("x^2 - 1
x^2 - 4
x")
resultant("x^2 - 1
x - 1
schur
Performs a real Schur decomposition of the real matrix A = UTU\
Syntax
schur(A)
Parameters
NameTypeDescription
AArray | MatrixMatrix A
Returns
{U: Array | Matrix, T: Array | Matrix — } Object containing both matrix U and T of the Schur Decomposition A=UTU'
Examples
schur([[1
0
See Also
lyap sylvester
series
Compute the Taylor series expansion of an expression around a point. Uses the formula f(a) + f\
Syntax
series(expr | variable) | series(expr
Type Signatures
string, string, Node, string, string, string, number, Node, string, number, string, string, number, number, Node, string, number, number
Parameters
NameTypeDescription
exprstring | NodeThe expression to expand
variablestringThe expansion variable
Returns
string — The Taylor series as a string
Examples
series("exp(x)
x
0
4)
series("sin(x)
seriesCoefficient
Extract the nth coefficient from the Taylor series expansion of an expression around a point. Uses the formula c_n = f^(n)(a) / n! where f^(n) is the nth derivative.
Syntax
seriesCoefficient(expr | variable | point
Type Signatures
string | Node, string, number, number
Parameters
NameTypeDescription
exprstring | NodeThe expression to expand
variablestringThe expansion variable
pointnumberThe expansion point
nnumberThe coefficient index (non-negative integer)
Returns
number — The nth Taylor coefficient
Examples
seriesCoefficient("exp(x)
x
0
3)
seriesCoefficient("sin(x)
simplify
Simplify an expression tree.
Syntax
simplify(expr) | simplify(expr | rules)
Parameters
NameTypeDescription
exprNode | string
rulesSimplifyRule[]
scopeObjectOptional scope with variables
optionsSimplifyOptionsOptional configuration settings
Returns
Node — Returns the simplified form of `expr`
Examples
simplify("3 + 2 / 4")
simplify("2x + x")
f = parse("x * (x + 2 + x)")
simplified = simplify(f)
simplified.evaluate({x: 2})
simplifyConstant
Replace constant subexpressions of node with their values.
Syntax
simplifyConstant(expr) | simplifyConstant(expr | options)
Type Signatures
string, Object, Node, Object, string, Object, Fraction, Object, BigNumber, Object, number, Object
Parameters
NameTypeDescription
nodeNode | string
optionsObject
Returns
Node — Returns expression with constant subexpressions evaluated
Examples
simplifyConstant("(3-3)*x")
simplifyConstant(parse("z-cos(tau/8)"))
simplifyCore
Perform simple one-pass simplifications on an expression tree.
Syntax
simplifyCore(node)
Parameters
NameTypeDescription
nodeNode | string
optionsObject
Returns
Node — Returns expression with basic simplifications applied
Examples
simplifyCore(parse("0*x"))
simplifyCore(parse("(x+0)*2"))
simplifyUtil
/ unaryPlus: { trivial: T, total: T, commutative: T, associative: T }, /*
slu
Calculate the Matrix LU decomposition with full pivoting. Matrix A is decomposed in two matrices (L, U) and two permutation vectors (pinv, q) where P * A * Q = L * U
Syntax
slu(A | order | threshold)
Type Signatures
SparseMatrix, number, number
Parameters
NameTypeDescription
ASparseMatrixA two dimensional sparse matrix for which to get the LU decomposition.
orderNumberThe Symbolic Ordering and Analysis order:
thresholdNumberPartial pivoting threshold (1 for partial pivoting)
Returns
Object — The lower triangular matrix, the upper triangular matrix and the permutation vectors.
Examples
slu(sparse([4.5
0
3.2
0; 3.1
2.9
solve
Solve an equation or expression equal to zero for a given variable. Handles linear equations, quadratic equations (via quadratic formula), and simple polynomials (rational roots theorem). The input can be an equation like "x^2 - 4 = 0" or just an expression like "x^2 - 4" (treated as equal to zero).
Syntax
solve(expr | variable)
Type Signatures
string, string, Node, string
Parameters
NameTypeDescription
exprstringThe equation or expression (= 0)
variablestringThe variable to solve for
Returns
number[] — Array of solutions
Examples
solve("x^2 - 4
x")
solve("2*x + 6
x")
solve("x^2 - 5*x + 6
substitute
Substitute a variable with a value or expression. Replaces all occurrences of the specified variable in an expression with the given value.
Syntax
substitute(expr | variable | value)
Type Signatures
Node, string, number, Node, string, string, Node, string, Node, string, string, number, string, string, string, string, string, Node
Parameters
NameTypeDescription
exprNode|stringThe expression to substitute into
variablestringThe variable name to replace
valuenumber|string|NodeThe replacement value or expression
Returns
number|string — Numeric result if value is a number, string otherwise
Examples
substitute("x^2 + 2*x
x
3)
substitute("x^2 + 2*x + 1
x
See Also
simplify evaluate
summation
Compute the summation of an expression over a variable from start to end. Attempts closed-form evaluation for common patterns (arithmetic, quadratic, geometric series), then falls back to numeric summation.
Syntax
summation(expr | variable | start
Parameters
NameTypeDescription
exprstring | NodeThe summand expression
variablestringThe summation index variable
startnumberThe lower bound (integer)
endnumberThe upper bound (integer)
Returns
number | string — The sum (number for numeric, string for closed-form)
Examples
summation("k
k
1
100)
summation("k^2
sylvester
Solves the real-valued Sylvester equation AX+XB=C for X
Syntax
sylvester(A | B | C)
Type Signatures
Array, Matrix, Matrix, Array, Array, Matrix, Array, Matrix, Array, Matrix, Array, Matrix, Matrix, Array, Array, Matrix, Matrix, Array
Parameters
NameTypeDescription
AMatrix | ArrayMatrix A
BMatrix | ArrayMatrix B
CMatrix | ArrayMatrix C
Returns
Matrix | Array — Matrix X, solving the Sylvester equation
Examples
sylvester([[-1
-2
See Also
schur lyap
symbolicEqual
Returns true if the difference of the expressions simplifies to 0
Syntax
symbolicEqual(expr1 | expr2) | symbolicEqual(expr1
Parameters
NameTypeDescription
expr1Node|stringThe first expression to compare
expr2Node|stringThe second expression to compare
optionsObjectOptional option object, passed to simplify
Returns
boolean —
Examples
symbolicEqual("x*y
y*x")
symbolicEqual("abs(x^2)
x^2")
symbolicEqual("abs(x)
See Also
simplify evaluate
symbolicProduct
Compute the product of an expression over a variable from start to end. Attempts closed-form evaluation for common patterns (factorial, partial factorial, constant product), then falls back to numeric evaluation.
Syntax
symbolicProduct(expr | variable | start
Parameters
NameTypeDescription
exprstring | NodeThe multiplicand expression
variablestringThe product index variable
startnumberThe lower bound (integer)
endnumberThe upper bound (integer)
Returns
number — The product
Examples
symbolicProduct("k
k
1
5)
symbolicProduct("k
See Also
summation evaluate
tangentLine
Compute the tangent line of an expression at a given point. Returns a string expression y = f(a) + f\
Syntax
tangentLine(expr | variable | point)
Type Signatures
string | Node, string, number
Parameters
NameTypeDescription
exprstring | NodeThe expression to differentiate
variablestringThe variable name
pointnumberThe point at which to compute the tangent
Returns
string — The tangent line expression as a string
taylor
Compute the Taylor polynomial expansion of an expression around a point. Returns only the polynomial string. Uses the formula f(a) + f\
Syntax
taylor(expr | variable) | taylor(expr
Parameters
NameTypeDescription
exprstring | NodeThe expression to expand
variablestringThe expansion variable
Returns
string — The Taylor polynomial as a string
Examples
taylor("sin(x)
x
0
5)
taylor("exp(x)
toRadicals
Convert expressions containing fractional powers to explicit radical form. x^(1/2) becomes sqrt(x), x^(1/3) becomes cbrt(x), x^(p/q) becomes nthRoot(x^p, q). Numeric values are simplified where possible.
Syntax
toRadicals(expr)
Type Signatures
string | Node
Parameters
NameTypeDescription
exprstring | NodeThe expression to convert
Returns
string — The radical form as a string
Examples
toRadicals("x^(1/2)")
toRadicals("x^(1/3)")
toRadicals("x^(2/3)")
toRadicals("4^(1/2)")
together
Combine fractions over a common denominator. This is the inverse of apart: it takes a sum of fractions and combines them into a single rational expression.
Syntax
together(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to combine
Returns
string — The combined expression as a string
Examples
together("1/(x-1) + 1/(x+1)")
together("1/x + 1/y")
together("a/b + c/d")
trigExpand
Expand trigonometric expressions using angle addition formulas: sin(a+b), cos(a+b), tan(a+b), and double-angle identities like sin(2*x).
Syntax
trigExpand(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to expand
Returns
Node|string — The expanded expression (same type as input)
Examples
trigExpand("sin(a + b)")
trigExpand("cos(a + b)")
trigExpand("sin(2 * x)")
trigExpand("tan(a + b)")
See Also
trigReduce simplify
trigReduce
Reduce products of trigonometric functions to sums using product-to-sum identities. Inverse of trigExpand. Applies sin^2, cos^2 half-angle and product formulas.
Syntax
trigReduce(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to reduce
Returns
Node|string — The reduced expression (same type as input)
Examples
trigReduce("sin(x)^2")
trigReduce("cos(x)^2")
trigReduce("sin(x) * cos(x)")
trigReduce("sin(a) * sin(b)")
See Also
trigExpand simplify
trigToExp
Convert trigonometric and hyperbolic functions to exponential form. Applies sin(x)->(exp(i*x)-exp(-i*x))/(2*i), cos(x)->(exp(i*x)+exp(-i*x))/2, and hyperbolic equivalents.
Syntax
trigToExp(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to convert
Returns
Node|string — The converted expression (same type as input)
Examples
trigToExp("cos(x)")
trigToExp("sin(x)")
trigToExp("sinh(x)")
trigToExp("cosh(x)")
See Also
expToTrig simplify
usolve
Finds one solution of the linear system U * x = b where U is an [n x n] upper triangular matrix and b is a [n] column vector.
Syntax
x=usolve(U | b)
Type Signatures
SparseMatrix, Array | Matrix, DenseMatrix, Array | Matrix, Array, Array | Matrix
Parameters
NameTypeDescription
UMatrix, ArrayA N x N matrix or array (U)
bMatrix, ArrayA column vector with the b values
Returns
DenseMatrix | Array — A column vector with the linear system solution (x)
Examples
x=usolve(sparse([1
1
1
1; 0
1
usolveAll
Finds all solutions of the linear system U * x = b where U is an [n x n] upper triangular matrix and b is a [n] column vector.
Syntax
x=usolve(U | b)
Type Signatures
SparseMatrix, Array | Matrix, DenseMatrix, Array | Matrix, Array, Array | Matrix
Parameters
NameTypeDescription
UMatrix, ArrayA N x N matrix or array (U)
bMatrix, ArrayA column vector with the b values
Returns
DenseMatrix[] | Array[] — An array of affine-independent column vectors (x) that solve the linear system
Examples
x=usolve(sparse([1
1
1
1; 0
1
variables
Extract all symbolic variable names from an expression. Walks the AST and collects SymbolNode names, excluding known mathematical constants (pi, e, i) and built-in function names. Returns a sorted array of unique variable names.
Syntax
variables(expr)
Parameters
NameTypeDescription
exprNode|stringThe expression to inspect
Returns
string[] — Sorted array of unique variable names
Examples
variables("x^2 + y*z + pi")
variables("a*sin(b) + c")
variables("3*x + 2")
zTransform
Compute the Z-transform of a discrete sequence using a lookup table of known transform pairs. Supported: 1 → z/(z-1), n → z/(z-1)^2, n^2 → z*(z+1)/(z-1)^3, a^n → z/(z-a), n*a^n → a*z/(z-a)^2, cos(w*n) and sin(w*n) patterns.
Syntax
zTransform(expr | nVar | zVar)
Parameters
NameTypeDescription
exprstring | NodeThe discrete sequence expression (function of nVar)
nVarstringThe time-domain index variable (e.g. 'n')
zVarstringThe Z-domain variable (e.g. 'z')
Returns
string — Z-domain expression as a string
Examples
zTransform("1
n
z")
zTransform("n
n