Construct a new ComputeEngine instance.
Identifier tables define functions and symbols (in options.ids).
If no table is provided the MathJSON Standard Library is used (ComputeEngine.getStandardLibrary())
The LaTeX syntax dictionary is defined in options.latexDictionary.
The order of the dictionaries matter: the definitions from the later ones
override the definitions from earlier ones. The first dictionary should
be the 'core' dictionary which include some basic definitions such
as domains (Booleans, Numbers, etc...) that are used by later
dictionaries.
Optionaloptions: {Optionalids?: readonly Readonly<{ [id: string]: IdentifierDefinition }>[]OptionalnumericMode?: NumericModeThe default mode is "auto". Use "machine"
to perform numeric calculations using 64-bit floats. Use "bignum" to
perform calculations using arbitrary precision floating point numbers.
Use "auto" or "complex" to allow calculations on complex numbers.
OptionalnumericPrecision?: numberSpecific how many digits of precision for the numeric calculations. Default is 100.
Optionaltolerance?: numberIf the absolute value of the difference of two
numbers is less than tolerance, they are considered equal. Used by
chop() as well.
Internal_Internal_Internal_Internal_Internal_Internal_Internal_Internal_ReadonlyAnythingReadonlyBooleansReadonlyComplexThe current scope.
A scope stores the definition of symbols and assumptions.
Scopes form a stack, and definitions in more recent scopes can obscure definitions from older scopes.
The ce.context property represents the current scope.
Optional InternaldeadlineAbsolute time beyond which evaluation should not proceed.
ReadonlyEReadonlyFalseReadonlyHalfReadonlyIReadonlyNaReadonlyNegativeReadonlyNegativeReadonlyNothingReadonlyNumbersReadonlyOneReadonlyPiReadonlyPositiveIn strict mode (the default) the Compute Engine performs validation of domains and signature and may report errors.
When strict mode is off, results may be incorrect or generate JavaScript errors if the input is not valid.
ReadonlyStringsReadonlyTrueReadonlyVoidReadonlyZeroExperimentaliterationExperimentalOptions to control the serialization to MathJSON when using BoxedExpression.json.
Options to control the serialization of MathJSON expression to LaTeX
when using this.latex or this.engine.serialize().
{@inheritDoc NumberFormattingOptions}
The numeric evaluation mode:
| Mode | |
|---|---|
"auto" |
Use bignum or complex numbers. |
"machine" |
IEEE 754-2008, 64-bit floating point numbers: 52-bit mantissa, about 15 digits of precision |
"bignum" |
Arbitrary precision floating point numbers, as provided by the "decimal.js" library |
"complex" |
Complex number represented by two machine numbers, a real and an imaginary part, as provided by the "complex.js" library |
The numeric evaluation mode:
| Mode | |
|---|---|
"auto" |
Use bignum or complex numbers. |
"machine" |
IEEE 754-2008, 64-bit floating point numbers: 52-bit mantissa, about 15 digits of precision |
"bignum" |
Arbitrary precision floating point numbers, as provided by the "decimal.js" library |
"complex" |
Complex number represented by two machine numbers, a real and an imaginary part, as provided by the "complex.js" library |
The precision, or number of significant digits, of numeric
calculations when the numeric mode is "auto" or "bignum".
To make calculations using more digits, at the cost of expanded memory
usage and slower computations, set the precision higher.
If the numeric mode is not "auto" or "bignum", it is set to "auto".
Trigonometric operations are accurate for precision up to 1,000.
ExperimentalrecursionExperimentalExperimentaltimeExperimentalValues smaller than the tolerance are considered to be zero for the
purpose of comparison, i.e. if |b - a| <= tolerance, b is considered
equal to a.
InternalSame as assign(), but for internal use:
InternalOptionalmetadata: MetadataInternalOptionaloptions: { details?: boolean; maxDepth?: number }Optionalscope: null | RuntimeScopeOptionaldepth: numberShortcut for this.fn("Add"...).
The result is canonical.
Optionalmetadata: MetadataOptionalmetadata: MetadataReturn a list of all the assumptions that match a pattern.
ce.assume(['Element', 'x', 'PositiveIntegers');
ce.ask(['Greater', 'x', '_val'])
// -> [{'val': 0}]
Assign a value to an identifier in the current scope.
Use undefined to reset the identifier to no value.
The identifier should be a valid MathJSON identifier not a LaTeX string.
The identifier can take the form "f(x, y") to create a function with two parameters, "x" and "y".
If the id was not previously declared, an automatic declaration
is done. The domain of the identifier is inferred from the value.
To more precisely define the domain of the identifier, use ce.declare()
instead, which allows you to specify the domain, value and other
attributes of the identifier.
Assign a value to an identifier in the current scope.
Use undefined to reset the identifier to no value.
The identifier should be a valid MathJSON identifier not a LaTeX string.
The identifier can take the form "f(x, y") to create a function with two parameters, "x" and "y".
If the id was not previously declared, an automatic declaration
is done. The domain of the identifier is inferred from the value.
To more precisely define the domain of the identifier, use ce.declare()
instead, which allows you to specify the domain, value and other
attributes of the identifier.
Add an assumption.
Note that the assumption is put into canonical form before being added.
Create an arbitrary precision number.
The return value is an object with methods to perform arithmetic operations:
toNumber(): convert to a JavaScript number with potential loss of precision
add()
sub()
neg() (unary minus)
mul()
div()
pow()
sqrt() (square root)
cbrt() (cube root)
exp() (e^x)
log()
ln() (natural logarithm)
mod()
abs()
ceil()
floor()
round()
equals()
gt()
gte()
lt()
lte()
cos()
sin()
tanh()
acos()
asin()
atan()
cosh()
sinh()
acosh()
asinh()
atanh()
isFinite()
isInteger()
isNaN()
isNegative()
isPositive()
isZero()
sign() (1, 0 or -1)
Return a boxed expression from the input.
Optionaloptions: { canonical?: boolean | CanonicalForm | CanonicalForm[] }InternalReplace a number that is close to 0 with the exact integer 0.
How close to 0 the number has to be to be considered 0 is determined by tolerance.
Create a complex number. The return value is an object with methods to perform arithmetic operations:
re (real part, as a JavaScript number)
im (imaginary part, as a JavaScript number)
add()
sub()
neg() (unary minus)
mul()
div()
pow()
sqrt() (square root)
exp() (e^x)
log()
ln() (natural logarithm)
mod()
abs()
ceil()
floor()
round()
arg() the angle of the complex number
inverse() the inverse of the complex number 1/z
conjugate() the conjugate of the complex number
equals()
cos()
sin()
tanh()
acos()
asin()
atan()
cosh()
sinh()
acosh()
asinh()
atanh()
isFinite()
isNaN()
isZero()
sign() (1, 0 or -1)
Declare an identifier: specify their domain, and other attributes, including optionally a value.
Once the domain of an identifier has been declared, it cannot be changed. The domain information is used to calculate the canonical form of expressions and ensure they are valid. If the domain could be changed after the fact, previously valid expressions could become invalid.
Use the Anyting domain for a very generic domain.
Declare an identifier: specify their domain, and other attributes, including optionally a value.
Once the domain of an identifier has been declared, it cannot be changed. The domain information is used to calculate the canonical form of expressions and ensure they are valid. If the domain could be changed after the fact, previously valid expressions could become invalid.
Use the Anyting domain for a very generic domain.
InternalAssociate a new delookupSymbolfinition to a function in the current context.
If a definition existed previously, it is replaced.
For internal use. Use ce.declare() instead.
InternalAssociate a new definition to a symbol in the current context.
If a definition existed previously, it is replaced.
For internal use. Use ce.declare() instead.
Shortcut for this.fn("Divide", [num, denom])
The result is canonical.
Optionalmetadata: MetadataReturn a canonical boxed domain.
If the domain is invalid, may return an ["Error"] expression
Optionalmetadata: MetadataOptionalwhere: SemiBoxedExpressionShortcut for this.fn("Error"...).
The result is canonical.
Optionalwhere: SemiBoxedExpressionReturn a function expression.
Note that the result may not be a function, or may have a different
head than the one specified.
For example:
ce.fn("Rational", [ce.number(1), ce.number(2)])) ( \to ) ce.number([1,2])
Optionaloptions: { canonical: boolean }Remove all assumptions about one or more symbols
Shortcut for this.fn("Divide", [1, expr])
The result is canonical.
Optionalmetadata: MetadataReturn the definition for a function matching this head.
Start looking in the current context, than up the scope chain.
This is a very rough lookup, since it doesn't account for the domain
of the argument or the codomain. However, it is useful during parsing
to differentiate between symbols that might represent a function application, e.g. f vs x.
Optionalscope: null | RuntimeScopeReturn a matching symbol definition, starting with the current scope and going up the scope chain. Prioritize finding a match by wikidata, if provided.
Optionalwikidata: stringOptionalscope: RuntimeScopeShortcut for this.fn("Multiply"...)
The result is canonical.
Optionalmetadata: MetadataShortcut for this.fn("Negate", [expr])
The result is canonical.
Optionalmetadata: MetadataThis function tries to avoid creating a boxed number if num corresponds
to a common value for which we have a shared instance (-1, 0, NaN, etc...)
Optionaloptions: { canonical?: boolean; metadata?: Metadata }Shortcut for this.fn("Pair"...)
The result is canonical.
Optionalmetadata: MetadataParse a string of LaTeX and return a corresponding BoxedExpression.
The result may not be canonical.
Optionaloptions: { canonical?: boolean | CanonicalForm | CanonicalForm[] }Parse a string of LaTeX and return a corresponding BoxedExpression.
The result may not be canonical.
Optionaloptions: { canonical?: boolean | CanonicalForm | CanonicalForm[] }Parse a string of LaTeX and return a corresponding BoxedExpression.
The result may not be canonical.
Optionaloptions: { canonical?: boolean | CanonicalForm | CanonicalForm[] }Remove the most recent scope from the scope stack, and set its parent scope as current.
Shortcut for this.fn("Power"...)
The result is canonical.
Optionalmetadata: MetadataCreate a new scope and add it to the top of the scope stack
The scope argument can be used to specify custom precision,
etc... for this scope
InternalAfter the configuration of the engine has changed, clear the caches so that new values can be recalculated.
This needs to happen for example when the numeric precision changes.
InternalReset the value of any identifiers that have been assigned a value in the current scope.
Serialize a BoxedExpression or a MathJSON expression to
a LaTeX string
Optionaloptions: { canonical?: boolean }InternalReturn false if the execution should stop.
This can occur if:
Shortcut for this.fn("Sqrt"...)
The result is canonical.
Optionalmetadata: MetadataOptionalmetadata: MetadataSet the current scope, return the previous scope.
Return a boxed symbol
Optionaloptions: { canonical?: boolean; metadata?: Metadata }Shortcut for this.fn("Tuple"...)
The result is canonical.
Optionalmetadata: MetadataShortcut for this.fn("Tuple"...)
The result is canonical.
Optionalmetadata: MetadataAnswer a query based on the current assumptions.
StaticgetOptionaldomain: "all" | LibraryCategoryStaticgetReturn identifier tables suitable for the specified categories, or "all"
for all categories ("arithmetic", "algebra", etc...).
An identifier table defines how the symbols and function names in a MathJSON expression should be interpreted, i.e. how to evaluate and manipulate them.
Optionalcategories: "all" | LibraryCategory | LibraryCategory[]
To use the CortexJS Compute Engine, create a
ComputeEngineinstance, or if using a mathfield, use the default Compute Engine instance from theMathfieldElementclass:ce = MathfieldElement.computeEngine.Use the instance to create boxed expressions with
ce.parse()andce.box().