Arithmetic
Constants
| Symbol | Value | |
|---|---|---|
ExponentialE | \approx 2.7182818284\ldots | Euler's number |
MachineEpsilon | 2^{−52} | The difference between 1 and the next larger floating point number. See Machine Epsilon on Wikipedia |
CatalanConstant | \approx 0.9159655941\ldots | \sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2n+1)^2} See Catalan's Constant on Wikipedia |
GoldenRatio | \approx 1.6180339887\ldots | \frac{1+\sqrt{5}}{2} See Golden Ratio on Wikipedia |
EulerGamma | \approx 0.5772156649\ldots | See Euler-Mascheroni Constant on Wikipedia |
Functions
Arithmetic Functions
| Function | Notation | |
|---|---|---|
Add | a + b | Addition |
Subtract | a - b | Subtraction |
Negate | -a | Additive inverse |
Multiply | a\times b | Multiplication |
Divide | \frac{a}{b} | Divide |
Power | a^b | Exponentiation |
Root | \sqrt[n]{x}=x^{\frac1n} | nth root |
Sqrt | \sqrt{x}=x^{\frac12} | Square root |
Square | x^2 |
Sums and Products
Sum(xs: collection)
Evaluate to a sum of all the elements in collection. If all the elements are
numbers, the result is a number. Otherwise it is an ["Add"] expression.
["Sum", ["List", 5, 7, 11]]
// ➔ 23
["Sum", ["List", 5, 7, "x" , "y"]]
// ➔ ["Add", 12, "x", "y"]
Note this is equivalent to:
["Reduce", ["List", 5, 7, 11], "Add"]
Sum(body: function, ...bounds: tuple) -> number
Evaluate to the sum of body for each value in bounds.
["Sum", ["Add", "i", 1], ["Tuple", "i", 1, 10]]
// ➔ 65
Sum(body: function, ...bounds: Element) -> number
Evaluate to the sum of body for each value in an Element-based indexing set.
This form uses ["Element", index, collection] to specify that the index variable
iterates over a finite collection (Set, List, or Range).
["Sum", "n", ["Element", "n", ["Set", 1, 2, 3]]]
// ➔ 6
["Sum", ["Power", "n", 2], ["Element", "n", ["Set", 1, 2, 3]]]
// ➔ 14 (1² + 2² + 3² = 1 + 4 + 9)
["Sum", "n", ["Element", "n", ["Range", 1, 5]]]
// ➔ 15 (1 + 2 + 3 + 4 + 5)
The indexing set can be:
- Set:
["Set", 1, 2, 3]- explicit finite set of values - List:
["List", 1, 2, 3]- ordered list of values - List (2-element):
["List", 1, 5]- when a List has exactly 2 integer elements, it is treated as a Range. This allows bracket notation like\sum_{n \in [1,5]} nto iterate over all integers from 1 to 5 (evaluates to 15, not 6). - Range:
["Range", 1, 10]- integer range from 1 to 10 - Interval:
["Interval", 1, 10]- enumerates integers in the interval. SupportsOpenandClosedboundary markers:["Interval", 1, 5]→ iterates 1, 2, 3, 4, 5 (closed bounds)["Interval", ["Open", 0], 5]→ iterates 1, 2, 3, 4, 5 (excludes 0)["Interval", 1, ["Open", 6]]→ iterates 1, 2, 3, 4, 5 (excludes 6)
Note: Evaluation requires a finite, enumerable domain with at most 1000 elements.
Sums over infinite sets (like \sum_{n \in \mathbb{N}}) remain symbolic.
Multiple Indexing Sets
Multiple Element expressions can be specified for multi-index sums:
["Sum", ["Multiply", "n", "m"], ["Element", "n", ["Set", 1, 2]], ["Element", "m", ["Set", 3, 4]]]
// ➔ 21 (1·3 + 1·4 + 2·3 + 2·4)
Mixed indexing sets (Element + Limits) can be used together:
["Sum", ["Add", "n", "m"], ["Element", "n", ["Set", 1, 2]], ["Limits", "m", 1, 2]]
// ➔ 12 (n iterates {1,2}, m iterates 1 to 2)
Condition Filtering
A condition can be attached to an Element expression to filter values from the set. The condition is the optional 4th operand of the Element expression.
// Sum only positive values from S
["Sum", "n", ["Element", "n", ["Set", 1, 2, 3, -1, -2], ["Greater", "n", 0]]]
// ➔ 6 (only 1 + 2 + 3)
// Sum values greater than or equal to 2
["Sum", "n", ["Element", "n", ["Set", 1, 2, 3, 4], ["GreaterEqual", "n", 2]]]
// ➔ 9 (only 2 + 3 + 4)
// Product of negative values
["Product", "k", ["Element", "k", ["Set", 1, -2, 3, -4], ["Less", "k", 0]]]
// ➔ 8 (only (-2) × (-4))
Supported condition operators: Greater, GreaterEqual, Less, LessEqual, NotEqual.
Simplification
When simplify() is called on a Sum expression with symbolic bounds, the following closed-form formulas are applied when applicable:
| Pattern | Simplifies to | Name |
|---|---|---|
\sum_{n=1}^{b} c | b \cdot c | Constant body |
\sum_{n=a}^{b} n | \frac{b(b+1) - a(a-1)}{2} | Triangular number (general bounds) |
\sum_{n=1}^{b} n^2 | \frac{b(b+1)(2b+1)}{6} | Sum of squares |
\sum_{n=1}^{b} n^3 | \left[\frac{b(b+1)}{2}\right]^2 | Sum of cubes |
\sum_{n=0}^{b} r^n | \frac{1-r^{b+1}}{1-r} | Geometric series |
\sum_{n=0}^{b} (-1)^n | \frac{1+(-1)^b}{2} | Alternating unit series |
\sum_{n=0}^{b} (-1)^n \cdot n | (-1)^b \lfloor\frac{b+1}{2}\rfloor | Alternating linear series |
\sum_{n=0}^{b} (a + dn) | (b+1)\left(a + \frac{db}{2}\right) | Arithmetic progression |
\sum_{k=0}^{n} \binom{n}{k} | 2^n | Sum of binomial coefficients |
\sum_{k=0}^{n} (-1)^k \binom{n}{k} | 0 | Alternating binomial sum |
\sum_{k=0}^{n} k \binom{n}{k} | n \cdot 2^{n-1} | Weighted binomial sum |
\sum_{k=1}^{n} \frac{1}{k(k+1)} | \frac{n}{n+1} | Partial fractions (telescoping) |
\sum_{k=2}^{n} \frac{1}{k(k-1)} | \frac{n-1}{n} | Partial fractions (telescoping) |
\sum_{k=0}^{n} k^2 \binom{n}{k} | n(n+1) \cdot 2^{n-2} | Weighted squared binomial sum |
\sum_{k=0}^{n} k^3 \binom{n}{k} | n^2(n+3) \cdot 2^{n-3} | Weighted cubed binomial sum |
\sum_{k=0}^{n} (-1)^k k \binom{n}{k} | 0 | Alternating weighted binomial sum (n ≥ 2) |
\sum_{k=0}^{n} \binom{n}{k}^2 | \binom{2n}{n} | Sum of binomial squares |
\sum_{k=1}^{n} k(k+1) | \frac{n(n+1)(n+2)}{3} | Sum of consecutive products |
\sum_{n=m}^{b} (a + dn) | (b-m+1)\left(a + \frac{d(m+b)}{2}\right) | Arithmetic progression (general bounds) |
\sum_{n=1}^{b} c \cdot f(n) | c \cdot \sum_{n=1}^{b} f(n) | Factor out constant |
Edge cases:
- Empty range (upper < lower): returns
0 - Single iteration (upper = lower): substitutes the bound value and returns the body
- Nested sums: inner sums are simplified first, enabling cascading simplification
Product(xs: collection)
Evaluate to a product of all the elements in collection.
If all the elements are numbers, the result is a number. Otherwise it is a ["Multiply"] expression.
["Product", ["List", 5, 7, 11]]
// ➔ 385
["Product", ["List", 5, "x", 11]]
// ➔ ["Multiply", 55, "x"]
Note this is equivalent to:
["Reduce", ["List", 5, 7, 11], "Multiply"]
Product(f: function, bounds:tuple)
Return the product of body for each value in bounds.
["Product", ["Add", "x", 1], ["Tuple", "x", 1, 10]]
// ➔ 39916800
Product(body: function, ...bounds: Element) -> number
Evaluate to the product of body for each value in an Element-based indexing set.
This form uses ["Element", index, collection] to specify that the index variable
iterates over a finite collection (Set, List, or Range).
["Product", "k", ["Element", "k", ["Set", 1, 2, 3, 4]]]
// ➔ 24 (4!)
["Product", ["Power", "k", 2], ["Element", "k", ["Set", 1, 2, 3]]]
// ➔ 36 (1² × 2² × 3² = 1 × 4 × 9)
See the Sum documentation above for details on supported collection types.
Simplification
When simplify() is called on a Product expression with symbolic bounds, the following closed-form formulas are applied when applicable:
| Pattern | Simplifies to | Name |
|---|---|---|
\prod_{n=1}^{b} c | c^b | Constant body |
\prod_{n=1}^{b} n | b! | Factorial |
\prod_{n=1}^{b} (n+c) | \frac{(b+c)!}{c!} | Shifted factorial |
\prod_{n=1}^{b} (2n-1) | (2b-1)!! | Odd double factorial |
\prod_{n=1}^{b} 2n | 2^b \cdot b! | Even double factorial |
\prod_{k=0}^{n-1} (x+k) | (x)_n | Rising factorial (Pochhammer) |
\prod_{k=0}^{n-1} (x-k) | \frac{x!}{(x-n)!} | Falling factorial |
\prod_{k=1}^{n} \frac{k+1}{k} | n+1 | Telescoping product |
\prod_{k=2}^{n} (1 - \frac{1}{k^2}) | \frac{n+1}{2n} | Wallis-like product |
\prod_{n=1}^{b} c \cdot f(n) | c^b \cdot \prod_{n=1}^{b} f(n) | Factor out constant |
Edge cases:
- Empty range (upper < lower): returns
1 - Single iteration (upper = lower): substitutes the bound value and returns the body
Transcendental Functions
| Function | Notation | |
|---|---|---|
Exp | \exponentialE^{x} | Exponential function |
Ln | \ln(x) | Logarithm function, the natural logarithm, the inverse of Exp |
Log | \log_b(x) | ["Log", <v>, <b>]Logarithm of base b, default 10 |
Lb | \log_2(x) | Binary logarithm function, the base-2 logarithm |
Lg | \log_{10}(x) | Common logarithm, the base-10 logarithm |
LogOnePlus | \ln(x+1) |
Rounding
| Function | Notation | |
|---|---|---|
Abs | \|x\| | Absolute value, magnitude |
Ceil | \lceil x \rceil | Rounds a number up to the next largest integer |
Floor | \lfloor x \rfloor | Round a number to the greatest integer less than the input value |
Chop | Replace real numbers that are very close to 0 (less than 10^{-10}) with 0 | |
Round |
Other Relational Operators
Congruent(a, b, modulus)
Evaluate to True if a is congruent to b modulo modulus.
["Congruent", 26, 11, 5]
// ➔ True
Other Functions
Clamp(value)
Clamp(value, lower, upper)
- If
valueis less thanlower, evaluate tolower - If
valueis greater thanupper, evaluate toupper - Otherwise, evaluate to
value
If lowerand upperare not provided, they take the default values of -1 and
+1.
["Clamp", 0.42]
// ➔ 1
["Clamp", 4.2]
// ➔ 1
["Clamp", -5, 0, "+Infinity"]
// ➔ 0
["Clamp", 100, 0, 11]
// ➔ 11
Max(x1, x2, ...)
Max(list)
If all the arguments are real numbers, excluding NaN, evaluate to the largest
of the arguments.
Otherwise, simplify the expression by removing values that are smaller than or equal to the largest real number.
["Max", 5, 2, -1]
// ➔ 5
["Max", 0, 7.1, "NaN", "x", 3]
// ➔ ["Max", 7.1, "NaN", "x"]
Max(x1, x2, ...)
Max(list)
If all the arguments are real numbers, excluding NaN, evaluate to the smallest
of the arguments.
Otherwise, simplify the expression by removing values that are greater than or equal to the smallest real number.
["Min", 5, 2, -1]
// ➔ -1
["Min", 0, 7.1, "x", 3]
// ➔ ["Min", 0, "x"]
Mod(a, b)
Evaluate to the Euclidian division (modulus) of a by b.
When a and b are positive integers, this is equivalent to the % operator in
JavaScript, and returns the remainder of the division of a by b.
However, when a and b are not positive integers, the result is different.
The result is always the same sign as b, or 0.
["Mod", 7, 5]
// ➔ 2
["Mod", -7, 5]
// ➔ 3
["Mod", 7, -5]
// ➔ -3
["Mod", -7, -5]
// ➔ -2
Rational(n)
Evaluate to a rational approximating the value of the number n.
["Rational", 0.42]
// ➔ ["Rational", 21, 50]
Rational(numerator, denominator)
Represent a rational number equal to numeratorover denominator.
Numerator(expr)
Return the numerator of expr.
Note that expr may be a non-canonical form.
["Numerator", ["Rational", 4, 5]]
// ➔ 4
Denominator(expr)
Return the denominator of expr.
Note that expr may be a non-canonical form.
["Denominator", ["Rational", 4, 5]]
// ➔ 5
NumeratorDenominator(expr)
Return the numerator and denominator of expr as a sequence.
Note that expr may be a non-canonical form.
["NumeratorDenominator", ["Rational", 4, 5]]
// ➔ ["Sequence", 4, 5]
The sequence can be used with another function, for example GCD to check if the fraction is in its canonical form:
["GCD", ["NumeratorDenominator", ["Rational", 4, 5]]]
// ➔ 1
["GCD", ["NumeratorDenominator", ["Rational", 8, 10]]]
// ➔ 2
Relational Operators
| Function | Notation | |
|---|---|---|
Equal | x = y | Mathematical relationship asserting that two quantities have the same value |
NotEqual | x \ne y | |
Greater | x \gt y | |
GreaterEqual | x \geq y | |
Less | x \lt y | |
LessEqual | x \leq y |
See below for additonal relational operators: Congruent, etc...
Polynomial Arithmetic
These functions operate on polynomial expressions.
| Function | Description |
|---|---|
Expand | Expand products and positive integer powers |
ExpandAll | Recursively expand products and positive integer powers |
Factor | Factor an expression into irreducible factors |
Together | Combine rational expressions into a single fraction |
Distribute | Distribute multiplication over addition |
PolynomialDegree | Return the degree of a polynomial |
CoefficientList | Return the list of coefficients of a polynomial |
PolynomialQuotient | Return the quotient of polynomial division |
PolynomialRemainder | Return the remainder of polynomial division |
PolynomialGCD | Return the greatest common divisor of two polynomials |
Cancel | Cancel common polynomial factors in a rational expression |
Expand(expr)
Expand out products and positive integer powers in expr.
["Expand", ["Power", ["Add", "x", 1], 2]]
// ➔ ["Add", ["Power", "x", 2], ["Multiply", 2, "x"], 1]
ExpandAll(expr)
Recursively expand out products and positive integer powers in expr and all subexpressions.
Factor(expr)
Factor(expr, var)
Factor a polynomial expression into a product of irreducible factors.
Supports:
- Perfect square trinomials:
a^2 \pm 2ab + b^2 \to (a \pm b)^2 - Difference of squares:
a^2 - b^2 \to (a-b)(a+b) - Quadratic factoring:
ax^2 + bx + c(when roots are rational) - Common factor extraction:
2x + 4 \to 2(x+2)
The optional var parameter specifies which variable to factor over.
Perfect square trinomial:
["Factor", ["Add", ["Power", "x", 2], ["Multiply", 2, "x"], 1]]
// ➔ ["Power", ["Add", "x", 1], 2] // (x+1)²
Quadratic with rational roots:
["Factor", ["Add", ["Power", "x", 2], ["Multiply", 5, "x"], 6]]
// ➔ ["Multiply", ["Add", "x", 2], ["Add", "x", 3]] // (x+2)(x+3)
Difference of squares:
["Factor", ["Add", ["Power", "x", 2], -4]]
// ➔ ["Multiply", ["Add", "x", -2], ["Add", "x", 2]] // (x-2)(x+2)
With coefficients:
["Factor", ["Add", ["Multiply", 4, ["Power", "x", 2]], ["Multiply", 12, "x"], 9]]
// ➔ ["Power", ["Add", ["Multiply", 2, "x"], 3], 2] // (2x+3)²
Automatic use in sqrt simplification:
["Sqrt", ["Add", ["Power", "x", 2], ["Multiply", 2, "x"], 1]]
// ➔ ["Abs", ["Add", "x", 1]] // |x+1| (auto-factors before applying sqrt rule)
Together(expr)
Combine rational expressions into a single fraction with a common denominator.
["Together", ["Add", ["Divide", 1, "x"], ["Divide", 1, "y"]]]
// ➔ ["Divide", ["Add", "x", "y"], ["Multiply", "x", "y"]]
Distribute(expr)
Distribute multiplication over addition in expr.
["Distribute", ["Multiply", "a", ["Add", "b", "c"]]]
// ➔ ["Add", ["Multiply", "a", "b"], ["Multiply", "a", "c"]]
PolynomialDegree(poly, var)
Return the degree of the polynomial poly with respect to the variable var.
["PolynomialDegree", ["Add", ["Power", "x", 3], ["Multiply", 2, "x"], 1], "x"]
// ➔ 3
CoefficientList(poly, var)
Return the list of coefficients of the polynomial poly with respect to the variable var, ordered from lowest to highest degree.
["CoefficientList", ["Add", ["Power", "x", 3], ["Multiply", 2, "x"], 1], "x"]
// ➔ ["List", 1, 2, 0, 1]
The result represents the polynomial 1 + 2x + 0x^2 + 1x^3.
PolynomialQuotient(dividend, divisor, var)
Return the quotient of the polynomial division of dividend by divisor with respect to the variable var.
["PolynomialQuotient", ["Subtract", ["Power", "x", 3], 1], ["Subtract", "x", 1], "x"]
// ➔ ["Add", ["Power", "x", 2], "x", 1]
This represents \frac{x^3 - 1}{x - 1} = x^2 + x + 1.
PolynomialRemainder(dividend, divisor, var)
Return the remainder of the polynomial division of dividend by divisor with respect to the variable var.
["PolynomialRemainder", ["Add", ["Power", "x", 3], ["Multiply", 2, "x"], 1], ["Add", "x", 1], "x"]
// ➔ -2
PolynomialGCD(a, b, var)
Return the greatest common divisor of two polynomials a and b with respect to the variable var.
["PolynomialGCD", ["Subtract", ["Power", "x", 2], 1], ["Subtract", "x", 1], "x"]
// ➔ ["Subtract", "x", 1]
This represents \gcd(x^2 - 1, x - 1) = x - 1.
Cancel(expr, var)
Cancel common polynomial factors in the numerator and denominator of the rational expression expr with respect to the variable var.
["Cancel", ["Divide", ["Subtract", ["Power", "x", 2], 1], ["Subtract", "x", 1]], "x"]
// ➔ ["Add", "x", 1]
This represents \frac{x^2 - 1}{x - 1} = x + 1 after canceling the common factor (x - 1).