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.
Optional
options: { Optional
ids?: readonly Readonly<{ Optional
numericThe 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.
Optional
numericSpecific how many digits of precision for the numeric calculations. Default is 100.
Optional
tolerance?: numberIf the absolute value of the difference of two
numbers is less than tolerance
, they are considered equal. Used by
chop()
as well.
Internal
_bignumInternal
_BIGNUM_Internal
_BIGNUM_Internal
_BIGNUM_Internal
_BIGNUM_Internal
_BIGNUM_Internal
_BIGNUM_Internal
_BIGNUM_Readonly
AnythingReadonly
BooleansReadonly
ComplexThe 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
Internal
deadlineAbsolute time beyond which evaluation should not proceed.
Readonly
EReadonly
FalseReadonly
HalfReadonly
IReadonly
NaNReadonly
NegativeReadonly
NegativeReadonly
NothingReadonly
NumbersReadonly
OneReadonly
PiReadonly
PositiveIn 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.
Readonly
StringsReadonly
TrueReadonly
VoidReadonly
ZeroExperimental
iterationExperimental
Options 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.
Experimental
recursionExperimental
Experimental
timeExperimental
Values 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
.
Internal
Same as assign(), but for internal use:
Internal
Optional
metadata: MetadataInternal
Optional
options: { Optional
details?: booleanOptional
maxOptional
scope: null | RuntimeScopeOptional
depth: numberInternal
Internal
Shortcut for this.fn("Add"...)
.
The result is canonical.
Optional
metadata: MetadataOptional
metadata: 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.
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.
Optional
options: { Optional
canonical?: boolean | CanonicalForm | CanonicalForm[]Replace 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.
Internal
Associate 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.
Internal
Associate 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.
Optional
metadata: MetadataReturn a canonical boxed domain.
If the domain is invalid, may return an ["Error"]
expression
Optional
metadata: MetadataOptional
where: SemiBoxedExpressionShortcut for this.fn("Error"...)
.
The result is canonical.
Optional
where: 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])
Optional
options: { Add a["Hold"]
wrapper to `expr.
Shortcut for this.fn("Divide", [1, expr])
The result is canonical.
Optional
metadata: 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
.
Optional
scope: 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.
Optional
wikidata: stringOptional
scope: RuntimeScopeShortcut for this.fn("Multiply"...)
The result is canonical.
Optional
metadata: MetadataShortcut for this.fn("Negate", [expr])
The result is canonical.
Optional
metadata: 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...)
Shortcut for this.fn("Pair"...)
The result is canonical.
Optional
metadata: MetadataParse a string of LaTeX and return a corresponding BoxedExpression
.
The result may not be canonical.
Optional
options: { Optional
canonical?: boolean | CanonicalForm | CanonicalForm[]Optional
options: { Optional
canonical?: boolean | CanonicalForm | CanonicalForm[]Optional
options: { Optional
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.
Optional
metadata: 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
Serialize a BoxedExpression
or a MathJSON
expression to
a LaTeX string
Optional
options: { Optional
canonical?: booleanShortcut for this.fn("Sqrt"...)
The result is canonical.
Optional
metadata: MetadataOptional
metadata: MetadataSet the current scope, return the previous scope.
Return a boxed symbol
Shortcut for this.fn("Tuple"...)
The result is canonical.
Optional
metadata: MetadataOptional
metadata: MetadataAnswer a query based on the current assumptions.
Static
getOptional
domain: "all" | LibraryCategoryStatic
getReturn 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.
Optional
categories: "all" | LibraryCategory | LibraryCategory[]
To use the CortexJS Compute Engine, create a
ComputeEngine
instance, or if using a mathfield, use the default Compute Engine instance from theMathfieldElement
class:ce = MathfieldElement.computeEngine
.Use the instance to create boxed expressions with
ce.parse()
andce.box()
.