@cortex-js/compute-engine 0.5.0 → 0.7.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.
Files changed (91) hide show
  1. package/dist/compute-engine.esm.js +16900 -13123
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +90 -36
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -1
  9. package/dist/types/compute-engine/assume.d.ts +2 -2
  10. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +23 -10
  11. package/dist/types/compute-engine/boxed-expression/box.d.ts +4 -18
  12. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +4 -4
  13. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +49 -6
  14. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +14 -11
  16. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
  17. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +5 -5
  18. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  19. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +10 -7
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +24 -10
  21. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/utils.d.ts +25 -8
  25. package/dist/types/compute-engine/compute-engine.d.ts +73 -47
  26. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  27. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  28. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  29. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -3
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +8 -8
  39. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
  40. package/dist/types/compute-engine/latex-syntax/parse.d.ts +89 -63
  41. package/dist/types/compute-engine/latex-syntax/public.d.ts +85 -67
  42. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +6 -4
  45. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  46. package/dist/types/compute-engine/library/arithmetic-add.d.ts +11 -0
  47. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +15 -0
  48. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +19 -0
  49. package/dist/types/compute-engine/{dictionary → library}/arithmetic-power.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -0
  51. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  52. package/dist/types/compute-engine/library/collections.d.ts +2 -0
  53. package/dist/types/compute-engine/library/core.d.ts +2 -0
  54. package/dist/types/compute-engine/library/domains.d.ts +15 -0
  55. package/dist/types/compute-engine/library/library.d.ts +17 -0
  56. package/dist/types/compute-engine/library/logic.d.ts +2 -0
  57. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  58. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  59. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  60. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  61. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  62. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +5 -1
  63. package/dist/types/compute-engine/numerics/numeric.d.ts +4 -2
  64. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  65. package/dist/types/compute-engine/public.d.ts +265 -219
  66. package/dist/types/compute-engine/rules.d.ts +1 -1
  67. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  68. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  69. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  70. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  71. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  72. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/sum.d.ts +2 -2
  74. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  75. package/dist/types/compute-engine.d.ts +3 -2
  76. package/dist/types/math-json/math-json-format.d.ts +27 -23
  77. package/dist/types/math-json/utils.d.ts +23 -18
  78. package/dist/types/math-json.d.ts +3 -3
  79. package/package.json +21 -22
  80. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +0 -11
  81. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +0 -9
  82. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +0 -17
  83. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +0 -2
  84. package/dist/types/compute-engine/dictionary/collections.d.ts +0 -2
  85. package/dist/types/compute-engine/dictionary/core.d.ts +0 -2
  86. package/dist/types/compute-engine/dictionary/dictionary.d.ts +0 -26
  87. package/dist/types/compute-engine/dictionary/logic.d.ts +0 -2
  88. package/dist/types/compute-engine/dictionary/polynomials.d.ts +0 -2
  89. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +0 -2
  90. package/dist/types/compute-engine/dictionary/sets.d.ts +0 -2
  91. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +0 -2
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -17,18 +17,18 @@ export * from './latex-syntax/public';
17
17
  * Metadata that can be associated with a `BoxedExpression`
18
18
  */
19
19
  export declare type Metadata = {
20
- latex?: string;
21
- wikidata?: string;
20
+ latex?: string | undefined;
21
+ wikidata?: string | undefined;
22
22
  };
23
23
  /**
24
24
  * The numeric evaluation mode:
25
25
  *
26
- * - `auto`: use machine number if precision is 15 or less, allow complex numbers.
27
- * - `machine`: 64-bit float, **IEEE 754-2008**, 64-bit float, 52-bit mantissa,
26
+ * - `"auto"`: use machine number if precision is 15 or less, allow complex numbers.
27
+ * - `"machine"`: 64-bit float, **IEEE 754-2008**, 64-bit float, 52-bit mantissa,
28
28
  * about 15 digits of precision
29
- * - `decimal`: arbitrary precision floating point numbers, as provided by the
29
+ * - `"decimal"`: arbitrary precision floating point numbers, as provided by the
30
30
  * "decimal.js" library
31
- * - `complex`: complex number represented by two machine numbers, a real and
31
+ * - `"complex"`: complex number represented by two machine numbers, a real and
32
32
  * an imaginary part, as provided by the "complex.js" library
33
33
  */
34
34
  export declare type NumericMode = 'auto' | 'machine' | 'decimal' | 'complex';
@@ -49,16 +49,16 @@ export declare type EvaluateOptions = {};
49
49
  */
50
50
  export declare type NOptions = {};
