@cortex-js/compute-engine 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/compute-engine.esm.js +7319 -5823
- package/dist/compute-engine.js +7319 -5823
- package/dist/compute-engine.min.esm.js +47 -25822
- package/dist/compute-engine.min.js +19 -25805
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -281
- package/dist/types/common/ansi-codes.d.ts +15 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +15 -19
- package/dist/types/compute-engine/boxed-expression/box.d.ts +8 -3
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +9 -9
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +16 -28
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +27 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +9 -21
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +6 -5
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +4 -4
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +13 -12
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +21 -15
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +30 -9
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +32 -12
- package/dist/types/compute-engine/compile.d.ts +18 -2
- package/dist/types/compute-engine/compute-engine.d.ts +77 -55
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +4 -21
- package/dist/types/compute-engine/function-utils.d.ts +124 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +31 -13
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +2 -2
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +3 -2
- package/dist/types/compute-engine/library/calculus.d.ts +2 -2
- package/dist/types/compute-engine/library/collections.d.ts +2 -2
- package/dist/types/compute-engine/library/complex.d.ts +2 -2
- package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -2
- package/dist/types/compute-engine/library/domains.d.ts +9 -9
- package/dist/types/compute-engine/library/library.d.ts +7 -5
- package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
- package/dist/types/compute-engine/library/logic.d.ts +2 -2
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/sets.d.ts +2 -2
- package/dist/types/compute-engine/library/statistics.d.ts +2 -2
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
- package/dist/types/compute-engine/library/utils.d.ts +1 -3
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +3 -2
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric.d.ts +61 -3
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +281 -189
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +20 -0
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -2
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +5 -3
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +4 -3
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +25 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.17.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module ComputeEngine
|
|
9
9
|
*/
|
|
10
|
-
import type { Decimal } from 'decimal.js';
|
|
11
10
|
import type { Complex } from 'complex.js';
|
|
11
|
+
import type { Decimal } from 'decimal.js';
|
|
12
12
|
import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
13
13
|
import type { LatexDictionaryEntry, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
14
14
|
export * from './latex-syntax/public';
|
|
@@ -35,6 +35,7 @@ export type Metadata = {
|
|
|
35
35
|
</div>
|
|
36
36
|
*/
|
|
37
37
|
export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
|
|
38
|
+
export type Hold = 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
38
39
|
/** Options for `BoxedExpression.simplify()` */
|
|
39
40
|
export type SimplifyOptions = {
|
|
40
41
|
recursive?: boolean;
|
|
@@ -42,9 +43,10 @@ export type SimplifyOptions = {
|
|
|
42
43
|
};
|
|
43
44
|
/** Options for `BoxedExpression.evaluate()`
|
|
44
45
|
*
|
|
45
|
-
* @internal
|
|
46
46
|
*/
|
|
47
|
-
export type EvaluateOptions = {
|
|
47
|
+
export type EvaluateOptions = {
|
|
48
|
+
numericMode?: boolean;
|
|
49
|
+
};
|
|
48
50
|
/** Options for `BoxedExpression.N()`
|
|
49
51
|
* @internal
|
|
50
52
|
*/
|
|
@@ -126,49 +128,24 @@ export type BoxedRule = [
|
|
|
126
128
|
export type BoxedRuleSet = Set<BoxedRule>;
|
|
127
129
|
export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
128
130
|
/** A domain constructor is the head of a domain expression. */
|
|
129
|
-
export type DomainConstructor = '
|
|
130
|
-
export type DomainLiteral =
|
|
131
|
-
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [
|
|
131
|
+
export type DomainConstructor = 'FunctionOf' | 'ListOf' | 'DictionaryOf' | 'TupleOf' | 'Intersection' | 'Union' | 'OptArg' | 'VarArg' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
|
|
132
|
+
export type DomainLiteral = 'Anything' | 'Values' | 'Domains' | 'Void' | 'NothingDomain' | 'Booleans' | 'Strings' | 'Symbols' | 'Collections' | 'Lists' | 'Dictionaries' | 'Sequences' | 'Tuples' | 'Sets' | 'Functions' | 'Predicates' | 'LogicOperators' | 'RelationalOperators' | 'NumericFunctions' | 'RealFunctions' | 'Numbers' | 'ComplexNumbers' | 'ExtendedRealNumbers' | 'ImaginaryNumbers' | 'Integers' | 'Rationals' | 'PositiveNumbers' | 'PositiveIntegers' | 'NegativeNumbers' | 'NegativeIntegers' | 'NonNegativeNumbers' | 'NonNegativeIntegers' | 'NonPositiveNumbers' | 'NonPositiveIntegers' | 'ExtendedComplexNumbers' | 'TranscendentalNumbers' | 'AlgebraicNumbers' | 'RationalNumbers' | 'RealNumbers';
|
|
133
|
+
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | ['Union', ...(DomainExpression<T> | BoxedExpression)[]] | ['Intersection', ...(DomainExpression<T> | BoxedExpression)[]] | ['ListOf', DomainExpression<T>] | ['DictionaryOf', DomainExpression<T>] | ['TupleOf', ...DomainExpression<T>[]] | ['OptArg', ...DomainExpression<T>[]] | ['VarArg', DomainExpression<T>] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['FunctionOf', ...DomainExpression<T>[]];
|
|
132
134
|
export interface BoxedDomain extends BoxedExpression {
|
|
133
|
-
is(s: BoxedDomain): boolean;
|
|
134
|
-
/** True if a valid domain, and compatible with `dom` */
|
|
135
|
-
isCompatible(dom: BoxedDomain | DomainLiteral, kind?: DomainCompatibility): boolean;
|
|
136
|
-
get literal(): string | null;
|
|
137
|
-
get ctor(): DomainConstructor | null;
|
|
138
|
-
get domainArgs(): (DomainExpression<BoxedExpression> | BoxedExpression | string)[] | null;
|
|
139
|
-
get domainArg1(): string | BoxedExpression | DomainExpression<BoxedExpression> | null;
|
|
140
|
-
get codomain(): BoxedDomain | null;
|
|
141
135
|
get canonical(): BoxedDomain;
|
|
142
136
|
get json(): Expression;
|
|
143
|
-
|
|
137
|
+
/** True if a valid domain, and compatible with `dom`
|
|
138
|
+
* `kind` is '"covariant"' by default, i.e. `this <: dom`
|
|
139
|
+
*/
|
|
140
|
+
isCompatible(dom: BoxedDomain | DomainLiteral, kind?: DomainCompatibility): boolean;
|
|
141
|
+
get base(): DomainLiteral;
|
|
142
|
+
get ctor(): DomainConstructor | null;
|
|
143
|
+
get params(): BoxedDomain[];
|
|
144
|
+
get optParams(): BoxedDomain[];
|
|
145
|
+
get restParam(): BoxedDomain | null;
|
|
146
|
+
get result(): BoxedDomain | null;
|
|
144
147
|
readonly isNumeric: boolean;
|
|
145
148
|
readonly isFunction: boolean;
|
|
146
|
-
/**
|
|
147
|
-
* If true, when all the arguments are numeric, the result of the
|
|
148
|
-
* evaluation is numeric. Numeric is any value with a domain of `Number`.
|
|
149
|
-
*
|
|
150
|
-
* Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
|
|
151
|
-
*
|
|
152
|
-
* Default: `false`
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* If true, when all the arguments are boolean, the result of the
|
|
156
|
-
* evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
|
|
157
|
-
*
|
|
158
|
-
* Example of logic functions: `And`, `Or`, `Not`, `Implies`
|
|
159
|
-
*
|
|
160
|
-
* **Default:** `false`
|
|
161
|
-
*/
|
|
162
|
-
/**
|
|
163
|
-
* The function represent a relation between the first argument and
|
|
164
|
-
* the second argument, and evaluates to a boolean indicating if the relation
|
|
165
|
-
* is satisfied.
|
|
166
|
-
*
|
|
167
|
-
* For example, `Equal`, `Less`, `Approx`, etc...
|
|
168
|
-
*
|
|
169
|
-
* **Default:** `false`
|
|
170
|
-
*/
|
|
171
|
-
readonly isRelationalOperator: boolean;
|
|
172
149
|
}
|
|
173
150
|
/**
|
|
174
151
|
* Options to control the serialization to MathJSON when using `BoxedExpression.json`.
|
|
@@ -216,7 +193,7 @@ export type JsonSerializationOptions = {
|
|
|
216
193
|
precision: 'auto' | 'max' | number;
|
|
217
194
|
};
|
|
218
195
|
/**
|
|
219
|
-
*
|
|
196
|
+
* ## THEORY OF OPERATIONS
|
|
220
197
|
*
|
|
221
198
|
* The `BoxedExpression` interface includes most of the member functions
|
|
222
199
|
* applicable to any kind of expression, for example `get symbol()` or
|
|
@@ -350,17 +327,29 @@ export interface BoxedExpression {
|
|
|
350
327
|
*
|
|
351
328
|
*/
|
|
352
329
|
readonly subexpressions: BoxedExpression[];
|
|
353
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
*
|
|
332
|
+
* All the symbols in the expression, recursively
|
|
354
333
|
*
|
|
355
334
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
356
335
|
*
|
|
357
336
|
*/
|
|
358
337
|
readonly symbols: string[];
|
|
359
338
|
/**
|
|
360
|
-
* All the
|
|
361
|
-
*
|
|
339
|
+
* All the identifiers used in the expression that do not have a value
|
|
340
|
+
* associated with them, i.e. they are declared but not defined.
|
|
341
|
+
*/
|
|
342
|
+
readonly unknowns: string[];
|
|
343
|
+
/**
|
|
344
|
+
*
|
|
345
|
+
* All the identifiers (symbols and functions) in the expression that are a
|
|
346
|
+
* free variable.
|
|
347
|
+
*
|
|
348
|
+
* A free variable is an identifier that is used in a function but is not a
|
|
349
|
+
* local variable or a parameter of that function.
|
|
350
|
+
*
|
|
362
351
|
*/
|
|
363
|
-
readonly
|
|
352
|
+
readonly freeVariables: string[];
|
|
364
353
|
/** All the `["Error"]` subexpressions
|
|
365
354
|
*
|
|
366
355
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
@@ -462,8 +451,6 @@ export interface BoxedExpression {
|
|
|
462
451
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
463
452
|
*/
|
|
464
453
|
readonly isPure: boolean;
|
|
465
|
-
/** True if the expression is a free variable, that is a symbol with no value */
|
|
466
|
-
readonly isFree: boolean;
|
|
467
454
|
/** True if the expression is a constant, that is a symbol with an immutable value */
|
|
468
455
|
readonly isConstant: boolean;
|
|
469
456
|
/**
|
|
@@ -484,21 +471,6 @@ export interface BoxedExpression {
|
|
|
484
471
|
*
|
|
485
472
|
*/
|
|
486
473
|
get canonical(): BoxedExpression;
|
|
487
|
-
/**
|
|
488
|
-
* If this expression is a function, apply the function `fn` to all its operands.
|
|
489
|
-
*
|
|
490
|
-
* Replace the head of this expression with `head`, if defined.
|
|
491
|
-
*
|
|
492
|
-
* If this expression is a dictionary, return a new dictionary with the values
|
|
493
|
-
* modified by `fn`.
|
|
494
|
-
*
|
|
495
|
-
* If `head` is provided, return a function expression with the modified
|
|
496
|
-
* dictionary as operand, otherwise return the modified dictionary.
|
|
497
|
-
*
|
|
498
|
-
* **Note** applicable to canonical and non-canonical expressions.
|
|
499
|
-
*
|
|
500
|
-
* */
|
|
501
|
-
apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
|
|
502
474
|
/**
|
|
503
475
|
* Replace all the symbols in the expression as indicated.
|
|
504
476
|
*
|
|
@@ -722,12 +694,9 @@ export interface BoxedExpression {
|
|
|
722
694
|
/** Wikidata identifier.
|
|
723
695
|
*
|
|
724
696
|
* **Note** `undefined` if not a canonical expression.
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
697
|
*/
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
/** An optional short description if the symbol or function head.
|
|
698
|
+
readonly wikidata: string | undefined;
|
|
699
|
+
/** An optional short description if a symbol or function expression.
|
|
731
700
|
*
|
|
732
701
|
* May include markdown. Each string is a paragraph.
|
|
733
702
|
*
|
|
@@ -736,7 +705,7 @@ export interface BoxedExpression {
|
|
|
736
705
|
*/
|
|
737
706
|
readonly description: undefined | string[];
|
|
738
707
|
/** An optional URL pointing to more information about the symbol or
|
|
739
|
-
* function head
|
|
708
|
+
* function head.
|
|
740
709
|
*
|
|
741
710
|
* **Note** `undefined` if not a canonical expression.
|
|
742
711
|
*
|
|
@@ -750,13 +719,13 @@ export interface BoxedExpression {
|
|
|
750
719
|
readonly complexity: number | undefined;
|
|
751
720
|
/**
|
|
752
721
|
* For symbols and functions, a possible definition associated with the
|
|
753
|
-
* expression. `
|
|
722
|
+
* expression. `baseDefinition` is the base class of symbol and function
|
|
754
723
|
* definition.
|
|
755
724
|
*
|
|
756
725
|
* **Note** `undefined` if not a canonical expression.
|
|
757
726
|
*
|
|
758
727
|
*/
|
|
759
|
-
readonly
|
|
728
|
+
readonly baseDefinition: BoxedBaseDefinition | undefined;
|
|
760
729
|
/**
|
|
761
730
|
* For functions, a possible definition associated with the expression.
|
|
762
731
|
*
|
|
@@ -772,32 +741,35 @@ export interface BoxedExpression {
|
|
|
772
741
|
*/
|
|
773
742
|
readonly symbolDefinition: BoxedSymbolDefinition | undefined;
|
|
774
743
|
/**
|
|
775
|
-
* The domain of this expression, without accounting for any inferred domain
|
|
776
|
-
* or `ce.defaultDomain`. If no domain has been explicitly set via assignment
|
|
777
|
-
* or via an `.assume()` directive, the `expr.explicitDomain` is `undefined`.
|
|
778
744
|
*
|
|
779
|
-
*
|
|
745
|
+
* Infer the domain of this expression.
|
|
780
746
|
*
|
|
781
|
-
*
|
|
747
|
+
* If the domain of this expression is already known, return `false`.
|
|
782
748
|
*
|
|
783
|
-
*
|
|
749
|
+
* If the domain was not set, set it to the inferred domain, return `true`
|
|
750
|
+
* If the domain was previously inferred, adjust it by widening it,
|
|
751
|
+
* return `true`
|
|
784
752
|
*
|
|
753
|
+
* @internal
|
|
785
754
|
*/
|
|
786
|
-
|
|
755
|
+
infer(domain: BoxedDomain): boolean;
|
|
787
756
|
/**
|
|
788
|
-
* Update the definition associated with this expression,
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
* **Note**: applicable only to canonical expressions
|
|
757
|
+
* Update the definition associated with this expression, using the
|
|
758
|
+
* current scope (`ce.context`).
|
|
792
759
|
*
|
|
793
760
|
* @internal
|
|
794
761
|
*/
|
|
795
|
-
bind(
|
|
762
|
+
bind(): void;
|
|
796
763
|
/**
|
|
764
|
+
*
|
|
765
|
+
* Reset the cached value associated with this expression.
|
|
766
|
+
*
|
|
767
|
+
* Use when the environment has changed, for example the numeric mode
|
|
768
|
+
* or precision, to force the expression to be re-evaluated.
|
|
797
769
|
*
|
|
798
770
|
* @internal
|
|
799
771
|
*/
|
|
800
|
-
|
|
772
|
+
reset(): void;
|
|
801
773
|
/**
|
|
802
774
|
* Return a simpler form of the canonical form of this expression.
|
|
803
775
|
*
|
|
@@ -844,9 +816,7 @@ export interface BoxedExpression {
|
|
|
844
816
|
* The result is in canonical form.
|
|
845
817
|
*
|
|
846
818
|
*/
|
|
847
|
-
evaluate(
|
|
848
|
-
[id: string]: SemiBoxedExpression | null | undefined;
|
|
849
|
-
}): BoxedExpression;
|
|
819
|
+
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
850
820
|
/** Return a numeric approximation of the canonical form of this expression.
|
|
851
821
|
*
|
|
852
822
|
* Any necessary calculations, including on decimal numbers (non-integers),
|
|
@@ -877,32 +847,38 @@ export interface BoxedExpression {
|
|
|
877
847
|
* **Note**: If non-canonical, return the value of its canonical counterpart
|
|
878
848
|
*/
|
|
879
849
|
get value(): BoxedExpression | undefined;
|
|
880
|
-
/**
|
|
850
|
+
/**
|
|
851
|
+
* Only the value of variables can be changed (symbols that are not
|
|
881
852
|
* constants).
|
|
882
853
|
*
|
|
854
|
+
* Throws a runtime error if a constant.
|
|
855
|
+
*
|
|
883
856
|
* **Note**: If non-canonical, does nothing.
|
|
884
857
|
*
|
|
885
858
|
*/
|
|
886
859
|
set value(value: BoxedExpression | number | undefined);
|
|
887
|
-
/**
|
|
860
|
+
/**
|
|
888
861
|
*
|
|
889
|
-
*
|
|
862
|
+
* The domain of the value of this expression.
|
|
863
|
+
*
|
|
864
|
+
* If a function expression, the domain of the value of the function
|
|
865
|
+
* (the codomain of the function).
|
|
890
866
|
*
|
|
891
867
|
* If a symbol the domain of the value of the symbol.
|
|
892
868
|
*
|
|
893
|
-
* Use `expr.head` to determine if an expression is a symbol or function
|
|
869
|
+
* Use `expr.head` to determine if an expression is a symbol or function
|
|
870
|
+
* expression.
|
|
871
|
+
*
|
|
872
|
+
* **Note**: if non-canonical or not valid, return `undefined`.
|
|
894
873
|
*
|
|
895
|
-
* **Note**: If non-canonical, return the domain of its canonical
|
|
896
|
-
* counterpart
|
|
897
874
|
*/
|
|
898
|
-
get domain(): BoxedDomain;
|
|
899
|
-
/** Modify the domain of a symbol
|
|
900
|
-
* (or a function name).
|
|
875
|
+
get domain(): BoxedDomain | undefined;
|
|
876
|
+
/** Modify the domain of a symbol.
|
|
901
877
|
*
|
|
902
878
|
* **Note**: If non-canonical, does nothing.
|
|
903
879
|
*
|
|
904
880
|
*/
|
|
905
|
-
set domain(domain:
|
|
881
|
+
set domain(domain: DomainExpression | BoxedDomain | undefined);
|
|
906
882
|
/** `true` if the value of this expression is a number.
|
|
907
883
|
*
|
|
908
884
|
* `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
|
|
@@ -1020,33 +996,32 @@ export interface ExpressionMapInterface<U> {
|
|
|
1020
996
|
delete(expr: BoxedExpression): void;
|
|
1021
997
|
clear(): void;
|
|
1022
998
|
[Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
|
|
999
|
+
entries(): IterableIterator<[BoxedExpression, U]>;
|
|
1023
1000
|
}
|
|
1024
1001
|
/**
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
* The index of the table is an identifier, the name of the symbol or
|
|
1028
|
-
* function for this definition
|
|
1002
|
+
* A table mapping identifiers to their definition.
|
|
1029
1003
|
*
|
|
1030
|
-
*
|
|
1031
|
-
*
|
|
1004
|
+
* Identifiers should be valid MathJSON identifiers. In addition, the
|
|
1005
|
+
* following rules are recommended:
|
|
1032
1006
|
*
|
|
1033
|
-
* - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1007
|
+
* - Use only latin letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1034
1008
|
* - The first character should be a letter: `/^[a-zA-Z]/`
|
|
1035
1009
|
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1036
1010
|
*
|
|
1011
|
+
* If a semi boxed expression
|
|
1012
|
+
*
|
|
1037
1013
|
*/
|
|
1038
|
-
export type
|
|
1039
|
-
|
|
1040
|
-
|
|
1014
|
+
export type IdentifierDefinition = SymbolDefinition | FunctionDefinition | SemiBoxedExpression;
|
|
1015
|
+
export type IdentifierDefinitions = Readonly<{
|
|
1016
|
+
[id: string]: IdentifierDefinition;
|
|
1017
|
+
}>;
|
|
1041
1018
|
/**
|
|
1042
|
-
* The entries
|
|
1043
|
-
* optimized for faster evaluation.
|
|
1019
|
+
* The entries have been validated and optimized for faster evaluation.
|
|
1044
1020
|
*
|
|
1045
1021
|
* When a new scope is created with `pushScope()` or when creating a new
|
|
1046
|
-
* engine instance, new instances of
|
|
1047
|
-
* as needed.
|
|
1022
|
+
* engine instance, new instances of this type are created as needed.
|
|
1048
1023
|
*/
|
|
1049
|
-
export type
|
|
1024
|
+
export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
|
|
1050
1025
|
/**
|
|
1051
1026
|
* A scope is a set of names in a dictionary that are bound (defined) in
|
|
1052
1027
|
* a MathJSON expression.
|
|
@@ -1064,13 +1039,15 @@ export type RuntimeIdentifierTable = Map<string, BoxedSymbolDefinition | BoxedFu
|
|
|
1064
1039
|
*/
|
|
1065
1040
|
export type Scope = {
|
|
1066
1041
|
/** Signal `timeout` when the execution time for this scope is exceeded.
|
|
1042
|
+
*
|
|
1067
1043
|
* Time in seconds, default 2s.
|
|
1068
1044
|
*
|
|
1069
1045
|
* @experimental
|
|
1070
1046
|
*/
|
|
1071
1047
|
timeLimit: number;
|
|
1072
1048
|
/** Signal `out-of-memory` when the memory usage for this scope is exceeded.
|
|
1073
|
-
*
|
|
1049
|
+
*
|
|
1050
|
+
* Memory is in Megabytes, default: 1Mb.
|
|
1074
1051
|
*
|
|
1075
1052
|
* @experimental
|
|
1076
1053
|
*/
|
|
@@ -1081,8 +1058,8 @@ export type Scope = {
|
|
|
1081
1058
|
* @experimental
|
|
1082
1059
|
*/
|
|
1083
1060
|
recursionLimit: number;
|
|
1084
|
-
/** Signal `iteration-limit-exceeded` when the iteration limit
|
|
1085
|
-
*
|
|
1061
|
+
/** Signal `iteration-limit-exceeded` when the iteration limit
|
|
1062
|
+
* in a loop is exceeded. Default: no limits.
|
|
1086
1063
|
*
|
|
1087
1064
|
* @experimental
|
|
1088
1065
|
*/
|
|
@@ -1090,16 +1067,8 @@ export type Scope = {
|
|
|
1090
1067
|
};
|
|
1091
1068
|
export type RuntimeScope = Scope & {
|
|
1092
1069
|
parentScope?: RuntimeScope;
|
|
1093
|
-
|
|
1070
|
+
ids?: RuntimeIdentifierDefinitions;
|
|
1094
1071
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
1095
|
-
/** The location of the call site that created this scope */
|
|
1096
|
-
origin?: {
|
|
1097
|
-
name?: string;
|
|
1098
|
-
line?: number;
|
|
1099
|
-
column?: number;
|
|
1100
|
-
};
|
|
1101
|
-
/** Free memory should not go below this level for execution to proceed */
|
|
1102
|
-
lowWaterMark?: number;
|
|
1103
1072
|
};
|
|
1104
1073
|
export type BaseDefinition = {
|
|
1105
1074
|
/** A short (about 1 line) description. May contain Markdown. */
|
|
@@ -1229,7 +1198,7 @@ export type FunctionSignature = {
|
|
|
1229
1198
|
/** An optional handler to determine the codomain of the function.
|
|
1230
1199
|
* If not provided, the codomain of the function is determined from `domain`
|
|
1231
1200
|
*/
|
|
1232
|
-
codomain?: (ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null;
|
|
1201
|
+
codomain?: (ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null | undefined;
|
|
1233
1202
|
/**
|
|
1234
1203
|
* Return the canonical form of the expression with the arguments `args`.
|
|
1235
1204
|
*
|
|
@@ -1237,11 +1206,14 @@ export type FunctionSignature = {
|
|
|
1237
1206
|
* can be put in canonical form.
|
|
1238
1207
|
*
|
|
1239
1208
|
* This handler should validate the domain and number of the arguments.
|
|
1209
|
+
*
|
|
1240
1210
|
* If a required argument is missing, it should be indicated with a
|
|
1241
1211
|
* `["Error", "'missing"]` expression. If more arguments than expected
|
|
1242
|
-
* are present, this should be indicated with
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1212
|
+
* are present, this should be indicated with an
|
|
1213
|
+
* ["Error", "'unexpected-argument'"]` error expression
|
|
1214
|
+
*
|
|
1215
|
+
* If the domain of an argument is not compatible, it should be indicated
|
|
1216
|
+
* with an `incompatible-domain` error.
|
|
1245
1217
|
*
|
|
1246
1218
|
* `["Sequence"]` expressions are not folded and need to be handled
|
|
1247
1219
|
* explicitly.
|
|
@@ -1251,10 +1223,11 @@ export type FunctionSignature = {
|
|
|
1251
1223
|
* arguments should be sorted in canonical order.
|
|
1252
1224
|
*
|
|
1253
1225
|
* The handler can make transformations based on the value of the arguments
|
|
1254
|
-
* that are exact and literal
|
|
1255
|
-
*
|
|
1226
|
+
* that are exact and literal (i.e.
|
|
1227
|
+
* `arg.numericValue !== null && arg.isExact`).
|
|
1256
1228
|
*
|
|
1257
|
-
* Values of symbols should not be substituted
|
|
1229
|
+
* Values of symbols should not be substituted, unless they have
|
|
1230
|
+
* a `holdUntil` attribute of `"never"`.
|
|
1258
1231
|
*
|
|
1259
1232
|
* The handler should not consider the value or any assumptions about any
|
|
1260
1233
|
* of the arguments that are symbols or functions (i.e. `arg.isZero`,
|
|
@@ -1284,6 +1257,9 @@ export type FunctionSignature = {
|
|
|
1284
1257
|
* as calculations involving decimal numbers (non-integers). Making exact
|
|
1285
1258
|
* calculations on integers or rationals is OK.
|
|
1286
1259
|
*
|
|
1260
|
+
* Do not reduce constants with a `holdUntil` attribute of `"N"`
|
|
1261
|
+
* or `"evaluate"`.
|
|
1262
|
+
*
|
|
1287
1263
|
* This handler should not have any side-effects: do not modify
|
|
1288
1264
|
* the environment of the `ComputeEngine` instance, do not perform I/O,
|
|
1289
1265
|
* do not do calculations that depend on random values.
|
|
@@ -1294,10 +1270,10 @@ export type FunctionSignature = {
|
|
|
1294
1270
|
*/
|
|
1295
1271
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1296
1272
|
/**
|
|
1297
|
-
* Evaluate
|
|
1273
|
+
* Evaluate a function expression.
|
|
1298
1274
|
*
|
|
1299
|
-
* The arguments have been
|
|
1300
|
-
*
|
|
1275
|
+
* The arguments have been evaluated, except the arguments to which a
|
|
1276
|
+
* `hold` applied.
|
|
1301
1277
|
*
|
|
1302
1278
|
* It is not necessary to further simplify or evaluate the arguments.
|
|
1303
1279
|
*
|
|
@@ -1310,7 +1286,7 @@ export type FunctionSignature = {
|
|
|
1310
1286
|
* - do not reduce rational numbers to decimal (floating point approximation)
|
|
1311
1287
|
* - do not down convert bignums to machine numbers
|
|
1312
1288
|
* - do not reduce square roots of rational numbers
|
|
1313
|
-
* - do not reduce constants with a `
|
|
1289
|
+
* - do not reduce constants with a `holdUntil` attribute of `"N"`
|
|
1314
1290
|
*
|
|
1315
1291
|
* If the expression cannot be evaluated, due to the values, domains, or
|
|
1316
1292
|
* assumptions about its arguments, for example, return `undefined` or
|
|
@@ -1337,19 +1313,19 @@ export type FunctionSignature = {
|
|
|
1337
1313
|
* evaluation, but a literal argument is out of range or
|
|
1338
1314
|
* not of the expected type.
|
|
1339
1315
|
*
|
|
1316
|
+
* Use the value of `ce.numericMode` to determine how to perform
|
|
1317
|
+
* the numeric evaluation.
|
|
1318
|
+
*
|
|
1340
1319
|
* Note that regardless of the current value of `ce.numericMode`, the
|
|
1341
1320
|
* arguments may be boxed numbers representing machine numbers, bignum
|
|
1342
1321
|
* numbers, complex numbers, rationals or big rationals.
|
|
1343
1322
|
*
|
|
1344
|
-
* Use the value of `ce.numericMode` to determine how to perform
|
|
1345
|
-
* the numeric evaluation.
|
|
1346
|
-
*
|
|
1347
1323
|
* If the numeric mode does not allow complex numbers (the
|
|
1348
1324
|
* `engine.numericMode` is not `"complex"` or `"auto"`) and the result of
|
|
1349
1325
|
* the evaluation would be a complex number, return `NaN` instead.
|
|
1350
1326
|
*
|
|
1351
|
-
* If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should
|
|
1352
|
-
* using bignums.
|
|
1327
|
+
* If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should
|
|
1328
|
+
* be done using bignums.
|
|
1353
1329
|
*
|
|
1354
1330
|
* Otherwise, `ce.numericMode` is `"machine", the evaluation should be
|
|
1355
1331
|
* performed using machine numbers.
|
|
@@ -1370,20 +1346,71 @@ export type FunctionSignature = {
|
|
|
1370
1346
|
};
|
|
1371
1347
|
export type BoxedFunctionSignature = {
|
|
1372
1348
|
domain: BoxedDomain;
|
|
1373
|
-
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
|
|
1349
|
+
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null | undefined);
|
|
1374
1350
|
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
|
|
1375
1351
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1376
|
-
evaluate?:
|
|
1352
|
+
evaluate?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1377
1353
|
N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1378
1354
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1379
1355
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
1380
1356
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1381
1357
|
};
|
|
1358
|
+
/**
|
|
1359
|
+
* The handlers are the primitive operations that can be performed on
|
|
1360
|
+
* collections.
|
|
1361
|
+
*
|
|
1362
|
+
* There are two types of collections:
|
|
1363
|
+
* - finite collections, such as lists, tuples, sets, matrices, etc...
|
|
1364
|
+
* The `size()` handler of finite collections returns the number of elements
|
|
1365
|
+
* - infinite collections, such as sequences, ranges, etc...
|
|
1366
|
+
* The `size()` handler of infinite collections returns `Infinity`
|
|
1367
|
+
* Infinite collections are not indexable, they have no `at()` handler.
|
|
1368
|
+
*
|
|
1369
|
+
*/
|
|
1370
|
+
export type CollectionHandlers = {
|
|
1371
|
+
/** Return an iterator
|
|
1372
|
+
* - start is optional and is a 1-based index.
|
|
1373
|
+
* - if start is not specified, start from index 1
|
|
1374
|
+
* - count is optional and is the number of elements to return
|
|
1375
|
+
* - if count is not specified or negative, return all the elements from start to the end
|
|
1376
|
+
*
|
|
1377
|
+
* If there is a `keys()` handler, there is no `iterator()` handler.
|
|
1378
|
+
*/
|
|
1379
|
+
iterator: (expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>;
|
|
1380
|
+
/** Return the element at the specified index.
|
|
1381
|
+
* The first element is `at(1)`, the last element is `at(-1)`.
|
|
1382
|
+
* If the index is <0, return the element at index `size() + index + 1`.
|
|
1383
|
+
* The index can also be a string for example for dictionaries.
|
|
1384
|
+
* If the index is invalid, return `undefined`.
|
|
1385
|
+
*/
|
|
1386
|
+
at: (expr: BoxedExpression, index: number | string) => undefined | BoxedExpression;
|
|
1387
|
+
/** Return the number of elements in the collection.
|
|
1388
|
+
* An empty collection has a size of 0.
|
|
1389
|
+
*/
|
|
1390
|
+
size: (expr: BoxedExpression) => number;
|
|
1391
|
+
/**
|
|
1392
|
+
* If the collection is indexed by strings, return the valid values
|
|
1393
|
+
* for the index.
|
|
1394
|
+
*/
|
|
1395
|
+
keys: (expr: BoxedExpression) => undefined | Iterator<string>;
|
|
1396
|
+
/**
|
|
1397
|
+
* Return the index of the first element that matches the target expression.
|
|
1398
|
+
* The comparison is done using the `target.isEqual()` method.
|
|
1399
|
+
* If the expression is not found, return `undefined`.
|
|
1400
|
+
* If the expression is found, return the index, 1-based.
|
|
1401
|
+
* If the expression is found multiple times, return the index of the first
|
|
1402
|
+
* match.
|
|
1403
|
+
*
|
|
1404
|
+
* From is the starting index for the search. If negative, start from the end
|
|
1405
|
+
* and search backwards.
|
|
1406
|
+
*/
|
|
1407
|
+
indexOf: (expr: BoxedExpression, target: BoxedExpression, from?: number) => number | string | undefined;
|
|
1408
|
+
};
|
|
1382
1409
|
/**
|
|
1383
1410
|
* Definition record for a function.
|
|
1384
1411
|
*
|
|
1385
1412
|
*/
|
|
1386
|
-
export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
1413
|
+
export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> & Partial<FunctionDefinitionFlags> & {
|
|
1387
1414
|
/**
|
|
1388
1415
|
* A number used to order arguments.
|
|
1389
1416
|
*
|
|
@@ -1415,12 +1442,12 @@ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlag
|
|
|
1415
1442
|
*
|
|
1416
1443
|
* **Default**: `"none"`
|
|
1417
1444
|
*/
|
|
1418
|
-
hold?:
|
|
1419
|
-
signature
|
|
1445
|
+
hold?: Hold;
|
|
1446
|
+
signature: FunctionSignature;
|
|
1420
1447
|
};
|
|
1421
|
-
export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
|
|
1448
|
+
export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHandlers> & FunctionDefinitionFlags & {
|
|
1422
1449
|
complexity: number;
|
|
1423
|
-
hold:
|
|
1450
|
+
hold: Hold;
|
|
1424
1451
|
signature: BoxedFunctionSignature;
|
|
1425
1452
|
};
|
|
1426
1453
|
/**
|
|
@@ -1432,7 +1459,7 @@ export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFl
|
|
|
1432
1459
|
* For example, it might be useful to override `algebraic = false`
|
|
1433
1460
|
* for a transcendental number.
|
|
1434
1461
|
*/
|
|
1435
|
-
export type
|
|
1462
|
+
export type NumericFlags = {
|
|
1436
1463
|
number: boolean | undefined;
|
|
1437
1464
|
integer: boolean | undefined;
|
|
1438
1465
|
rational: boolean | undefined;
|
|
@@ -1495,21 +1522,26 @@ export type SymbolAttributes = {
|
|
|
1495
1522
|
};
|
|
1496
1523
|
/**
|
|
1497
1524
|
* A bound symbol (i.e. one with an associated definition) has either a domain
|
|
1498
|
-
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain =
|
|
1525
|
+
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumbers)
|
|
1499
1526
|
*/
|
|
1500
1527
|
export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
|
|
1501
|
-
domain?:
|
|
1502
|
-
/**
|
|
1528
|
+
domain?: DomainLiteral | BoxedDomain;
|
|
1529
|
+
/** If true, the domain is inferred, and could be adjusted later
|
|
1530
|
+
* as more information becomes available or if the symbol is explicitly
|
|
1531
|
+
* declared.
|
|
1532
|
+
*/
|
|
1533
|
+
inferred?: boolean;
|
|
1534
|
+
/** `value` can be a JS function since for some constants, such as
|
|
1503
1535
|
* `Pi`, the actual value depends on the `precision` setting of the
|
|
1504
|
-
* `ComputeEngine` */
|
|
1536
|
+
* `ComputeEngine` and possible other environment settings */
|
|
1505
1537
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1506
|
-
flags?: Partial<
|
|
1538
|
+
flags?: Partial<NumericFlags>;
|
|
1507
1539
|
};
|
|
1508
|
-
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<
|
|
1540
|
+
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<NumericFlags> {
|
|
1509
1541
|
get value(): BoxedExpression | undefined;
|
|
1510
1542
|
set value(val: SemiBoxedExpression | number | undefined);
|
|
1511
1543
|
domain: BoxedDomain | undefined;
|
|
1512
|
-
|
|
1544
|
+
inferredDomain: boolean;
|
|
1513
1545
|
}
|
|
1514
1546
|
export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
|
|
1515
1547
|
export type CompiledExpression = {
|
|
@@ -1522,27 +1554,29 @@ export interface ComputeEngineStats {
|
|
|
1522
1554
|
expressions: null | Set<BoxedExpression>;
|
|
1523
1555
|
highwaterMark: number;
|
|
1524
1556
|
}
|
|
1557
|
+
export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: any, args: any) => BoxedExpression) | undefined;
|
|
1525
1558
|
/** @internal */
|
|
1526
1559
|
export interface IComputeEngine {
|
|
1527
1560
|
latexDictionary: readonly LatexDictionaryEntry[];
|
|
1528
|
-
|
|
1529
|
-
readonly
|
|
1530
|
-
|
|
1531
|
-
readonly
|
|
1532
|
-
|
|
1533
|
-
readonly
|
|
1534
|
-
|
|
1535
|
-
readonly
|
|
1536
|
-
|
|
1537
|
-
readonly
|
|
1538
|
-
|
|
1539
|
-
readonly
|
|
1540
|
-
|
|
1541
|
-
readonly
|
|
1542
|
-
|
|
1543
|
-
readonly
|
|
1544
|
-
|
|
1545
|
-
readonly
|
|
1561
|
+
readonly Anything: BoxedDomain;
|
|
1562
|
+
readonly Void: BoxedDomain;
|
|
1563
|
+
readonly Strings: BoxedDomain;
|
|
1564
|
+
readonly Booleans: BoxedDomain;
|
|
1565
|
+
readonly Numbers: BoxedDomain;
|
|
1566
|
+
readonly True: BoxedExpression;
|
|
1567
|
+
readonly False: BoxedExpression;
|
|
1568
|
+
readonly Pi: BoxedExpression;
|
|
1569
|
+
readonly E: BoxedExpression;
|
|
1570
|
+
readonly Nothing: BoxedExpression;
|
|
1571
|
+
readonly Zero: BoxedExpression;
|
|
1572
|
+
readonly One: BoxedExpression;
|
|
1573
|
+
readonly Half: BoxedExpression;
|
|
1574
|
+
readonly NegativeOne: BoxedExpression;
|
|
1575
|
+
readonly I: BoxedExpression;
|
|
1576
|
+
readonly NaN: BoxedExpression;
|
|
1577
|
+
readonly PositiveInfinity: BoxedExpression;
|
|
1578
|
+
readonly NegativeInfinity: BoxedExpression;
|
|
1579
|
+
readonly ComplexInfinity: BoxedExpression;
|
|
1546
1580
|
/** @internal */
|
|
1547
1581
|
readonly _BIGNUM_NAN: Decimal;
|
|
1548
1582
|
/** @internal */
|
|
@@ -1569,7 +1603,6 @@ export interface IComputeEngine {
|
|
|
1569
1603
|
readonly iterationLimit: number;
|
|
1570
1604
|
/** @experimental */
|
|
1571
1605
|
readonly recursionLimit: number;
|
|
1572
|
-
defaultDomain: null | BoxedDomain;
|
|
1573
1606
|
/** {@inheritDoc NumericMode} */
|
|
1574
1607
|
numericMode: NumericMode;
|
|
1575
1608
|
tolerance: number;
|
|
@@ -1691,12 +1724,21 @@ export interface IComputeEngine {
|
|
|
1691
1724
|
* Associate a new definition to a symbol in the current context.
|
|
1692
1725
|
*
|
|
1693
1726
|
* If a definition existed previously, it is replaced.
|
|
1727
|
+
*
|
|
1728
|
+
*
|
|
1729
|
+
* For internal use. Use `ce.declare()` instead.
|
|
1730
|
+
*
|
|
1731
|
+
* @internal
|
|
1694
1732
|
*/
|
|
1695
1733
|
defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1696
1734
|
/**
|
|
1697
1735
|
* Associate a new definition to a function in the current context.
|
|
1698
1736
|
*
|
|
1699
1737
|
* If a definition existed previously, it is replaced.
|
|
1738
|
+
*
|
|
1739
|
+
* For internal use. Use `ce.declare()` instead.
|
|
1740
|
+
*
|
|
1741
|
+
* @internal
|
|
1700
1742
|
*/
|
|
1701
1743
|
defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1702
1744
|
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
@@ -1726,7 +1768,7 @@ export interface IComputeEngine {
|
|
|
1726
1768
|
* If the domain is invalid, may return an `["Error"]` expression
|
|
1727
1769
|
*
|
|
1728
1770
|
*/
|
|
1729
|
-
domain(domain:
|
|
1771
|
+
domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
|
|
1730
1772
|
/**
|
|
1731
1773
|
* Return a canonical expression.
|
|
1732
1774
|
*
|
|
@@ -1756,6 +1798,7 @@ export interface IComputeEngine {
|
|
|
1756
1798
|
* The result is canonical.
|
|
1757
1799
|
*/
|
|
1758
1800
|
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
1801
|
+
domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
|
|
1759
1802
|
/**
|
|
1760
1803
|
* Add a`["Hold"]` wrapper to `expr.
|
|
1761
1804
|
*/
|
|
@@ -1775,6 +1818,10 @@ export interface IComputeEngine {
|
|
|
1775
1818
|
* The result is canonical.
|
|
1776
1819
|
*/
|
|
1777
1820
|
pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1821
|
+
/** Shortcut for `this.fn("Sqrt"...)`
|
|
1822
|
+
*
|
|
1823
|
+
* The result is canonical.
|
|
1824
|
+
*/
|
|
1778
1825
|
sqrt(base: BoxedExpression, metadata?: Metadata): any;
|
|
1779
1826
|
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
1780
1827
|
*
|
|
@@ -1821,7 +1868,9 @@ export interface IComputeEngine {
|
|
|
1821
1868
|
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
1822
1869
|
* a LaTeX string
|
|
1823
1870
|
*/
|
|
1824
|
-
serialize(expr: SemiBoxedExpression
|
|
1871
|
+
serialize(expr: SemiBoxedExpression, options?: {
|
|
1872
|
+
canonical?: boolean;
|
|
1873
|
+
}): LatexString;
|
|
1825
1874
|
/**
|
|
1826
1875
|
* Options to control the serialization of MathJSON expression to LaTeX
|
|
1827
1876
|
* when using `this.latex` or `this.engine.serialize()`.
|
|
@@ -1837,14 +1886,59 @@ export interface IComputeEngine {
|
|
|
1837
1886
|
/** {@inheritDoc JsonSerializationOptions} */
|
|
1838
1887
|
get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
|
|
1839
1888
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
/**
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1889
|
+
/** Create a new scope on top of the scope stack, and set it as current */
|
|
1890
|
+
pushScope(scope?: Partial<Scope>): IComputeEngine;
|
|
1891
|
+
/** Remove the most recent scope from the scope stack, and set its
|
|
1892
|
+
* parent scope as current. */
|
|
1893
|
+
popScope(): IComputeEngine;
|
|
1894
|
+
/** Set the current scope, return the previous scope. */
|
|
1895
|
+
swapScope(scope: RuntimeScope | null): RuntimeScope | null;
|
|
1896
|
+
/**
|
|
1897
|
+
* Reset the value of any identifiers that have been assigned a value
|
|
1898
|
+
* in the current scope.
|
|
1899
|
+
* @internal */
|
|
1900
|
+
resetContext(): void;
|
|
1901
|
+
/** Assign a value to an identifier in the current scope.
|
|
1902
|
+
* Use `undefined` to reset the identifier to no value.
|
|
1903
|
+
*
|
|
1904
|
+
* The identifier should be a valid MathJSON identifier
|
|
1905
|
+
* not a LaTeX string.
|
|
1906
|
+
*
|
|
1907
|
+
* The identifier can take the form "f(x, y") to create a function
|
|
1908
|
+
* with two parameters, "x" and "y".
|
|
1909
|
+
*
|
|
1910
|
+
* If the id was not previously declared, an automatic declaration
|
|
1911
|
+
* is done. The domain of the identifier is inferred from the value.
|
|
1912
|
+
* To more precisely define the domain of the identifier, use `ce.declare()`
|
|
1913
|
+
* instead, which allows you to specify the domain, value and other
|
|
1914
|
+
* attributes of the identifier.
|
|
1915
|
+
*/
|
|
1916
|
+
assign(ids: {
|
|
1917
|
+
[id: string]: AssignValue;
|
|
1918
|
+
}): IComputeEngine;
|
|
1919
|
+
assign(id: string, value: AssignValue): IComputeEngine;
|
|
1920
|
+
assign(arg1: string | {
|
|
1921
|
+
[id: string]: AssignValue;
|
|
1922
|
+
}, arg2?: AssignValue): IComputeEngine;
|
|
1923
|
+
/**
|
|
1924
|
+
* Declare an identifier: specify their domain, and other attributes,
|
|
1925
|
+
* including optionally a value.
|
|
1926
|
+
*
|
|
1927
|
+
* Once the domain of an identifier has been declared, it cannot be changed.
|
|
1928
|
+
* The domain information is used to calculate the canonical form of
|
|
1929
|
+
* expressions and ensure they are valid. If the domain could be changed
|
|
1930
|
+
* after the fact, previously valid expressions could become invalid.
|
|
1931
|
+
*
|
|
1932
|
+
* Use the `Anyting` domain for a very generic domain.
|
|
1933
|
+
*
|
|
1934
|
+
*/
|
|
1935
|
+
declare(identifiers: {
|
|
1936
|
+
[id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1937
|
+
}): IComputeEngine;
|
|
1938
|
+
declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
1939
|
+
declare(arg1: string | {
|
|
1940
|
+
[id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1941
|
+
}, arg2?: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
1848
1942
|
/**
|
|
1849
1943
|
* Add an assumption.
|
|
1850
1944
|
*
|
|
@@ -1860,13 +1954,11 @@ export interface IComputeEngine {
|
|
|
1860
1954
|
*
|
|
1861
1955
|
*
|
|
1862
1956
|
*/
|
|
1863
|
-
assume(
|
|
1864
|
-
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
1865
|
-
assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
|
|
1957
|
+
assume(predicate: SemiBoxedExpression): AssumeResult;
|
|
1866
1958
|
/** Remove all assumptions about one or more symbols */
|
|
1867
1959
|
forget(symbol?: string | string[]): void;
|
|
1868
1960
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1869
|
-
ask(pattern:
|
|
1961
|
+
ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
|
|
1870
1962
|
/** @internal */
|
|
1871
1963
|
shouldContinueExecution(): boolean;
|
|
1872
1964
|
/** @internal */
|