Readonly
keysThe keys of the dictionary.
If this expression not a dictionary, return null
Readonly
keysIf this expression is a dictionary, return the value of the key
entry.
Readonly
isThe value of this expression is a number that is the root of a non-zero univariate polynomial with rational coefficients.
All integers and rational numbers are algebraic.
Transcendental numbers, such as \( \pi \) or \( e \) are not algebraic.
Readonly
isThe value of this expression is a number, but not NaN
or any Infinity
isReal || isImaginary
Readonly
isisReal || isImaginary || isInfinity
Readonly
isReal or ±Infinity
isReal || isInfinity
Readonly
isThe value of this expression is a number with a imaginary part
Readonly
isThe value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
Readonly
istrue
if the value of this expression is a number.
isExtendedComplex || isNaN
= isReal || isImaginary || isInfinity || isNaN
Note that in a fateful twist of cosmic irony, NaN
("Not a Number")
is a number.
Readonly
isThe value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
Note that every integer is also a rational.
Readonly
isThe value of this expression is real number: finite and not imaginary.
isFinite && !isImaginary
Readonly
isReadonly
isReadonly
isThis expression is a number, but not ±Infinity and not NaN
Readonly
isThe numeric value of this expression is ±Infinity or Complex Infinity
Readonly
is"Not a Number".
A value representing undefined result of computations, such as 0/0
,
as per the floating point format standard IEEE-754.
Note that if isNaN
is true, isNumber
is also true (yes, NaN
is a
number).
Readonly
isThe numeric value of this expression is < 0, same as isLess(0)
Readonly
isThe numeric value of this expression is not -1.
Readonly
isThe numeric value of this expression is >= 0, same as isGreaterEqual(0)
Readonly
isThe numeric value of this expression is <= 0, same as isLessEqual(0)
Readonly
isThe numeric value of this expression is not 0.
Readonly
isReadonly
isThe numeric value of this expression is not 1.
Readonly
isThe numeric value of this expression is > 0, same as isGreater(0)
Readonly
isReadonly
isThe numeric value of this expression is 0.
Readonly
nopsIf this expression is a function, the number of operands, otherwise 0.
Note that a function can have 0 operands, so to check if this expression
is a function, check if this.ops !== null
instead.
Note applicable to canonical and non-canonical expressions.
Readonly
op1First operand, i.e.this.ops[0]
Note applicable to canonical and non-canonical expressions.
Readonly
op2Second operand, i.e.this.ops[1]
Note applicable to canonical and non-canonical expressions.
Readonly
op3Third operand, i.e. this.ops[2]
Note applicable to canonical and non-canonical expressions.
Readonly
opsThe list of arguments of the function, its "tail".
If the expression is not a function, return null
.
Note applicable to canonical and non-canonical expressions.
Readonly
numericReturn the value of this expression, if a number literal.
Note it is possible for numericValue
to be null
, and for isNotZero
to be true. For example, when a symbol has been defined with an assumption.
Conversely, isNumber
may be true even if numericValue
is null
,
example the symbol Pi
return true for isNumber
but numericValue
is
null
. It's value can be accessed with .value.numericValue
Readonly
sgnReturn the following, depending on the value of this expression:
-1
if it is < 00
if it is = 0+1
if it is > 0undefined
this value may be positive, negative or zero. We don't know
right now (a symbol with an Integer domain, but no currently assigned
value, for example)null
this value will never be positive, negative or zero (NaN
,
a string or a complex number for example)Note that complex numbers have no natural ordering,
so if the value is a complex number, sgn
is either 0, or null
If a symbol, this does take assumptions into account, that is this.sgn
will return 1
if isPositive
is true
, even if this expression has
no value
Readonly
baseFor symbols and functions, a possible definition associated with the
expression. baseDefinition
is the base class of symbol and function
definition.
Note undefined
if not a canonical expression.
Readonly
complexityExpressions with a higher complexity score are sorted first in commutative functions
Note undefined
if not a canonical expression.
Readonly
descriptionAn optional short description if a symbol or function expression.
May include markdown. Each string is a paragraph.
Note undefined
if not a canonical expression.
Readonly
engineThe Compute Engine associated with this expression provides a context in which to interpret it, such as definition of symbols and functions.
ComputeEngine is the class that implements IComputeEngine.
Readonly
errorsAll the ["Error"]
subexpressions
Note applicable to canonical and non-canonical expressions.
Readonly
freeAll the identifiers (symbols and functions) in the expression that are not a local variable or a parameter of that function.
Readonly
functionFor functions, a possible definition associated with the expression.
Note undefined
if not a canonical expression or not a function.
Readonly
Internal
hashReadonly
headAll boxed expressions have a head.
If not a function this can be Symbol
, String
, Number
or Dictionary
.
If the head expression can be represented as a string, it is returned as a string.
Note applicable to canonical and non-canonical expressions. The head
of a non-canonical expression may be different than the head of its
canonical counterpart. For example the canonical counterpart of ["Divide", 5, 7]
is ["Rational", 5, 5]
.
Readonly
isTrue if the expression is a constant, that is a symbol with an immutable value
Readonly
isAn exact value is not further transformed when evaluated. To get an
approximate evaluation of an exact value, use .N()
.
Non-exact values includes:
Readonly
isIf this is the Nothing
symbol, return true
.
Note applicable to canonical and non-canonical expressions.
Readonly
isIf true, the value of the expression never changes and evaluating it has no side-effects. If false, the value of the expression may change, if the value of other expression changes or for other reasons.
If this.isPure
is false
, this.value
is undefined. Call
this.evaluate()
to determine the value of the expression instead.
As an example, the Random
function is not pure.
Note applicable to canonical and non-canonical expressions.
Readonly
jsonMathJSON representation of this expression.
Note applicable to canonical and non-canonical expressions.
Readonly
rankReturn 0 for a scalar, 1 for a vector, 2 for a matrix, > 2 for a multidimensional matrix. It's the length of expr.shape
Readonly
Internal
rawFor debugging, the raw MathJSON representation of this expression without decanonicalization.
Readonly
scopeThe scope in which this expression has been defined. Is null when the expression is not canonical.
Readonly
shapeThe shape describes the axis of the expression.
When the expression is a scalar (number), the shape is []
.
When the expression is a vector, the shape is [n]
.
When the expression is a matrix, the shape is [n, m]
.
Readonly
subexpressionsAll the subexpressions in this expression, recursively
Note applicable to canonical and non-canonical expressions.
Readonly
symbolFor symbols, a possible definition associated with the expression.
Note undefined
if not a symbol
Readonly
symbolsAll the symbols in the expression, recursively
Note applicable to canonical and non-canonical expressions.
Readonly
unknownsAll the identifiers used in the expression that do not have a value associated with them, i.e. they are declared but not defined.
Readonly
urlAn optional URL pointing to more information about the symbol or function head.
Note undefined
if not a canonical expression.
Readonly
wikidataWikidata identifier.
Note undefined
if not a canonical expression.
Return the canonical form of this expression.
If this is a function expressin, a definition is associated with the canonical expression.
When determining the canonical form the following function definition flags are applied:
associative
: \( f(a, f(b), c) \longrightarrow f(a, b, c) \)idempotent
: \( f(f(a)) \longrightarrow f(a) \)involution
: \( f(f(a)) \longrightarrow a \)commutative
: sort the arguments.If his expression is already canonical, the value of canonical is
this
.
The domain of the value of this expression.
If a function expression, the domain of the value of the function (the codomain of the function).
If a symbol the domain of the value of the symbol.
Use expr.head
to determine if an expression is a symbol or function
expression.
Note: if non-canonical or not valid, return undefined
.
Modify the domain of a symbol.
Note: If non-canonical, does nothing.
If true
, this expression is in a canonical form.
Note applicable to canonical and non-canonical expressions.
Internal
For internal use only, set when a canonical expression is created.
LaTeX representation of this expression.
The serialization can be customized with ComputeEngine.latexOptions
Note applicable to canonical and non-canonical expressions.
Internal
Note applicable to canonical and non-canonical expressions.
Return a JavaScript primitive representing the value of this expression.
Equivalent to expr.N().valueOf()
.
Only the value of variables can be changed (symbols that are not constants).
Throws a runtime error if a constant.
Note: If non-canonical, does nothing.
Return the number of exprs that matched the pattern
Optional
options: PatternMatchOptionsReturn the value of the canonical form of this expression.
A pure expression always return the same value and has no side effects.
If expr.isPure
is true
, expr.value
and expr.evaluate()
are
synonyms.
For an impure expression, expr.value
is undefined.
Evaluating an impure expression may have some side effects, for
example modifying the ComputeEngine
environment, such as its set of
assumptions.
Only exact calculations are performed, no approximate calculations on decimal numbers (non-integer numbers). Constants, rational numbers and square root of rational numbers are preserved.
To perform approximate calculations, use expr.N()
instead.
The result of expr.evaluate()
may be the same as expr.simplify()
.
The result is in canonical form.
Optional
options: EvaluateOptionsAll the subexpressions matching the head
Note applicable to canonical and non-canonical expressions.
Internal
Infer the domain of this expression.
If the domain of this expression is already known, return false
.
If the domain was not set, set it to the inferred domain, return true
If the domain was previously inferred, adjust it by widening it,
return true
Attempt to match this expression to the rhs
expression.
If rhs
does not match, return null
.
Otherwise return an object literal.
If this expression includes wildcards (symbols with a name that starts
with _
), the object literal will include a prop for each matching named
wildcard.
If rhs
matches this pattern but there are no named wildcards, return
the empty object literal, {}
.
Note applicable to canonical and non-canonical expressions.
Optional
options: PatternMatchOptionsReturn a numeric approximation of the canonical form of this expression.
Any necessary calculations, including on decimal numbers (non-integers), are performed.
The calculations are performed according to the numericMode
and
precision
properties of the ComputeEngine
.
To only perform exact calculations, use this.evaluate()
instead.
If the function is not numeric, the result of this.N()
is the same as
this.evaluate()
.
The result is in canonical form.
Optional
options: NOptionsTransform the expression by applying the rules:
if the lhs
of a rule matches, it is replaced by its rhs
.
If no rules apply, return null
.
See also subs
for a simple substitution.
Note applicable to canonical and non-canonical expressions.
Optional
options: ReplaceOptionsReturn a simpler form of the canonical form of this expression.
A series of rewriting rules are applied repeatedly, until no more rules apply.
If a custom simplify
handler is associated with this function
definition, it is invoked.
The values assigned to symbols and the assumptions about symbols may be
used, for example arg.isInteger
or arg.isPositive
.
No calculations involving decimal numbers (numbers that are not integers) are performed but exact calculations may be performed, for example:
\( \sin(\frac{\pi}{4}) \longrightarrow \frac{\sqrt{2}}{2} \).
The result is in canonical form.
Optional
options: SimplifyOptionsReplace all the symbols in the expression as indicated.
Note the same effect can be achieved with this.replace()
, but
using this.subs()
is more efficient, and simpler.
Note applicable to canonical and non-canonical expressions.
Optional
options: { Optional
canonical?: booleanIf expr
matches the pattern, return true
, otherwise false
Optional
options: PatternMatchOptionsUsed by JSON.stringify()
to serialize this object to JSON.
Method version of expr.json
.
From Object.toString()
, return a string representation of the
expression. This string is suitable to be output to the console
for debugging, for example. To get a LaTeX representation of the
expression, use expr.latex
.
Used when coercing a BoxedExpression
to a String
.
From Object.valueOf()
, return a primitive value for the expression.
If the expression is a machine number, or bignum or rational that can be
converted to a machine number, return a JavaScript number
.
If the expression is a symbol, return the name of the symbol as a string
.
Otherwise return a JavaScript primitive representation of the expression.
Mathematical equality (strong equality), that is the value
of this expression and of rhs
are numerically equal.
The numeric value of both expressions are compared.
Numbers whose difference is less than engine.tolerance
are
considered equal. This tolerance is set when the engine.precision
is
changed to be such that the last two digits are ignored.
The numeric value of both expressions are compared.
The numeric value of both expressions are compared.
If the expressions cannot be compared, return undefined
The numeric value of both expressions are compared.
The numeric value of both expressions are compared.
Structural/symbolic equality (weak equality).
ce.parse('1+x').isSame(ce.parse('x+1'))
is false
Note applicable to canonical and non-canonical expressions.
Readonly
stringIf this expression is a string, return the value of the string.
Otherwise, return null
.
Note applicable to canonical and non-canonical expressions.
Readonly
istrue
if this expression or any of its subexpressions is an ["Error"]
expression.
Note applicable to canonical and non-canonical expressions. For non-canonical expression, this may indicate a syntax error while parsing LaTeX. For canonical expression, this may indicate argument domain mismatch, or missing or unexpected arguments.
Readonly
symbolIf this expression is a symbol, return the name of the symbol as a string.
Otherwise, return null
.
Note applicable to canonical and non-canonical expressions.
THEORY OF OPERATIONS
The
BoxedExpression
interface includes most of the member functions applicable to any kind of expression, for exampleget symbol()
orget ops()
.When a member function is not applicable to this
BoxedExpression
, for exampleget symbol()
on aBoxedNumber
, it returnsnull
.This convention makes it convenient to manipulate expressions without having to check what kind of instance they are before manipulating them.