51
51
  export declare type ReplaceOptions = {
52
- /** If true, apply replacement rules to all sub-expressions.
53
- * If false, only consider the top-level expression.
52
+ /** If `true`, apply replacement rules to all sub-expressions.
53
+ * If `false`, only consider the top-level expression.
54
54
  *
55
55
  * **Default**: `true`
56
56
  */
57
57
  recursive?: boolean;
58
58
  /**
59
- * If true, stop after the first rule that matches.
59
+ * If `true`, stop after the first rule that matches.
60
60
  *
61
- * If false, apply all the remaining rules even after the first match.
61
+ * If `false`, apply all the remaining rules even after the first match.
62
62
  *
63
63
  * **Default**: `true`
64
64
  */
@@ -81,6 +81,9 @@ export declare type ReplaceOptions = {
81
81
  * rule whose `lhs` is always a symbol.
82
82
  */
83
83
  export declare type Substitution = {
84
+ [symbol: string]: SemiBoxedExpression;
85
+ };
86
+ export declare type BoxedSubstitution = {
84
87
  [symbol: string]: BoxedExpression;
85
88
  };
86
89
  /** A LaTeX string starts and end with `$`, for example
@@ -111,7 +114,7 @@ export declare type Rule = [
111
114
  lhs: LatexString | SemiBoxedExpression | Pattern,
112
115
  rhs: LatexString | SemiBoxedExpression,
113
116
  options?: {
114
- condition?: LatexString | ((wildcards: Substitution) => boolean);
117
+ condition?: LatexString | ((wildcards: BoxedSubstitution) => boolean);
115
118
  priority?: number;
116
119
  }
117
120
  ];
@@ -119,16 +122,55 @@ export declare type BoxedRule = [
119
122
  lhs: Pattern,
120
123
  rhs: BoxedExpression,
121
124
  priority: number,
122
- condition: undefined | ((wildcards: Substitution) => boolean)
125
+ condition: undefined | ((wildcards: BoxedSubstitution) => boolean)
123
126
  ];
124
127
  export declare type BoxedRuleSet = Set<BoxedRule>;
125
- /**
126
- * Domains can be defined as a union or intersection of domains:
127
- * - `["Union", "Number", "Boolean"]` A number or a boolean.
128
- * - `["SetMinus", "Number", 1]` Any number except "1".
129
- *
130
- */
131
- export declare type DomainExpression = BoxedExpression;
128
+ export declare type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
129
+ /** A domain constructor is the head of a domain expression. */
130
+ export declare type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
131
+ export declare type DomainLiteral = string;
132
+ export declare type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
133
+ export interface BoxedDomain extends BoxedExpression {
134
+ is(s: BoxedDomain): boolean;
135
+ /** True if a valid domain, and compatible with `dom` */
136
+ isCompatible(dom: BoxedDomain | DomainLiteral, kind?: DomainCompatibility): boolean;
137
+ get literal(): string | null;
138
+ get ctor(): DomainConstructor | null;
139
+ get domainArgs(): (DomainExpression<BoxedExpression> | BoxedExpression | string)[] | null;
140
+ get domainArg1(): string | BoxedExpression | DomainExpression<BoxedExpression> | null;
141
+ get codomain(): BoxedDomain | null;
142
+ get canonical(): BoxedDomain;
143
+ get json(): Expression;
144
+ readonly isNothing: boolean;
145
+ readonly isNumeric: boolean;
146
+ readonly isFunction: boolean;
147
+ /**
148
+ * If true, when all the arguments are numeric, the result of the
149
+ * evaluation is numeric. Numeric is any value with a domain of `Number`.
150
+ *
151
+ * Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
152
+ *
153
+ * Default: `false`
154
+ */
155
+ /**
156
+ * If true, when all the arguments are boolean, the result of the
157
+ * evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
158
+ *
159
+ * Example of logic functions: `And`, `Or`, `Not`, `Implies`
160
+ *
161
+ * **Default:** `false`
162
+ */
163
+ /**
164
+ * The function represent a relation between the first argument and
165
+ * the second argument, and evaluates to a boolean indicating if the relation
166
+ * is satisfied.
167
+ *
168
+ * For example, `Equal`, `Less`, `Approx`, etc...
169
+ *
170
+ * **Default:** `false`
171
+ */
172
+ readonly isRelationalOperator: boolean;
173
+ }
132
174
  /**
133
175
  * Options to control the serialization to MathJSON when using `BoxedExpression.json`.
134
176
  */
@@ -148,7 +190,7 @@ export declare type JsonSerializationOptions = {
148
190
  /** A list of space separated keywords indicating which MathJSON expressions
149
191
  * can use a shorthand.
150
192
  *
151
- * **Default**: `['all']`
193
+ * **Default**: `["all"]`
152
194
  */
153
195
  shorthands: ('all' | 'number' | 'symbol' | 'function' | 'dictionary' | 'string')[];
154
196
  /** A list of space separated keywords indicating which metadata should be
@@ -216,7 +258,7 @@ export interface BoxedExpression {
216
258
  * @category Object Methods
217
259
  *
218
260
  */
219
- is(rhs: any): boolean;
261
+ is(rhs: unknown): boolean;
220
262
  /** @internal */
221
263
  get hash(): number;
222
264
  /** An optional short description of the symbol or function head.
@@ -240,7 +282,7 @@ export interface BoxedExpression {
240
282
  get value(): BoxedExpression | undefined;
241
283
  /** Only the value of variables can be changed (symbols that are not constants) */
242
284
  set value(value: BoxedExpression | number | undefined);
243
- /** Return an approximation of the value of this expression. Floating-point
285
+ /** An approximation of the value of this expression. Floating-point
244
286
  * operations may be performed.
245
287
  *
246
288
  * Just like `this.value`, it returns `undefined` for impure expressions.
@@ -257,6 +299,10 @@ export interface BoxedExpression {
257
299
  * As an example, the `Random` function is not pure.
258
300
  */
259
301
  get isPure(): boolean;
302
+ /** True if the expression is a free variable, that is a symbol with no value */
303
+ get isFree(): boolean;
304
+ /** True if the expression is a constant, that is a symbol with an immutable value */
305
+ get isConstant(): boolean;
260
306
  /**
261
307
  * If `true`, this expression represents a value that was not calculated
262
308
  * or that does not reference another expression.
@@ -270,6 +316,14 @@ export interface BoxedExpression {
270
316
  * @internal
271
317
  */
272
318
  set isCanonical(val: boolean);
319
+ /** All the subexpressions matching the head */
320
+ getSubexpressions(head: string): BoxedExpression[];
321
+ /** All the subexpressions in this expression, recursively */
322
+ get subexpressions(): BoxedExpression[];
323
+ /** All the symbols in the expression, recursively */
324
+ get symbols(): BoxedExpression[];
325
+ /** All the `["Error"]` subexpressions */
326
+ get errors(): BoxedExpression[];
273
327
  /** `ops` is the list of arguments of the function, its "tail"
274
328
  *
275
329
  * @category Function Expression
@@ -412,7 +466,7 @@ export interface BoxedExpression {
412
466
  * performed if they are safe from overflow. This method makes it easy
413
467
  * to check for this, whether the value is a Decimal or a number.
414
468
  *
415
- * By default, "small" is less than 10,000.
469
+ * By default, "small" is less than 1,000,000.
416
470
  *
417
471
  * @category Numeric Expression
418
472
  *
@@ -441,8 +495,9 @@ export interface BoxedExpression {
441
495
  * Note that complex numbers have no natural ordering,
442
496
  * so if the value is a complex number, `sgn` is either 0, or `null`
443
497
  *
444
- * If a symbol, this does take assumptions into account, that is `this.sgn` will return
445
- * `1` if `isPositive` is `true`, even if this expression has no value
498
+ * If a symbol, this does take assumptions into account, that is `this.sgn`
499
+ * will return `1` if `isPositive` is `true`, even if this expression has
500
+ * no value
446
501
  *
447
502
  * @category Numeric Expression
448
503
  *
@@ -455,12 +510,17 @@ export interface BoxedExpression {
455
510
  *
456
511
  */
457
512
  get symbol(): string | null;
458
- /** Shortcut for `this.symbol === "Missing"`
513
+ /**
514
+ * If this is the `Nothing`, return `true`.
515
+ */
516
+ get isNothing(): boolean;
517
+ /** `true` if this expression or any subexpression is an `["Error"]`
518
+ * expression.
459
519
  *
460
520
  * @category Symbol Expression
461
521
  *
462
522
  */
463
- get isMissing(): boolean;
523
+ get isValid(): boolean;
464
524
  /** If this expression is a string, return the value of the string.
465
525
  * Otherwise, return `null`.
466
526
  *
@@ -468,18 +528,12 @@ export interface BoxedExpression {
468
528
  *
469
529
  */
470
530
  get string(): string | null;
471
- /** True if this domain is a subset of domain `d`
472
- *
473
- * @category Expression Properties
474
- *
475
- */
476
- isSubsetOf(d: BoxedExpression | string): undefined | boolean;
477
- /** True if the value of this expression is a number.
531
+ /** `true` if the value of this expression is a number.
478
532
  *
479
533
  * `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
480
534
  *
481
535
  * Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
482
- * is a number.
536
+ * **is** a number.
483
537
  *
484
538
  * @category Expression Properties
485
539
  */
@@ -586,7 +640,7 @@ export interface BoxedExpression {
586
640
  *
587
641
  */
588
642
  get isNaN(): boolean | undefined;
589
- /** Not ±Infinity and not `NaN`
643
+ /** This expression is a number, but not ±Infinity and not `NaN`
590
644
  *
591
645
  * @category Expression Properties
592
646
  */
@@ -644,7 +698,7 @@ export interface BoxedExpression {
644
698
  * @category Relational Operator
645
699
  */
646
700
  isEqual(rhs: BoxedExpression): boolean;
647
- /** If the expressions cannot be compared, `undefined` is returned
701
+ /** If the expressions cannot be compared, return `undefined`
648
702
  *
649
703
  * @category Relational Operator
650
704
  */
@@ -666,17 +720,17 @@ export interface BoxedExpression {
666
720
  * @category Expression Properties
667
721
  */
668
722
  get isPositive(): boolean | undefined;
669
- /** The value of this expression is >= 0, same as `isGreaterEqual(0)`
723
+ /** The value of this expression is >= 0, same as `isGreaterEqual(0)`
670
724
  *
671
725
  * @category Expression Properties
672
726
  */
673
727
  get isNonNegative(): boolean | undefined;
674
- /** The value of this expression is < 0, same as `isLess(0)`
728
+ /** The value of this expression is < 0, same as `isLess(0)`
675
729
  *
676
730
  * @category Expression Properties
677
731
  */
678
732
  get isNegative(): boolean | undefined;
679
- /** The value of this expression is <= 0, same as `isLessEqual(0)`
733
+ /** The value of this expression is <= 0, same as `isLessEqual(0)`
680
734
  *
681
735
  * @category Expression Properties
682
736
  */
@@ -693,12 +747,28 @@ export interface BoxedExpression {
693
747
  * first in commutative functions
694
748
  */
695
749
  get complexity(): number;
696
- /** The domain of this expression, using the value of the expression,
697
- * definitions associated with this expression and assumptions if necessary */
698
- get domain(): BoxedExpression;
699
- /** Symbols that represent a variable, can have their domain modified */
700
- set domain(domain: BoxedExpression | string);
701
- /** For symbols and functions, a possible definition associated with the expression */
750
+ /** The domain of this expression. If a function expression, this the domain
751
+ * of the value of the function(the codomain of the function), if a symbol
752
+ * the domain of the value of the symbol.
753
+ */
754
+ get domain(): BoxedDomain;
755
+ /** Symbols that represent a variable (or a function name), can have their
756
+ * domain modified */
757
+ set domain(domain: BoxedDomain | string);
758
+ /**
759
+ * The domain of this expression, without accounting for any inferred domain
760
+ * or `defaultDomain`. If no domain has been explicitly set via assignment
761
+ * or via an `.assume()` directive, the `expr.explicitDomain` is `null.
762
+ *
763
+ * This is useful to determine if the domain of an expression is inferred.
764
+ *
765
+ * In most cases you'll want to use `.domain` instead.
766
+ */
767
+ get explicitDomain(): BoxedDomain | null;
768
+ /** For symbols and functions, a possible definition associated with the
769
+ * expression. `basedDefinition` is the base class of symbol and function
770
+ * definition. */
771
+ get basedDefinition(): BoxedBaseDefinition | undefined;
702
772
  get functionDefinition(): BoxedFunctionDefinition | undefined;
703
773
  get symbolDefinition(): BoxedSymbolDefinition | undefined;
704
774
  /**
@@ -785,6 +855,7 @@ export interface BoxedExpression {
785
855
  solve(vars: Iterable<string>): null | BoxedExpression[];
786
856
  /**
787
857
  * If this expression is a function, apply the function `fn` to all its operands.
858
+ *
788
859
  * Replace the head of this expression with `head`, if defined.
789
860
  *
790
861
  * If this expression is a dictionary, return a new dictionary with the values
@@ -813,16 +884,16 @@ export interface BoxedExpression {
813
884
  subs(sub: Substitution): BoxedExpression;
814
885
  /**
815
886
  * Update the definition associated with this expression, taking
816
- * into account the current context.
887
+ * into account the specified scope.
817
888
  *
818
889
  * @internal
819
890
  */
820
- _repairDefinition(): void;
891
+ bind(scope: RuntimeScope | null): void;
821
892
  /** Purge any cached values.
822
893
  *
823
894
  * @internal
824
895
  */
825
- _purge(): undefined;
896
+ unbind(): void;
826
897
  }
827
898
  /** A semi boxed expression is an MathJSON expression which can include some
828
899
  * boxed terms.
@@ -847,7 +918,7 @@ export interface Pattern extends BoxedExpression {
847
918
  * equal to the expression. If there are no named wildcards and the expression
848
919
  * matches the pattern, and empty object literal `{}` is returned.
849
920
  */
850
- match(expr: BoxedExpression, options?: PatternMatchOption): Substitution | null;
921
+ match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
851
922
  /** If `expr` matches the pattern, return `true`, otherwise `false` */
852
923
  test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
853
924
  /** Return the number of exprs that matched the pattern */
@@ -863,25 +934,25 @@ export interface ExpressionMapInterface<U> {
863
934
  [Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
864
935
  }
865
936
  /**
866
- * A dictionary contains definitions for symbols, functions and rules.
937
+ * A symbol table contains definitions for symbols, functions and rules.
867
938
  *
868
939
  */
869
- export declare type Dictionary = {
940
+ export declare type SymbolTable = {
870
941
  symbols?: SymbolDefinition[];
871
942
  functions?: FunctionDefinition[];
872
943
  simplifyRules?: BoxedRuleSet;
873
944
  };
874
945
  /**
875
- * The entries of a `CompiledDictionary` have been validated and
946
+ * The entries of a `RuntimeSymbolTable` have been validated and
876
947
  * optimized for faster evaluation.
877
948
  *
878
949
  * When a new scope is created with `pushScope()` or when creating a new
879
950
  * engine instance, new instances of `RuntimeDictionary` are created as needed.
880
951
  */
881
- export declare type RuntimeDictionary = {
952
+ export declare type RuntimeSymbolTable = {
882
953
  symbols: Map<string, BoxedSymbolDefinition>;
883
954
  symbolWikidata: Map<string, BoxedSymbolDefinition>;
884
- functions: Map<string, BoxedFunctionDefinition[]>;
955
+ functions: Map<string, BoxedFunctionDefinition>;
885
956
  functionWikidata: Map<string, BoxedFunctionDefinition>;
886
957
  };
887
958
  /**
@@ -930,7 +1001,7 @@ export declare type Scope = {
930
1001
  };
931
1002
  export declare type RuntimeScope = Scope & {
932
1003
  parentScope: RuntimeScope;
933
- dictionary?: RuntimeDictionary;
1004
+ symbolTable?: RuntimeSymbolTable;
934
1005
  assumptions: undefined | ExpressionMapInterface<boolean>;
935
1006
  /** The location of the call site that created this scope */
936
1007
  origin?: {
@@ -949,9 +1020,9 @@ export declare type BaseDefinition = {
949
1020
  * The name of a symbol or function is an arbitrary string of Unicode
950
1021
  * characters, however the following conventions are recommended:
951
1022
  *
952
- * - Use only letters, digits and `-`, and the first character should be
953
- * a letter: `/^[a-zA-Z][a-zA-Z0-9-]+/`
954
- * - Built-in functions and symbols should start with an uppercase letter
1023
+ * - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
1024
+ * - The first character should be a letter: `/^[a-zA-Z]/`
1025
+ * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
955
1026
  *
956
1027
  */
957
1028
  name: string;
@@ -966,20 +1037,8 @@ export declare type BaseDefinition = {
966
1037
  * for the `Pi` constant.
967
1038
  */
968
1039
  wikidata?: string;
969
- /**
970
- * The domain of this item.
971
- *
972
- * For dictionaries, this is the domain of all the items in the dictionary.
973
- *
974
- * For strings, it's always 'String'.
975
- *
976
- * For symbols, this is the domain of their value.
977
- *
978
- * For functions, this is the domain of their result (aka codomain)
979
- */
980
- domain?: BoxedExpression | string;
981
1040
  };
982
- export declare type BoxedBaseDefinition = {
1041
+ export interface BoxedBaseDefinition {
983
1042
  name: string;
984
1043
  wikidata?: string;
985
1044
  description?: string | string[];
@@ -990,32 +1049,35 @@ export declare type BoxedBaseDefinition = {
990
1049
  * This field is usually undefined, but its value is set by `getDefinition()`
991
1050
  */
992
1051
  scope: RuntimeScope | undefined;
993
- domain?: BoxedExpression;
994
- _purge(): undefined;
995
- };
1052
+ /** When the environment changes, for example the numerical precision,
1053
+ * call `reset()` so that any cached values can be recalculated.
1054
+ */
1055
+ reset(): any;
1056
+ }
996
1057
  /**
997
1058
  * A function definition can have some flags to indicate specific
998
1059
  * properties of the function.
999
1060
  */
1000
1061
  export declare type FunctionDefinitionFlags = {
1001
- /** If true, the function is applied element by element to lists, matrices
1002
- * and equations.
1062
+ /** If `true`, the function is applied element by element to lists, matrices
1063
+ * (`["List"]` or `["Tuple"]` expressions) and equations (relational
1064
+ * operators).
1003
1065
  *
1004
1066
  * **Default**: `false`
1005
1067
  */
1006
1068
  threadable: boolean;
1007
- /** If true, `["f", ["f", a], b]` simplifies to `["f", a, b]`
1069
+ /** If `true`, `["f", ["f", a], b]` simplifies to `["f", a, b]`
1008
1070
  *
1009
1071
  * **Default**: `false`
1010
1072
  */
1011
1073
  associative: boolean;
1012
- /** If true, `["f", a, b]` equals `["f", b, a]`. The canonical
1074
+ /** If `true`, `["f", a, b]` equals `["f", b, a]`. The canonical
1013
1075
  * version of the function will order the arguments.
1014
1076
  *
1015
1077
  * **Default**: `false`
1016
1078
  */
1017
1079
  commutative: boolean;
1018
- /** If true, when the function is univariate, `["f", ["Add", x, c]]` where `c`
1080
+ /** If `true`, when the function is univariate, `["f", ["Add", x, c]]` where `c`
1019
1081
  * is constant, is simplified to `["Add", ["f", x], c]`.
1020
1082
  *
1021
1083
  * When the function is multivariate, additivity is considered only on the
@@ -1025,7 +1087,7 @@ export declare type FunctionDefinitionFlags = {
1025
1087
  *
1026
1088
  * **Default**: `false`
1027
1089
  */
1028
- /** If true, when the function is univariate, `["f", ["Multiply", x, y]]`
1090
+ /** If `true`, when the function is univariate, `["f", ["Multiply", x, y]]`
1029
1091
  * simplifies to `["Multiply", ["f", x], ["f", y]]`.
1030
1092
  *
1031
1093
  * When the function is multivariate, multiplicativity is considered only on the
@@ -1034,54 +1096,26 @@ export declare type FunctionDefinitionFlags = {
1034
1096
  *
1035
1097
  * **Default**: `false`
1036
1098
  */
1037
- /** If true, when the function is univariate, `["f", ["Multiply", x, c]]`
1099
+ /** If `true`, when the function is univariate, `["f", ["Multiply", x, c]]`
1038
1100
  * simplifies to `["Multiply", ["f", x], c]` where `c` is constant
1039
1101
  *
1040
- * When the function is multivariate, multiplicativity is considered only on the
1041
- * first argument: `["f", ["Multiply", x, y], z]` simplifies to
1102
+ * When the function is multivariate, multiplicativity is considered only on
1103
+ * the first argument: `["f", ["Multiply", x, y], z]` simplifies to
1042
1104
  * `["Multiply", ["f", x, z], ["f", y, z]]`
1043
1105
  *
1044
1106
  * Default: `false`
1045
1107
  */
1046
- /** If true, `["f", ["f", x]]` simplifies to `["f", x]`.
1108
+ /** If `true`, `["f", ["f", x]]` simplifies to `["f", x]`.
1047
1109
  *
1048
1110
  * **Default**: `false`
1049
1111
  */
1050
1112
  idempotent: boolean;
1051
- /** If true, `["f", ["f", x]]` simplifies to `x`.
1113
+ /** If `true`, `["f", ["f", x]]` simplifies to `x`.
1052
1114
  *
1053
1115
  * **Default**: `false`
1054
1116
  */
1055
1117
  involution: boolean;
1056
- /**
1057
- * If true, when all the arguments are numeric, the result of the
1058
- * evaluation is numeric. Numeric is any value with a domain of `Number`.
1059
- *
1060
- * Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
1061
- *
1062
- * Default: false
1063
- */
1064
- numeric: boolean;
1065
- /**
1066
- * If true, when all the arguments are boolean, the result of the
1067
- * evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
1068
- *
1069
- * Example of logic functions: `And`, `Or`, `Not`, `Implies`
1070
- *
1071
- * **Default:** false
1072
- */
1073
- logic: boolean;
1074
- /**
1075
- * The function represent a relation between the first argument and
1076
- * the second argument, and evaluates to a boolean indicating if the relation
1077
- * is satisfied.
1078
- *
1079
- * For example, `Equal`, `Less`, `Approx`, etc...
1080
- *
1081
- * **Default:** false
1082
- */
1083
- relationalOperator: boolean;
1084
- /** If true, the value of this function is always the same for a given
1118
+ /** If `true`, the value of this function is always the same for a given
1085
1119
  * set of arguments and it has no side effects.
1086
1120
  *
1087
1121
  * An expression using this function is pure if the function and all its
@@ -1091,7 +1125,7 @@ export declare type FunctionDefinitionFlags = {
1091
1125
  *
1092
1126
  * This information may be used to cache the value of expressions.
1093
1127
  *
1094
- * **Default:** true
1128
+ * **Default:** `true`
1095
1129
  */
1096
1130
  pure: boolean;
1097
1131
  /**
@@ -1102,46 +1136,30 @@ export declare type FunctionDefinitionFlags = {
1102
1136
  * **Default:** false
1103
1137
  */
1104
1138
  inert: boolean;
1105
- };
1106
- /**
1107
- * Definition record for a function.
1108
- *
1109
- */
1110
- export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1111
- /**
1112
- * A number used to order arguments. Argument with higher
1113
- * complexity are placed after arguments with lower complexity when
1114
- * ordered canonically in commutative functions.
1115
- *
1116
- * - Additive functions: 1000-1999
1117
- * - Multiplicative functions: 2000-2999
1118
- * - Root and power functions: 3000-3999
1119
- * - Log functions: 4000-4999
1120
- * - Trigonometric functions: 5000-5999
1121
- * - Hypertrigonometric functions: 6000-6999
1122
- * - Special functions (factorial, Gamma, ...): 7000-7999
1123
- * - Collections: 8000-8999
1124
- * - Inert and styling: 9000-9999
1125
- * - Logic: 10000-10999
1126
- * - Relational: 11000-11999
1127
- *
1128
- * **Default**: 100,000
1129
- */
1130
- complexity?: number;
1131
1139
  /**
1132
- * - `none` Each of the arguments is evaluated (default)
1133
- * - `all` None of the arguments are evaluated and they are passed as is
1134
- * - `first` The first argument is not evaluated, the others are
1135
- * - `rest` The first argument is evaluated, the others aren't
1140
+ * All the arguments of a numeric function are numeric,
1141
+ * and its value is numeric.
1136
1142
  */
1137
- hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1143
+ numeric: boolean;
1138
1144
  /**
1139
- * If true, `Sequence` arguments appearing in the arguments of a function
1140
- * should not automatically be flattened out
1145
+ * When true, evaluating the function create a temporary scope.
1146
+ * This is used for example by the `Lambda` function to keep track of the
1147
+ * inferred domain of its wildcard `_` arguments
1141
1148
  */
1142
- sequenceHold?: boolean;
1149
+ scoped: boolean;
1150
+ };
1151
+ /**
1152
+ *
1153
+ */
1154
+ export declare type FunctionSignature = {
1155
+ /** The domain of this signature, a domain compatible with the `Function`
1156
+ * domain) */
1157
+ domain?: BoxedDomain | DomainExpression;
1143
1158
  /** The minimum and maximum values of the result of the function */
1144
- range?: [min: number, max: number];
1159
+ /** An optional handler to determine the codomain of the function.
1160
+ * If not provided, the codomain of the function is determined from `domain`
1161
+ */
1162
+ codomain?: (ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null;
1145
1163
  /**
1146
1164
  * Return the canonical form of the expression with the arguments `args`.
1147
1165
  *
@@ -1252,31 +1270,6 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
1252
1270
  *
1253
1271
  */
1254
1272
  N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1255
- /**
1256
- *
1257
- * Calculate the domain of the result, based on the value of the arguments.
1258
- *
1259
- * If the domain of the result is always the same, use the `domain` property
1260
- * instead.
1261
- *
1262
- * The argument `args` represent the arguments of the function.
1263
- *
1264
- * The return value is `null` if the input arguments cannot be handled by
1265
- * this definition.
1266
- *
1267
- * Otherwise, the return value is the domain of the result.
1268
- *
1269
- * Return `"Nothing"` if the arguments are acceptable, but the evaluation
1270
- * will fail, for example in some cases if there are missing arguments.
1271
- *
1272
- * This function is used to select the correct definition when there are
1273
- * multiple definitions for the same function name.
1274
- *
1275
- * For example it allows to distinguish between a `Add` function that
1276
- * applies to numbers and an `Add` function that applies to tensors.
1277
- *
1278
- */
1279
- evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
1280
1273
  /** Dimensional analysis
1281
1274
  * @experimental
1282
1275
  */
@@ -1286,20 +1279,61 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
1286
1279
  /** Return a compiled (optimized) expression. */
1287
1280
  compile?: (expr: BoxedExpression) => CompiledExpression;
1288
1281
  };
1289
- export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1290
- complexity: number;
1291
- hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1292
- sequenceHold: boolean;
1293
- range?: [min: number, max: number];
1282
+ export declare type BoxedFunctionSignature = {
1283
+ domain: BoxedDomain;
1284
+ codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null);
1294
1285
  canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1295
1286
  simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1296
1287
  evaluate?: BoxedLambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1297
1288
  N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1298
- evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
1299
1289
  evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1300
1290
  sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
1301
1291
  compile?: (expr: BoxedExpression) => CompiledExpression;
1302
1292
  };
1293
+ /**
1294
+ * Definition record for a function.
1295
+ *
1296
+ */
1297
+ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1298
+ /**
1299
+ * A number used to order arguments.
1300
+ *
1301
+ * Argument with higher complexity are placed after arguments with lower
1302
+ * complexity when ordered canonically in commutative functions.
1303
+ *
1304
+ * - Additive functions: 1000-1999
1305
+ * - Multiplicative functions: 2000-2999
1306
+ * - Root and power functions: 3000-3999
1307
+ * - Log functions: 4000-4999
1308
+ * - Trigonometric functions: 5000-5999
1309
+ * - Hypertrigonometric functions: 6000-6999
1310
+ * - Special functions (factorial, Gamma, ...): 7000-7999
1311
+ * - Collections: 8000-8999
1312
+ * - Inert and styling: 9000-9999
1313
+ * - Logic: 10000-10999
1314
+ * - Relational: 11000-11999
1315
+ *
1316
+ * **Default**: 100,000
1317
+ */
1318
+ complexity?: number;
1319
+ /**
1320
+ * - `"none"` Each of the arguments is evaluated (default)
1321
+ * - `"all"` None of the arguments are evaluated and they are passed as is
1322
+ * - `"first"` The first argument is not evaluated, the others are
1323
+ * - `"rest"` The first argument is evaluated, the others aren't
1324
+ * - `"last"`: The last argument is not evaluated, the others are
1325
+ * - `"most"`: All the arguments are evaluated, except the last one
1326
+ *
1327
+ * **Default**: `"none"`
1328
+ */
1329
+ hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1330
+ signature?: FunctionSignature;
1331
+ };
1332
+ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1333
+ complexity: number;
1334
+ hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1335
+ signature: BoxedFunctionSignature;
1336
+ };
1303
1337
  /**
1304
1338
  * When used in a `SymbolDefinition`, these flags are optional.
1305
1339
  *
@@ -1361,11 +1395,12 @@ export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & P
1361
1395
  * `Pi`, the actual value depends on the `precision` setting of the
1362
1396
  * `ComputeEngine` */
1363
1397
  value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
1364
- domain?: string | BoxedExpression;
1398
+ domain?: string | BoxedDomain;
1365
1399
  };
1366
1400
  export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
1367
1401
  get value(): BoxedExpression | undefined;
1368
1402
  set value(val: BoxedExpression | undefined);
1403
+ domain: BoxedDomain | undefined;
1369
1404
  at?: (index: string | number) => undefined | BoxedExpression;
1370
1405
  }
1371
1406
  export declare type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
@@ -1382,41 +1417,41 @@ export interface ComputeEngineStats {
1382
1417
  /** @internal */
1383
1418
  export interface IComputeEngine {
1384
1419
  /** @internal */
1385
- readonly ZERO: BoxedExpression;
1420
+ readonly _ZERO: BoxedExpression;
1386
1421
  /** @internal */
1387
- readonly ONE: BoxedExpression;
1422
+ readonly _ONE: BoxedExpression;
1388
1423
  /** @internal */
1389
- readonly TWO: BoxedExpression;
1424
+ readonly _TWO: BoxedExpression;
1390
1425
  /** @internal */
1391
- readonly HALF: BoxedExpression;
1426
+ readonly _HALF: BoxedExpression;
1392
1427
  /** @internal */
1393
- readonly NEGATIVE_ONE: BoxedExpression;
1428
+ readonly _NEGATIVE_ONE: BoxedExpression;
1394
1429
  /** @internal */
1395
- readonly I: BoxedExpression;
1430
+ readonly _I: BoxedExpression;
1396
1431
  /** @internal */
1397
- readonly NAN: BoxedExpression;
1432
+ readonly _NAN: BoxedExpression;
1398
1433
  /** @internal */
1399
- readonly POSITIVE_INFINITY: BoxedExpression;
1434
+ readonly _POSITIVE_INFINITY: BoxedExpression;
1400
1435
  /** @internal */
1401
- readonly NEGATIVE_INFINITY: BoxedExpression;
1436
+ readonly _NEGATIVE_INFINITY: BoxedExpression;
1402
1437
  /** @internal */
1403
- readonly COMPLEX_INFINITY: BoxedExpression;
1438
+ readonly _COMPLEX_INFINITY: BoxedExpression;
1404
1439
  /** @internal */
1405
- readonly DECIMAL_NAN: Decimal;
1440
+ readonly _DECIMAL_NAN: Decimal;
1406
1441
  /** @internal */
1407
- readonly DECIMAL_ZERO: Decimal;
1442
+ readonly _DECIMAL_ZERO: Decimal;
1408
1443
  /** @internal */
1409
- readonly DECIMAL_ONE: Decimal;
1444
+ readonly _DECIMAL_ONE: Decimal;
1410
1445
  /** @internal */
1411
- readonly DECIMAL_TWO: Decimal;
1446
+ readonly _DECIMAL_TWO: Decimal;
1412
1447
  /** @internal */
1413
- readonly DECIMAL_HALF: Decimal;
1448
+ readonly _DECIMAL_HALF: Decimal;
1414
1449
  /** @internal */
1415
- readonly DECIMAL_PI: Decimal;
1450
+ readonly _DECIMAL_PI: Decimal;
1416
1451
  /** @internal */
1417
- readonly DECIMAL_NEGATIVE_ONE: Decimal;
1452
+ readonly _DECIMAL_NEGATIVE_ONE: Decimal;
1418
1453
  /** The current scope */
1419
- context: RuntimeScope;
1454
+ context: RuntimeScope | null;
1420
1455
  /** Absolute time beyond which evaluation should not proceed
1421
1456
  * @internal
1422
1457
  */
@@ -1427,7 +1462,7 @@ export interface IComputeEngine {
1427
1462
  readonly iterationLimit: number;
1428
1463
  /** @experimental */
1429
1464
  readonly recursionLimit: number;
1430
- defaultDomain: null | BoxedExpression;
1465
+ defaultDomain: null | BoxedDomain;
1431
1466
  /** {@inheritDoc NumericMode} */
1432
1467
  numericMode: NumericMode;
1433
1468
  tolerance: number;
@@ -1448,13 +1483,17 @@ export interface IComputeEngine {
1448
1483
  * If a definition existed previously, it is replaced.
1449
1484
  */
1450
1485
  defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
1451
- getSymbolDefinition(name: string, wikidata?: string): undefined | BoxedSymbolDefinition;
1452
1486
  /**
1453
- * Return `undefined` if no definition exist for this `head.
1487
+ * Associate a new definition to a function in the current context.
1488
+ *
1489
+ * If a definition existed previously, it is replaced.
1454
1490
  */
1455
- getFunctionDefinition(head: string, wikidata?: string): undefined | BoxedFunctionDefinition;
1491
+ defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
1492
+ lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1493
+ /** Return `undefined` if no definition exist for this `head` */
1494
+ lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
1456
1495
  /**
1457
- * Returned a boxed expression from the input.
1496
+ * Return a boxed expression from the input.
1458
1497
  *
1459
1498
  * The result may not be canonical.
1460
1499
  */
@@ -1465,14 +1504,22 @@ export interface IComputeEngine {
1465
1504
  symbol(sym: string, metadata?: Metadata): BoxedExpression;
1466
1505
  /** Return a canonical boxed string */
1467
1506
  string(s: string, metadata?: Metadata): BoxedExpression;
1468
- /** Return a canonical boxed domain */
1469
- domain(domain: BoxedExpression | string, metadata?: Metadata): BoxedExpression;
1470
- /** Return a canonical expression.
1507
+ /** Return a canonical boxed domain.
1508
+ *
1509
+ * If the domain is invalid, may return an `["Error"]` expression
1510
+ *
1511
+ */
1512
+ domain(domain: SemiBoxedExpression | BoxedDomain | string, metadata?: Metadata): BoxedDomain;
1513
+ /** Return a canonical lambda expression */
1514
+ lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
1515
+ /**
1516
+ * Return a canonical expression.
1471
1517
  *
1472
1518
  * Note that the result may not be a function, or may have a different
1473
1519
  * `head` than the one specified.
1474
1520
  *
1475
- * For example `ce.fn("Add", [ce.number(2), ce.number(3)]))` \( \to \) 5
1521
+ * For example:
1522
+ * `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
1476
1523
  *
1477
1524
  */
1478
1525
  fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
@@ -1483,15 +1530,15 @@ export interface IComputeEngine {
1483
1530
  * In general, consider using `fn()` or `box()` instead.
1484
1531
  *
1485
1532
  * The result is canonical, but the caller has to ensure that all the
1486
- * conditions are met (i.e. ops properly normalized and sorted, all
1487
- * ops canonical, etc..) so that the result is actually canonical.
1533
+ * conditions are met (i.e. `ops` properly normalized and sorted, all
1534
+ * `ops` canonical, etc..) so that the result is actually canonical.
1488
1535
  */
1489
1536
  _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1490
1537
  /** Shortcut for `this.fn("Error"...)`.
1491
1538
  *
1492
1539
  * The result is canonical.
1493
1540
  */
1494
- error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): any;
1541
+ error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
1495
1542
  /** Shortcut for `this.fn("Add"...)`.
1496
1543
  *
1497
1544
  * The result is canonical.
@@ -1548,7 +1595,7 @@ export interface IComputeEngine {
1548
1595
  */
1549
1596
  serialize(expr: SemiBoxedExpression): LatexString;
1550
1597
  /**
1551
- * Options to control the serailization of MathJSON expression to LaTeX
1598
+ * Options to control the serialization of MathJSON expression to LaTeX
1552
1599
  * when using `this.latex` or `this.engine.serialize()`.
1553
1600
  *
1554
1601
  *
@@ -1577,7 +1624,7 @@ export interface IComputeEngine {
1577
1624
  *
1578
1625
  *
1579
1626
  */
1580
- assume(symbol: LatexString | SemiBoxedExpression, domain: BoxedExpression): AssumeResult;
1627
+ assume(symbol: LatexString | SemiBoxedExpression, domain: BoxedDomain): AssumeResult;
1581
1628
  assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
1582
1629
  assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
1583
1630
  /** Remove all assumptions about one or more symbols */
@@ -1585,7 +1632,7 @@ export interface IComputeEngine {
1585
1632
  get assumptions(): ExpressionMapInterface<boolean>;
1586
1633
  ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
1587
1634
  pushScope(options?: {
1588
- dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
1635
+ symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
1589
1636
  assumptions?: (LatexString | Expression | BoxedExpression)[];
1590
1637
  scope?: Partial<Scope>;
1591
1638
  }): void;
@@ -1608,10 +1655,9 @@ export interface IComputeEngine {
1608
1655
  cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
1609
1656
  readonly stats: ComputeEngineStats;
1610
1657
  /** @internal */
1611
- purge(): void;
1658
+ reset(): void;
1612
1659
  /** @internal */
1613
1660
  _register(expr: BoxedExpression): void;
1614
1661
  /** @internal */
1615
1662
  _unregister(expr: BoxedExpression): void;
1616
1663
  }
1617
- export declare function getVars(expr: BoxedExpression): string[];