@cortex-js/compute-engine 0.4.2 → 0.5.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 (132) hide show
  1. package/README.md +4 -5
  2. package/dist/compute-engine.esm.js +16755 -10484
  3. package/dist/compute-engine.min.esm.js +2 -7
  4. package/dist/compute-engine.min.js +2 -7
  5. package/dist/math-json.esm.js +148 -12472
  6. package/dist/math-json.min.esm.js +2 -7
  7. package/dist/math-json.min.js +2 -7
  8. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  9. package/dist/types/common/signals.d.ts +90 -0
  10. package/dist/types/compute-engine/assume.d.ts +21 -6
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +95 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +53 -0
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  26. package/dist/types/compute-engine/compute-engine.d.ts +284 -99
  27. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  28. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  29. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  33. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/core.d.ts +2 -2
  35. package/dist/types/compute-engine/dictionary/dictionary.d.ts +18 -11
  36. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  38. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  39. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  40. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -2
  41. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +576 -0
  56. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +4 -5
  57. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +41 -0
  59. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  60. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  61. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  62. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  63. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  64. package/dist/types/compute-engine/public.d.ts +1416 -447
  65. package/dist/types/compute-engine/rules.d.ts +16 -6
  66. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  67. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  68. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  69. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  70. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  71. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  72. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  73. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  74. package/dist/types/compute-engine.d.ts +3 -5
  75. package/dist/types/math-json/math-json-format.d.ts +101 -0
  76. package/dist/types/math-json/utils.d.ts +97 -0
  77. package/dist/types/math-json.d.ts +4 -3
  78. package/package.json +29 -28
  79. package/dist/compute-engine.js +0 -17296
  80. package/dist/cortex.esm.js +0 -20989
  81. package/dist/cortex.js +0 -21011
  82. package/dist/cortex.min.esm.js +0 -7
  83. package/dist/cortex.min.js +0 -7
  84. package/dist/math-json.js +0 -12517
  85. package/dist/types/common/debug.d.ts +0 -28
  86. package/dist/types/common/utils.d.ts +0 -153
  87. package/dist/types/compute-engine/canonical-forms.d.ts +0 -74
  88. package/dist/types/compute-engine/dictionary/domains.d.ts +0 -26
  89. package/dist/types/compute-engine/dictionary/utils.d.ts +0 -5
  90. package/dist/types/compute-engine/domains.d.ts +0 -4
  91. package/dist/types/compute-engine/evaluate.d.ts +0 -13
  92. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  93. package/dist/types/compute-engine/internal-compute-engine.d.ts +0 -108
  94. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  95. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  96. package/dist/types/compute-engine/numeric.d.ts +0 -21
  97. package/dist/types/compute-engine/numerical-eval.d.ts +0 -5
  98. package/dist/types/compute-engine/order.d.ts +0 -18
  99. package/dist/types/compute-engine/patterns.d.ts +0 -22
  100. package/dist/types/compute-engine/predicates.d.ts +0 -42
  101. package/dist/types/compute-engine/simplify.d.ts +0 -6
  102. package/dist/types/compute-engine/utils.d.ts +0 -15
  103. package/dist/types/cortex/formatter.d.ts +0 -165
  104. package/dist/types/cortex/parse-cortex.d.ts +0 -5
  105. package/dist/types/cortex/reserved-words.d.ts +0 -1
  106. package/dist/types/cortex/serialize-cortex.d.ts +0 -14
  107. package/dist/types/cortex.d.ts +0 -8
  108. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  109. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  110. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  111. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  112. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  113. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  114. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  115. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  116. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  117. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  118. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  119. package/dist/types/latex-syntax/parse.d.ts +0 -138
  120. package/dist/types/latex-syntax/public.d.ts +0 -456
  121. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  122. package/dist/types/latex-syntax/utils.d.ts +0 -10
  123. package/dist/types/point-free-parser/characters.d.ts +0 -25
  124. package/dist/types/point-free-parser/combinators.d.ts +0 -46
  125. package/dist/types/point-free-parser/core-combinators.d.ts +0 -78
  126. package/dist/types/point-free-parser/grammar.d.ts +0 -12
  127. package/dist/types/point-free-parser/identifier-parsers.d.ts +0 -7
  128. package/dist/types/point-free-parser/numeric-parsers.d.ts +0 -8
  129. package/dist/types/point-free-parser/parsers.d.ts +0 -130
  130. package/dist/types/point-free-parser/string-parsers.d.ts +0 -29
  131. package/dist/types/point-free-parser/whitespace-parsers.d.ts +0 -17
  132. package/dist/types/public.d.ts +0 -163
@@ -1,49 +1,889 @@
1
- /* 0.4.2 */
2
- import type { ExpressionMap } from './expression-map';
3
- import type { Substitution } from './patterns';
1
+ /* 0.5.0 */
2
+ * The most important classes are {@link ComputeEngine} and
3
+ * {@link BoxedExpression}.
4
+ *
5
+ * With `ComputeEngine` you create `BoxedExpression` objects. With
6
+ * `BoxedExpression` you simplify, evaluate and serialize expressions.
7
+ *
8
+ * @module ComputeEngine
9
+ */
4
10
  import type { Decimal } from 'decimal.js';
5
11
  import type { Complex } from 'complex.js';
6
- export declare type Numeric = number | Decimal | Complex;
7
- export declare type Pattern<T extends number = Numeric> = Expression<T>;
8
- export declare type Rule<T extends number = Numeric> = [
9
- lhs: string | Pattern<T>,
10
- rhs: string | Pattern<T>,
11
- condition?: string | ((ce: ComputeEngine<T>, args: Substitution<T>) => boolean)
12
+ import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../common/signals';
13
+ import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
14
+ import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
15
+ export * from './latex-syntax/public';
16
+ /**
17
+ * Metadata that can be associated with a `BoxedExpression`
18
+ */
19
+ export declare type Metadata = {
20
+ latex?: string;
21
+ wikidata?: string;
22
+ };
23
+ /**
24
+ * The numeric evaluation mode:
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,
28
+ * about 15 digits of precision
29
+ * - `decimal`: arbitrary precision floating point numbers, as provided by the
30
+ * "decimal.js" library
31
+ * - `complex`: complex number represented by two machine numbers, a real and
32
+ * an imaginary part, as provided by the "complex.js" library
33
+ */
34
+ export declare type NumericMode = 'auto' | 'machine' | 'decimal' | 'complex';
35
+ /** Options for `BoxedExpression.simplify()`
36
+ *
37
+ */
38
+ export declare type SimplifyOptions = EvaluateOptions & {
39
+ recursive?: boolean;
40
+ rules?: BoxedRuleSet;
41
+ };
42
+ /** Options for `BoxedExpression.evaluate()`
43
+ *
44
+ * @internal
45
+ */
46
+ export declare type EvaluateOptions = {};
47
+ /** Options for `BoxedExpression.N()`
48
+ * @internal
49
+ */
50
+ export declare type NOptions = {};
51
+ export declare type ReplaceOptions = {
52
+ /** If true, apply replacement rules to all sub-expressions.
53
+ * If false, only consider the top-level expression.
54
+ *
55
+ * **Default**: `true`
56
+ */
57
+ recursive?: boolean;
58
+ /**
59
+ * If true, stop after the first rule that matches.
60
+ *
61
+ * If false, apply all the remaining rules even after the first match.
62
+ *
63
+ * **Default**: `true`
64
+ */
65
+ once?: boolean;
66
+ /**
67
+ * If `iterationLimit` > 1, the rules will be repeatedly applied
68
+ * until no rules apply, up to `maxIterations` times.
69
+ *
70
+ * Note that if `once` is true, `maxIterations` has no effect.
71
+ *
72
+ * **Default**: `1`
73
+ */
74
+ iterationLimit?: number;
75
+ };
76
+ /**
77
+ * A substitution describes the values of the wildcards in a pattern so that
78
+ * the pattern is equal to a target expression.
79
+ *
80
+ * A substitution can also be considered a more constrained version of a
81
+ * rule whose `lhs` is always a symbol.
82
+ */
83
+ export declare type Substitution = {
84
+ [symbol: string]: BoxedExpression;
85
+ };
86
+ /** A LaTeX string starts and end with `$`, for example
87
+ * `"$\frac{\pi}{2}$"`.
88
+ */
89
+ export declare type LatexString = string;
90
+ /**
91
+ * A rule describes how to modify an expressions that matches a `lhs` pattern
92
+ * into a new expressions matching `rhs`.
93
+ *
94
+ * `x-1` \( \to \) `1-x`
95
+ * `(x+1)(x-1)` \( \to \) `x^2-1
96
+ *
97
+ * The `lhs` can be expressed as a LaTeX string or a MathJSON expression.
98
+ *
99
+ * Unbound variables (`x`, but not `Pi`) are matched structurally with a
100
+ * a target expression, then the expression is rewritten as the `rhs`, with
101
+ * the corresponding unbound variables in the `rhs` replaced by their values
102
+ * in the `lhs.
103
+ *
104
+ * Pattern symbols (e.g. `_1`, `_a`) can be used as well.
105
+ *
106
+ * In addition:
107
+ * - `__1` (`__a`, etc..) match a sequence of one or more expressions
108
+ * - `___1` (`___a`, etc...) match a sequence of zero or more expressions
109
+ */
110
+ export declare type Rule = [
111
+ lhs: LatexString | SemiBoxedExpression | Pattern,
112
+ rhs: LatexString | SemiBoxedExpression,
113
+ options?: {
114
+ condition?: LatexString | ((wildcards: Substitution) => boolean);
115
+ priority?: number;
116
+ }
12
117
  ];
13
- export declare type RuleSet<T extends number = Numeric> = Iterable<Rule<T>>;
118
+ export declare type BoxedRule = [
119
+ lhs: Pattern,
120
+ rhs: BoxedExpression,
121
+ priority: number,
122
+ condition: undefined | ((wildcards: Substitution) => boolean)
123
+ ];
124
+ 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;
132
+ /**
133
+ * Options to control the serialization to MathJSON when using `BoxedExpression.json`.
134
+ */
135
+ export declare type JsonSerializationOptions = {
136
+ /** A list of space separated function names that should be excluded from
137
+ * the JSON output.
138
+ *
139
+ * Those functions are replaced with an equivalent, for example, `Square` with
140
+ * `Power`, etc...
141
+ *
142
+ * Possible values include `Sqrt`, `Root`, `Square`, `Exp`, `Subtract`,
143
+ * `Rational`, `Complex`
144
+ *
145
+ * **Default**: `[]` (none)
146
+ */
147
+ exclude: string[];
148
+ /** A list of space separated keywords indicating which MathJSON expressions
149
+ * can use a shorthand.
150
+ *
151
+ * **Default**: `['all']`
152
+ */
153
+ shorthands: ('all' | 'number' | 'symbol' | 'function' | 'dictionary' | 'string')[];
154
+ /** A list of space separated keywords indicating which metadata should be
155
+ * included in the MathJSON. If metadata is included, shorthand notation
156
+ * is not used.
157
+ *
158
+ * **Default**: `[]` (none)
159
+ */
160
+ metadata: ('all' | 'wikidata' | 'latex')[];
161
+ /** If true, repeating decimals are detected and serialized accordingly
162
+ * For example:
163
+ * - `1.3333333333333333` \( \to \) `1.(3)`
164
+ * - `0.142857142857142857142857142857142857142857142857142` \( \to \) `0.(1428571)`
165
+ *
166
+ * **Default**: `true`
167
+ */
168
+ repeatingDecimal: boolean;
169
+ };
14
170
  /**
15
- * A dictionary maps a MathJSON name to a definition.
171
+ * **Theory of Operations**
16
172
  *
17
- * A named entry in a dictionary can refer to a symbol, as in the expression,
18
- * `"Pi"`, to a function: "Add" in the expression `["Add", 2, 3]`, or
19
- * to a `"Set`".
173
+ * The `BoxedExpression` interface includes most of the member functions
174
+ * applicable to any kind of expression, for example `get symbol()` or
175
+ * `get ops()`.
20
176
  *
21
- * The name can be an arbitrary string of Unicode characters, however
22
- * the following conventions are recommended:
177
+ * When a member function is not applicable to this `BoxedExpression`,
178
+ * for example `get symbol()` on a `BoxedNumber`, it returns `null`.
23
179
  *
24
- * - Use only letters, digits and `-`, and the first character should be
25
- * a letter: `/^[a-zA-Z][a-zA-Z0-9-]+/`
26
- * - Built-in functions and symbols should start with an uppercase letter
180
+ * This convention makes it convenient to manipulate expressions without
181
+ * having to check what kind of instance they are before manipulating them.
182
+ *
183
+ */
184
+ export interface BoxedExpression {
185
+ /** The Compute Engine associated with this expression provides
186
+ * a context in which to interpret it, such as definition of symbols
187
+ * and functions.
188
+ */
189
+ readonly engine: IComputeEngine;
190
+ /** From `Object.valueOf()`, return a primitive value for the expression.
191
+ *
192
+ * If the expression is a machine number, or a Decimal that can be
193
+ * converted to a machine number, return a `number`.
194
+ *
195
+ * If the expression is a rational number, return `[number, number]`.
196
+ *
197
+ * If the expression is a symbol, return the name of the symbol as a `string`.
198
+ *
199
+ * Otherwise return a LaTeX representation of the expression.
200
+ *
201
+ * @category Object Methods
202
+ */
203
+ valueOf(): number | string | [number, number];
204
+ /** From `Object.toString()`, return a LaTeX representation of the expression.
205
+ *
206
+ * @category Object Methods
207
+ */
208
+ toString(): string;
209
+ /** From `Object.toJSON()`, equivalent to `JSON.stringify(this.json)`
210
+ *
211
+ * @category Object Methods
212
+ */
213
+ toJSON(): string;
214
+ /** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
215
+ *
216
+ * @category Object Methods
217
+ *
218
+ */
219
+ is(rhs: any): boolean;
220
+ /** @internal */
221
+ get hash(): number;
222
+ /** An optional short description of the symbol or function head.
223
+ *
224
+ * May include markdown. Each string is a paragraph. */
225
+ readonly description: string[];
226
+ /** An optional URL pointing to more information about the symbol or function head */
227
+ readonly url: string;
228
+ /** All boxed expressions have a head.
229
+ *
230
+ * If not a function this can be `Symbol`, `String`, `Number` or `Dictionary`.
231
+ *
232
+ * If the head expression can be represented as a string, it is returned
233
+ * as a string.
234
+ */
235
+ get head(): BoxedExpression | string;
236
+ /**
237
+ * If `this.isPure` is `true`, this is a synonym for `this.evaluate()`.
238
+ * Otherwise, it returns `undefined`.
239
+ */
240
+ get value(): BoxedExpression | undefined;
241
+ /** Only the value of variables can be changed (symbols that are not constants) */
242
+ set value(value: BoxedExpression | number | undefined);
243
+ /** Return an approximation of the value of this expression. Floating-point
244
+ * operations may be performed.
245
+ *
246
+ * Just like `this.value`, it returns `undefined` for impure expressions.
247
+ */
248
+ get numericValue(): BoxedExpression | undefined;
249
+ /** If true, the value of the expression never changes and evaluating it has
250
+ * no side-effects.
251
+ * If false, the value of the expression may change, if the
252
+ * value of other expression changes or for other reasons.
253
+ *
254
+ * If `this.isPure` is `false`, `this.value` is undefined. Call
255
+ * `this.evaluate()` to determine the value of the expression instead.
256
+ *
257
+ * As an example, the `Random` function is not pure.
258
+ */
259
+ get isPure(): boolean;
260
+ /**
261
+ * If `true`, this expression represents a value that was not calculated
262
+ * or that does not reference another expression.
263
+ * This means the expression is either a number, a string or a dictionary.
264
+ * Functions and symbols are not literals.
265
+ */
266
+ get isLiteral(): boolean;
267
+ /** If `true`, this expression is in a canonical form */
268
+ get isCanonical(): boolean;
269
+ /** For internal use only, set when a canonical expression is created.
270
+ * @internal
271
+ */
272
+ set isCanonical(val: boolean);
273
+ /** `ops` is the list of arguments of the function, its "tail"
274
+ *
275
+ * @category Function Expression
276
+ *
277
+ */
278
+ get ops(): null | BoxedExpression[];
279
+ /** If this expression is a function, the number of operands, otherwise 0.
280
+ *
281
+ * Note that a function can have 0 operands, so to check if this expression
282
+ * is a function, check if `this.ops !== null` instead.
283
+ *
284
+ * @category Function Expression
285
+ *
286
+ */
287
+ get nops(): number;
288
+ /** First operand, i.e.`this.ops[0]`
289
+ *
290
+ *
291
+ * @category Function Expression
292
+ *
293
+ *
294
+ */
295
+ get op1(): BoxedExpression;
296
+ /** Second operand, i.e.`this.ops[0]`
297
+ *
298
+ *
299
+ * @category Function Expression
300
+ *
301
+ *
302
+ */
303
+ get op2(): BoxedExpression;
304
+ /** Third operand, i.e. `this.ops[2]`
305
+ *
306
+ *
307
+ * @category Function Expression
308
+ *
309
+ *
310
+ */
311
+ get op3(): BoxedExpression;
312
+ /** The keys of the dictionary.
313
+ *
314
+ * If this expression not a dictionary, return `null`
315
+ *
316
+ * @category Dictionary Expression
317
+ *
318
+ */
319
+ get keys(): IterableIterator<string> | null;
320
+ /**
321
+ *
322
+ * @category Dictionary Expression
323
+ */
324
+ get keysCount(): number;
325
+ /**
326
+ * If this expression is a dictionary, return the value of the `key` entry.
327
+ *
328
+ * @category Dictionary Expression
329
+ *
330
+ */
331
+ getKey(key: string): BoxedExpression | undefined;
332
+ /**
333
+ * If this expression is a dictionary, return true if the dictionary has a
334
+ * `key` entry.
335
+ *
336
+ * @category Dictionary Expression
337
+ *
338
+ */
339
+ hasKey(key: string): boolean;
340
+ /**
341
+ * Return the value of this number or symbol, if stored as a machine number.
342
+ *
343
+ * Note it is possible for `machineValue` to be `null`, and for `isNotZero` to be true.
344
+ * For example, when a symbol has been defined with an assumption.
345
+ *
346
+ * If `machineValue` is not `null`, then `decimalValue`, `rationalValue`
347
+ * and `complexValue` are `null.
348
+ *
349
+ * @category Numeric Expression
350
+ *
351
+ */
352
+ get machineValue(): number | null;
353
+ /** If the value of this expression is a rational number, return it.
354
+ * Otherwise, return `[null, null]`.
355
+ *
356
+ * If `rationalValue` is not `[null, null]`, then `machineValue`, `decimalValue`
357
+ * and `complexValue` are `null.
358
+ *
359
+ * @category Numeric Expression
360
+ *
361
+ */
362
+ get rationalValue(): [numer: number, denom: number] | [null, null];
363
+ /** If the value of this expression is a `Decimal` number, return it.
364
+ * Otherwise, return `null`.
365
+ *
366
+ * A `Decimal` number is an arbitrarily long floating point number.
367
+ *
368
+ * If `decimalValue` is not `null`, then `machineValue`
369
+ * and `complexValue` are `null` and `rationalValue` is `[null, null]`.
370
+ *
371
+ * @category Numeric Expression
372
+ *
373
+ */
374
+ get decimalValue(): Decimal | null;
375
+ /** If the value of this expression is a `Complex` number, return it.
376
+ * Otherwise, return `null`.
377
+ *
378
+ * If `complexValue` is not `null`, then `machineValue`, `rationalValue`
379
+ * and `decimalValue` are `null.
380
+ *
381
+ * @category Numeric Expression
382
+ *
383
+ *
384
+ */
385
+ get complexValue(): Complex | null;
386
+ /** Return an approximation of the numeric value of this expression as
387
+ * a 64-bit floating point number.
388
+ *
389
+ * If the value is a machine number, return it exactly.
390
+ *
391
+ * If the value is a rational number, return the numerator divided by the
392
+ * denominator.
393
+ *
394
+ * If the value is a Decimal number that can be represented by a machine
395
+ * number, return this value. There might be a small loss of precision due
396
+ * to the limitations of the binary representation of numbers as machine
397
+ * numbers.
398
+ *
399
+ * If the value of this expression cannot be represented by a float,
400
+ * return `null`.
401
+ *
402
+ * @category Numeric Expression
403
+ *
404
+ *
405
+ */
406
+ get asFloat(): number | null;
407
+ /**
408
+ * If the value of this expression is an integer with a 'small' absolute value,
409
+ * return this value. Otherwise, return `null`.
410
+ *
411
+ * Some calculations, for example to put in canonical forms, are only
412
+ * performed if they are safe from overflow. This method makes it easy
413
+ * to check for this, whether the value is a Decimal or a number.
414
+ *
415
+ * By default, "small" is less than 10,000.
416
+ *
417
+ * @category Numeric Expression
418
+ *
419
+ */
420
+ get asSmallInteger(): number | null;
421
+ /**
422
+ * If the value of this an expression is a small integer or a rational,
423
+ * return this value. Otherwise, return `[null, null`].
424
+ *
425
+ * @category Numeric Expression
426
+ *
427
+ */
428
+ get asRational(): [number, number] | [null, null];
429
+ /**
430
+ * Return the following, depending on the value of this expression:
431
+ *
432
+ * * `-1` if it is < 0
433
+ * * `0` if it is = 0
434
+ * * `+1` if it is > 0
435
+ * * `undefined` this value may be positive, negative or zero. We don't know
436
+ * right now (a symbol with an Integer domain, but no currently assigned
437
+ * value, for example)
438
+ * * `null` this value will never be positive, negative or zero (`NaN`,
439
+ * a string or a complex number for example)
440
+ *
441
+ * Note that complex numbers have no natural ordering,
442
+ * so if the value is a complex number, `sgn` is either 0, or `null`
443
+ *
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
446
+ *
447
+ * @category Numeric Expression
448
+ *
449
+ */
450
+ get sgn(): -1 | 0 | 1 | undefined | null;
451
+ /** If this expression is a symbol, return the name of the symbol as a string.
452
+ * Otherwise, return `null`.
453
+ *
454
+ * @category Symbol Expression
455
+ *
456
+ */
457
+ get symbol(): string | null;
458
+ /** Shortcut for `this.symbol === "Missing"`
459
+ *
460
+ * @category Symbol Expression
461
+ *
462
+ */
463
+ get isMissing(): boolean;
464
+ /** If this expression is a string, return the value of the string.
465
+ * Otherwise, return `null`.
466
+ *
467
+ * @category String Expression
468
+ *
469
+ */
470
+ 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.
478
+ *
479
+ * `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
480
+ *
481
+ * Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
482
+ * is a number.
483
+ *
484
+ * @category Expression Properties
485
+ */
486
+ get isNumber(): boolean | undefined;
487
+ /** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
488
+ *
489
+ *
490
+ * @category Expression Properties
491
+ *
492
+ */
493
+ get isInteger(): boolean | undefined;
494
+ /** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
495
+ *
496
+ * Note that every integer is also a rational.
497
+ *
498
+ *
499
+ * @category Expression Properties
500
+ *
501
+ */
502
+ get isRational(): boolean | undefined;
503
+ /**
504
+ * The value of this expression is a number that is the root of a non-zero
505
+ * univariate polynomial with rational coefficients.
506
+ *
507
+ * All integers and rational numbers are algebraic.
508
+ *
509
+ * Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
510
+ *
511
+ *
512
+ * @category Expression Properties
513
+ *
514
+ */
515
+ get isAlgebraic(): boolean | undefined;
516
+ /**
517
+ * The value of this expression is real number: finite and not imaginary.
518
+ *
519
+ * `isFinite && !isImaginary`
520
+ *
521
+ *
522
+ * @category Expression Properties
523
+ */
524
+ get isReal(): boolean | undefined;
525
+ /** Real or ±Infinity
526
+ *
527
+ * `isReal || isInfinity`
528
+ *
529
+ *
530
+ * @category Expression Properties
531
+ */
532
+ get isExtendedReal(): boolean | undefined;
533
+ /**
534
+ * The value of this expression is a number, but not `NaN` or any Infinity
535
+ *
536
+ * `isReal || isImaginary`
537
+ *
538
+ *
539
+ * @category Expression Properties
540
+ *
541
+ */
542
+ get isComplex(): boolean | undefined;
543
+ /** `isReal || isImaginary || isInfinity`
544
+ *
545
+ *
546
+ * @category Expression Properties
547
+ */
548
+ get isExtendedComplex(): boolean | undefined;
549
+ /** The value of this expression is a number with a imaginary part
550
+ *
551
+ *
552
+ * @category Expression Properties
553
+ */
554
+ get isImaginary(): boolean | undefined;
555
+ /**
556
+ * @category Expression Properties
557
+ */
558
+ get isZero(): boolean | undefined;
559
+ /**
560
+ * @category Expression Properties
561
+ */
562
+ get isNotZero(): boolean | undefined;
563
+ /**
564
+ * @category Expression Properties
565
+ */
566
+ get isOne(): boolean | undefined;
567
+ /**
568
+ * @category Expression Properties
569
+ */
570
+ get isNegativeOne(): boolean | undefined;
571
+ /** ±Infinity or Complex Infinity
572
+ *
573
+ * @category Expression Properties
574
+ */
575
+ get isInfinity(): boolean | undefined;
576
+ /**
577
+ * "Not a Number".
578
+ *
579
+ * A value representing undefined result of computations, such as `0/0`,
580
+ * as per the floating point format standard IEEE-754.
581
+ *
582
+ * Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
583
+ * number).
584
+ *
585
+ * @category Expression Properties
586
+ *
587
+ */
588
+ get isNaN(): boolean | undefined;
589
+ /** Not ±Infinity and not `NaN`
590
+ *
591
+ * @category Expression Properties
592
+ */
593
+ get isFinite(): boolean | undefined;
594
+ /**
595
+ * @category Expression Properties
596
+ */
597
+ get isEven(): boolean | undefined;
598
+ /**
599
+ * @category Expression Properties
600
+ */
601
+ get isOdd(): boolean | undefined;
602
+ /**
603
+ * @category Expression Properties
604
+ */
605
+ get isPrime(): boolean | undefined;
606
+ /**
607
+ * @category Expression Properties
608
+ */
609
+ get isComposite(): boolean | undefined;
610
+ /** Structural/symbolic equality (weak equality).
611
+ *
612
+ * `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
613
+ *
614
+ * @category Relational Operator
615
+ */
616
+ isSame(rhs: BoxedExpression): boolean;
617
+ /**
618
+ * True if the expression includes a symbol `v` or a function head `v`.
619
+ */
620
+ has(v: string | string[]): boolean;
621
+ /** Attempt to match this expression to the `rhs` expression.
622
+ *
623
+ * If `rhs` does not match, return `null`.
624
+ *
625
+ * Otherwise return an object literal.
626
+ *
627
+ * If this expression includes wildcards (symbols with a name that starts
628
+ * with `_`), the object literal will include a prop for each matching named
629
+ * wildcard.
630
+ *
631
+ * If `rhs` matches this pattern but there are no named wildcards, return
632
+ * the empty object literal, `{}`.
633
+ */
634
+ match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
635
+ /** Mathematical equality (strong equality), that is the value
636
+ * of this expression and of `rhs` are numerically equal.
637
+ *
638
+ * Both expressions are numerically evaluated.
639
+ *
640
+ * Numbers whose difference is less than `engine.tolerance` are
641
+ * considered equal. This tolerance is set when the `engine.precision` is
642
+ * changed to be such that the last two digits are ignored.
643
+ *
644
+ * @category Relational Operator
645
+ */
646
+ isEqual(rhs: BoxedExpression): boolean;
647
+ /** If the expressions cannot be compared, `undefined` is returned
648
+ *
649
+ * @category Relational Operator
650
+ */
651
+ isLess(rhs: BoxedExpression): boolean | undefined;
652
+ /**
653
+ * @category Relational Operator
654
+ */
655
+ isLessEqual(rhs: BoxedExpression): boolean | undefined;
656
+ /**
657
+ * @category Relational Operator
658
+ */
659
+ isGreater(rhs: BoxedExpression): boolean | undefined;
660
+ /**
661
+ * @category Relational Operator
662
+ */
663
+ isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
664
+ /** The value of this expression is > 0, same as `isGreater(0)`
665
+ *
666
+ * @category Expression Properties
667
+ */
668
+ get isPositive(): boolean | undefined;
669
+ /** The value of this expression is >= 0, same as `isGreaterEqual(0)`
670
+ *
671
+ * @category Expression Properties
672
+ */
673
+ get isNonNegative(): boolean | undefined;
674
+ /** The value of this expression is < 0, same as `isLess(0)`
675
+ *
676
+ * @category Expression Properties
677
+ */
678
+ get isNegative(): boolean | undefined;
679
+ /** The value of this expression is <= 0, same as `isLessEqual(0)`
680
+ *
681
+ * @category Expression Properties
682
+ */
683
+ get isNonPositive(): boolean | undefined;
684
+ /** Wikidata identifier */
685
+ get wikidata(): string;
686
+ set wikidata(val: string);
687
+ /** MathJSON representation of this expression */
688
+ get json(): Expression;
689
+ /** LaTeX representation of this expression */
690
+ get latex(): LatexString;
691
+ set latex(val: string);
692
+ /** Expressions with a higher complexity score are sorted
693
+ * first in commutative functions
694
+ */
695
+ 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 */
702
+ get functionDefinition(): BoxedFunctionDefinition | undefined;
703
+ get symbolDefinition(): BoxedSymbolDefinition | undefined;
704
+ /**
705
+ * Return the canonical form of this expression.
706
+ *
707
+ * If a function, consider the function definition flags:
708
+ * - `associative`: \\( f(a, f(b), c) \longrightarrow f(a, b, c) \\)
709
+ * - `idempotent`: \\( f(f(a)) \longrightarrow f(a) \\)
710
+ * - `involution`: \\( f(f(a)) \longrightarrow a \\)
711
+ * - `commutative`: sort the arguments.
712
+ *
713
+ * Additionally, some simplifications involving exact computations on
714
+ * small integers may be performed.
715
+ *
716
+ * For example:
717
+ * - \\( 2 + x + 1 \longrightarrow x + 3 \\)
718
+ * - \\( \sqrt{4} \longrightarrow 2 \\)
719
+ * - \\(\frac{4}{10} \longrightarrow \frac{2}{5} \\).
720
+ *
721
+ * However, no calculation is performed involving floating point numbers, so
722
+ * \\( \sqrt(2) \longrightarrow \sqrt(2) \\).
723
+ *
724
+ * Determining the canonical form does not depend on the values assigned to,
725
+ * or assumptions about, symbols.
726
+ */
727
+ get canonical(): BoxedExpression;
728
+ /**
729
+ * Return a simpler form of this expression.
730
+ *
731
+ * The expression is first converted to canonical form. Then a series of
732
+ * rewriting rules are applied repeatedly, until no rules apply.
733
+ *
734
+ * If a custom `simplify` handler is associated with this function definition,
735
+ * it is invoked.
736
+ *
737
+ * The values assigned to symbols and the assumptions about symbols may be
738
+ * used, for example `arg.isInteger` or `arg.isPositive`.
739
+ *
740
+ * No calculations involving floating point numbers are performed but exact
741
+ * calculations may be performed, for example
742
+ * \\( \sin(\frac{\pi}{4}) \longrightarrow \frac{\sqrt{2}}{2} \\).
743
+ *
744
+ * The result is in canonical form.
745
+ *
746
+ */
747
+ simplify(options?: SimplifyOptions): BoxedExpression;
748
+ /**
749
+ * Return the value of this expression.
750
+ *
751
+ * The expression is first converted to canonical form.
752
+ *
753
+ * A pure expression always return the same value and has no side effects.
754
+ * If `this.isPure` is `true`, `this.value` and `this.evaluate()` are synonyms.
755
+ * For an impure expression, `this.value` is undefined.
756
+ *
757
+ * Evaluating an impure expression may have some side effects, for
758
+ * example modifying the `ComputeEngine` environment, such as its set of assumptions.
759
+ *
760
+ * Only exact calculations are performed, no floating point calculations.
761
+ * To perform approximate floating point calculations, use `this.N()` instead.
762
+ *
763
+ * The result of `this.evaluate()` may be the same as `this.simplify()`.
764
+ *
765
+ * The result is in canonical form.
766
+ *
767
+ */
768
+ evaluate(options?: EvaluateOptions): BoxedExpression;
769
+ /** Return a numeric approximation of this expression.
770
+ *
771
+ * The expression is first converted to canonical form.
772
+ *
773
+ * Any necessary calculations, including on floating point numbers,
774
+ * are performed. The calculations are performed according
775
+ * to the `numericMode` and `precision` properties of the `ComputeEngine`.
776
+ *
777
+ * To only perform exact calculations, use `this.evaluate()` instead.
778
+ *
779
+ * If the function is not numeric, the result of `this.N()` is the same as
780
+ * `this.evaluate()`.
781
+ *
782
+ * The result is in canonical form.
783
+ */
784
+ N(options?: NOptions): BoxedExpression;
785
+ solve(vars: Iterable<string>): null | BoxedExpression[];
786
+ /**
787
+ * If this expression is a function, apply the function `fn` to all its operands.
788
+ * Replace the head of this expression with `head`, if defined.
789
+ *
790
+ * If this expression is a dictionary, return a new dictionary with the values
791
+ * modified by `fn`.
792
+ *
793
+ * If `head` is provided, return a function
794
+ * with the modified dictionary as operand, otherwise return the
795
+ * modified dictionary. */
796
+ apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
797
+ /**
798
+ * Transform the expression by according to the rules:
799
+ * the matching `lhs` of a rule is replaced by its `rhs`.
800
+ *
801
+ * If no rules apply, return `null`.
802
+ *
803
+ * See also `subs` for a simple substitution.
804
+ */
805
+ replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
806
+ /**
807
+ * Replace all the symbols in the expression as indicated.
808
+ *
809
+ * Note the same effect can be achieved with `this.replace()`, but
810
+ * using `this.subs()` is more efficient, and simpler.
811
+ *
812
+ */
813
+ subs(sub: Substitution): BoxedExpression;
814
+ /**
815
+ * Update the definition associated with this expression, taking
816
+ * into account the current context.
817
+ *
818
+ * @internal
819
+ */
820
+ _repairDefinition(): void;
821
+ /** Purge any cached values.
822
+ *
823
+ * @internal
824
+ */
825
+ _purge(): undefined;
826
+ }
827
+ /** A semi boxed expression is an MathJSON expression which can include some
828
+ * boxed terms.
27
829
  *
28
- * As a shorthand for a numeric symbol definition, a number can be used as
29
- * well. In that case the domain is determined automatically.
830
+ * This is convenient when creating new expressions from portions
831
+ * of an existing `BoxedExpression` while avoiding unboxing and reboxing.
832
+ */
833
+ export declare type SemiBoxedExpression = BoxedExpression | number | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | string | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[];
834
+ export declare type LambdaExpression = SemiBoxedExpression;
835
+ export declare type BoxedLambdaExpression = BoxedExpression;
836
+ export declare type PatternMatchOption = {
837
+ recursive?: boolean;
838
+ numericTolerance?: number;
839
+ exact?: boolean;
840
+ };
841
+ export interface Pattern extends BoxedExpression {
842
+ /**
843
+ * If `expr` does not match the pattern, return `null`.
844
+ *
845
+ * Otherwise, return a substitution describing the values that the named
846
+ * wildcard in the pattern should be changed to in order for the pattern to be
847
+ * equal to the expression. If there are no named wildcards and the expression
848
+ * matches the pattern, and empty object literal `{}` is returned.
849
+ */
850
+ match(expr: BoxedExpression, options?: PatternMatchOption): Substitution | null;
851
+ /** If `expr` matches the pattern, return `true`, otherwise `false` */
852
+ test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
853
+ /** Return the number of exprs that matched the pattern */
854
+ count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOption): number;
855
+ subs(sub: Substitution): Pattern;
856
+ }
857
+ export interface ExpressionMapInterface<U> {
858
+ has(expr: BoxedExpression): boolean;
859
+ get(expr: BoxedExpression): U | undefined;
860
+ set(expr: BoxedExpression, value: U): void;
861
+ delete(expr: BoxedExpression): void;
862
+ clear(): void;
863
+ [Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
864
+ }
865
+ /**
866
+ * A dictionary contains definitions for symbols, functions and rules.
30
867
  *
31
- * ```json
32
- * { "x": 1.0 }
33
- * { "x" : { "domain": "RealNumber", "value": 1.0 } }
34
- * ```
35
868
  */
36
- export declare type Dictionary<T extends number = number> = {
37
- [name: string]: T | Definition<T>;
869
+ export declare type Dictionary = {
870
+ symbols?: SymbolDefinition[];
871
+ functions?: FunctionDefinition[];
872
+ simplifyRules?: BoxedRuleSet;
38
873
  };
39
874
  /**
40
875
  * The entries of a `CompiledDictionary` have been validated and
41
876
  * optimized for faster evaluation.
42
877
  *
43
878
  * When a new scope is created with `pushScope()` or when creating a new
44
- * engine instance, new instances of `CompiledDictionary` are created as needed.
879
+ * engine instance, new instances of `RuntimeDictionary` are created as needed.
45
880
  */
46
- export declare type CompiledDictionary<T extends number = number> = Map<string, Definition<T>>;
881
+ export declare type RuntimeDictionary = {
882
+ symbols: Map<string, BoxedSymbolDefinition>;
883
+ symbolWikidata: Map<string, BoxedSymbolDefinition>;
884
+ functions: Map<string, BoxedFunctionDefinition[]>;
885
+ functionWikidata: Map<string, BoxedFunctionDefinition>;
886
+ };
47
887
  /**
48
888
  * A scope is a set of names in a dictionary that are bound (defined) in
49
889
  * a MathJSON expression.
@@ -65,23 +905,33 @@ export declare type Scope = {
65
905
  warn?: WarningSignalHandler;
66
906
  /** Signal `timeout` when the execution time for this scope is exceeded.
67
907
  * Time in seconds, default 2s.
908
+ *
909
+ * @experimental
68
910
  */
69
911
  timeLimit?: number;
70
912
  /** Signal `out-of-memory` when the memory usage for this scope is exceeded.
71
913
  * Memory in Megabytes, default: 1Mb.
914
+ *
915
+ * @experimental
72
916
  */
73
917
  memoryLimit?: number;
74
918
  /** Signal `recursion-depth-exceeded` when the recursion depth for this
75
- * scope is exceeded. */
919
+ * scope is exceeded.
920
+ *
921
+ * @experimental
922
+ */
76
923
  recursionLimit?: number;
77
924
  /** Signal `iteration-limit-exceeded` when the iteration limit for this
78
- * scope is exceeded. Default: no limits.*/
925
+ * scope is exceeded. Default: no limits.
926
+ *
927
+ * @experimental
928
+ */
79
929
  iterationLimit?: number;
80
930
  };
81
- export declare type RuntimeScope<T extends number = number> = Scope & {
82
- parentScope: RuntimeScope<T>;
83
- dictionary?: CompiledDictionary<T>;
84
- assumptions: undefined | ExpressionMap<T, boolean>;
931
+ export declare type RuntimeScope = Scope & {
932
+ parentScope: RuntimeScope;
933
+ dictionary?: RuntimeDictionary;
934
+ assumptions: undefined | ExpressionMapInterface<boolean>;
85
935
  /** The location of the call site that created this scope */
86
936
  origin?: {
87
937
  name?: string;
@@ -93,556 +943,675 @@ export declare type RuntimeScope<T extends number = number> = Scope & {
93
943
  /** Set when one or more warnings have been signaled in this scope */
94
944
  warnings?: WarningSignal[];
95
945
  };
946
+ export declare type BaseDefinition = {
947
+ /** The name of the symbol or function for this definition
948
+ *
949
+ * The name of a symbol or function is an arbitrary string of Unicode
950
+ * characters, however the following conventions are recommended:
951
+ *
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
955
+ *
956
+ */
957
+ name: string;
958
+ /** A short (about 1 line) description. May contain Markdown. */
959
+ description?: string | string[];
960
+ /** A URL pointing to more information about this symbol or head. */
961
+ url?: string;
962
+ /**
963
+ * A short string representing an entry in a wikibase.
964
+ *
965
+ * For example `Q167` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
966
+ * for the `Pi` constant.
967
+ */
968
+ 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
+ };
982
+ export declare type BoxedBaseDefinition = {
983
+ name: string;
984
+ wikidata?: string;
985
+ description?: string | string[];
986
+ url?: string;
987
+ /**
988
+ * The scope this definition belongs to.
989
+ *
990
+ * This field is usually undefined, but its value is set by `getDefinition()`
991
+ */
992
+ scope: RuntimeScope | undefined;
993
+ domain?: BoxedExpression;
994
+ _purge(): undefined;
995
+ };
96
996
  /**
97
- * A function definition can have some flags set indicating specific
997
+ * A function definition can have some flags to indicate specific
98
998
  * properties of the function.
99
999
  */
100
- export declare type FunctionFeatures = {
1000
+ export declare type FunctionDefinitionFlags = {
101
1001
  /** If true, the function is applied element by element to lists, matrices
102
1002
  * and equations.
103
1003
  *
104
- * Default: false
1004
+ * **Default**: `false`
105
1005
  */
106
1006
  threadable: boolean;
107
- /** If true, [f, [f, a], b] simplifies to [f, a, b]
1007
+ /** If true, `["f", ["f", a], b]` simplifies to `["f", a, b]`
108
1008
  *
109
- * Default: false
1009
+ * **Default**: `false`
110
1010
  */
111
1011
  associative: boolean;
112
- /** If true, [f, a, b] simplifies to [f, b, a]
1012
+ /** If true, `["f", a, b]` equals `["f", b, a]`. The canonical
1013
+ * version of the function will order the arguments.
113
1014
  *
114
- * Default: false
1015
+ * **Default**: `false`
115
1016
  */
116
1017
  commutative: boolean;
117
- /** If true, when the function is univariate, `[f, ["Add", x, c]]` where `c`
118
- * is constant, is simplified to `["Add", [f, x], c]`.
1018
+ /** If true, when the function is univariate, `["f", ["Add", x, c]]` where `c`
1019
+ * is constant, is simplified to `["Add", ["f", x], c]`.
119
1020
  *
120
1021
  * When the function is multivariate, additivity is considered only on the
121
- * first argument: `[f, ["Add", x, c], y]` simplifies to `["Add", [f, x, y], c]`.
1022
+ * first argument: `["f", ["Add", x, c], y]` simplifies to `["Add", ["f", x, y], c]`.
122
1023
  *
123
- * Default: false
1024
+ * For example, `Log` is additive.
1025
+ *
1026
+ * **Default**: `false`
124
1027
  */
125
- additive: boolean;
126
- /** If true, when the function is univariate, `[f, ["Multiply", x, y]]`
127
- * simplifies to `["Multiply", [f, x], [f, y]]`.
1028
+ /** If true, when the function is univariate, `["f", ["Multiply", x, y]]`
1029
+ * simplifies to `["Multiply", ["f", x], ["f", y]]`.
128
1030
  *
129
- * When the function is multivariate, multipicativity is considered only on the
130
- * first argument: `[f, ["Multiply", x, y], z]` simplifies to
131
- * `["Multiply", [f, x, z], [f, y, z]]`
1031
+ * When the function is multivariate, multiplicativity is considered only on the
1032
+ * first argument: `["f", ["Multiply", x, y], z]` simplifies to
1033
+ * `["Multiply", ["f", x, z], ["f", y, z]]`
132
1034
  *
133
- * Default: false
1035
+ * **Default**: `false`
134
1036
  */
135
- multiplicative: boolean;
136
- /** If true, when the function is univariate, `[f, ["Multiply", x, c]]`
137
- * simplifies to `["Multiply", [f, x], c]` where `c` is constant
1037
+ /** If true, when the function is univariate, `["f", ["Multiply", x, c]]`
1038
+ * simplifies to `["Multiply", ["f", x], c]` where `c` is constant
138
1039
  *
139
1040
  * When the function is multivariate, multiplicativity is considered only on the
140
- * first argument: `[f, ["Multiply", x, y], z]` simplifies to
141
- * `["Multiply", [f, x, z], [f, y, z]]`
1041
+ * first argument: `["f", ["Multiply", x, y], z]` simplifies to
1042
+ * `["Multiply", ["f", x, z], ["f", y, z]]`
142
1043
  *
143
- * Default: false
1044
+ * Default: `false`
144
1045
  */
145
- outtative: boolean;
146
- /** If true, `[f, [f, x]]` simplifies to `[f, x]`.
1046
+ /** If true, `["f", ["f", x]]` simplifies to `["f", x]`.
147
1047
  *
148
- * Default: false
1048
+ * **Default**: `false`
149
1049
  */
150
1050
  idempotent: boolean;
151
- /** If true, `[f, [f, x]]` simplifies to `x`.
1051
+ /** If true, `["f", ["f", x]]` simplifies to `x`.
152
1052
  *
153
- * Default: false
1053
+ * **Default**: `false`
154
1054
  */
155
1055
  involution: boolean;
156
1056
  /**
157
- * If true, the input arguments and the result are expected to be `number`.
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`
158
1061
  *
159
1062
  * Default: false
160
1063
  */
161
1064
  numeric: boolean;
162
- /** If true, invoking the function with a given set of arguments will
163
- * always return the same value, i.e. `Sin` is pure, `Random` isn't.
164
- * This is used to cache the result of the function.
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`
165
1070
  *
166
- * Default: true
1071
+ * **Default:** false
167
1072
  */
168
- pure: boolean;
169
- };
170
- /** A domain such as 'Number' or 'Boolean' represents a set of values.
171
- *
172
- * Domains can be defined as a union or intersection of domains:
173
- * - `["Union", "Number", "Boolean"]` A number or a boolean.
174
- * - `["SetMinus", "Number", 1]` Any number except "1".
175
- *
176
- * Domains are defined in a hierarchy (a lattice).
177
- */
178
- export declare type Domain<T extends number = number> = Expression<T>;
179
- export declare type BaseDefinition<T extends number = number> = {
180
- domain: Domain<T> | ((...args: Expression<T>[]) => Domain<T>);
1073
+ logic: boolean;
181
1074
  /**
182
- * A short string representing an entry in a wikibase.
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.
183
1078
  *
184
- * For example `Q167` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
185
- * for the `Pi` constant.
1079
+ * For example, `Equal`, `Less`, `Approx`, etc...
1080
+ *
1081
+ * **Default:** false
186
1082
  */
187
- wikidata?: string;
1083
+ relationalOperator: boolean;
1084
+ /** If true, the value of this function is always the same for a given
1085
+ * set of arguments and it has no side effects.
1086
+ *
1087
+ * An expression using this function is pure if the function and all its
1088
+ * arguments are pure.
1089
+ *
1090
+ * For example `Sin` is pure, `Random` isn't.
1091
+ *
1092
+ * This information may be used to cache the value of expressions.
1093
+ *
1094
+ * **Default:** true
1095
+ */
1096
+ pure: boolean;
188
1097
  /**
189
- * The scope this definition belongs to.
1098
+ * An inert function evaluates directly to one of its argument, typically
1099
+ * the first one. They may be used to provide formating hints, but do
1100
+ * not affect simplification or evaluation.
190
1101
  *
191
- * This field is usually undefined, but its value is set by `getDefinition()`,
192
- * `getFunctionDefinition()` and `getSymbolDefinition()`.
1102
+ * **Default:** false
193
1103
  */
194
- scope?: Scope;
1104
+ inert: boolean;
195
1105
  };
196
1106
  /**
197
- *
1107
+ * Definition record for a function.
198
1108
  *
199
1109
  */
200
- export declare type FunctionDefinition<T extends number = number> = BaseDefinition<T> & Partial<FunctionFeatures> & {
1110
+ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
201
1111
  /**
202
- * - `none`: Each of the arguments is evaluated
203
- * - `all`: The arguments will not be evaluated and will be passed as is
204
- * - `first`: The first argument is not evaluated, the others are
205
- * - `rest`: The first argument is evaluated, the others aren't
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
206
1129
  */
207
- hold?: 'none' | 'all' | 'first' | 'rest';
1130
+ complexity?: number;
208
1131
  /**
209
- * If true, `Sequence` arguments are not automatically spliced in
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
210
1136
  */
211
- sequenceHold?: boolean;
1137
+ hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
212
1138
  /**
213
- * The number and domains of the arguments for this function.
214
- *
1139
+ * If true, `Sequence` arguments appearing in the arguments of a function
1140
+ * should not automatically be flattened out
215
1141
  */
216
- inputDomain?: Domain[];
1142
+ sequenceHold?: boolean;
1143
+ /** The minimum and maximum values of the result of the function */
1144
+ range?: [min: number, max: number];
217
1145
  /**
1146
+ * Return the canonical form of the expression with the arguments `args`.
218
1147
  *
219
- * The domain of the result.
1148
+ * All the arguments that are not subject to a hold are in canonical form.
1149
+ * Any `Nothing` argument has been removed.
220
1150
  *
221
- * If `range` is a function, the arguments of `range()` are the
222
- * the arguments of the function. The `range()` function can
223
- * make use of available assumptions to determine its result.
1151
+ * If the function is associative, idempotent or an involution,
1152
+ * it should handle its arguments accordingly. Notably, if it
1153
+ * is commutative, the arguments should be sorted in canonical order.
224
1154
  *
225
- * The range should be as precise as possible. A range of
226
- * `Anything` is correct, but won't be very helpful.
1155
+ * The handler can make transformations based on the value of the arguments
1156
+ * that are literal and either rational numbers (i.e.
1157
+ * `arg.isLiteral && arg.isRational`) or integers (i.e.
1158
+ * `isLiteral && arg.isInteger`).
227
1159
  *
228
- * A range of `Number` is good, a range of `RealNumber` is better
229
- * and a range of `["Interval", 0, "+Infinity"]` is even better.
1160
+ * The handler should not consider the value of the arguments
1161
+ * that are symbols or functions.
230
1162
  *
231
- */
232
- range: Domain<T> | ((engine: ComputeEngine, ...args: Expression<T>[]) => Expression<T>);
233
- /**
234
- * The value of this function, as a lambda function.
235
- * The arguments are `_`, `_2`, `_3`, etc...
1163
+ * The handler should not consider any assumptions about any of the
1164
+ * arguments that are symbols or functions i.e. `arg.isZero`,
1165
+ * `arg.isInteger`, etc...
1166
+ *
1167
+ * The handler should not make transformations based on the value of
1168
+ * floating point numbers.
1169
+ *
1170
+ * The result of the handler should be a canonical expression.
236
1171
  *
237
- * This property may be used to perform some simplification, or
238
- * to numerically evaluate the function if no `evalNumber` property
239
- * is provided.
240
1172
  */
241
- value?: T | Expression;
1173
+ canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
242
1174
  /**
243
- * Rewrite the expression into a simplified form.
1175
+ * Rewrite an expression into a simpler form.
244
1176
  *
245
- * If appropriate, make use of assumptions with `ce.is()`.
1177
+ * The arguments are in canonical form and have been simplified.
246
1178
  *
247
- * Do not resolve the values of variables, that is `ce.simplify("x+1")` is
248
- * `x + 1` even if `x = 0`. However, resolving constants is OK.
1179
+ * The handler can use the values assigned to symbols and the assumptions about
1180
+ * symbols, for example with `arg.machineValue`, `arg.isInteger` or
1181
+ * `arg.isPositive`.
249
1182
  *
250
- * Do not make approximate evaluations (i.e. floating point operations).
1183
+ * Even though a symbol may not have a value, there may be some information
1184
+ * about it reflected for example in `this.isZero` or `this.isPrime`.
251
1185
  *
252
- * Do not perform complex or lengthy operations: do these in `ce.evaluate()`.
1186
+ * The handler should not perform approximate numeric calculations, such
1187
+ * as calculations involving floating point numbers. Making exact
1188
+ * calculations on integers or rationals is OK. It is recommended, but not
1189
+ * required, that the calculations be limited to `this.smallIntegerValue`
1190
+ * (i.e. numeric representations of the expression as an integer of small
1191
+ * magnitude).
253
1192
  *
254
- * Only make simple rewrites of the expression.
1193
+ * This handler should not have any side-effects: do not modify
1194
+ * the environment of the `ComputeEngine` instance, do not perform I/O,
1195
+ * do not do calculations that depend on random values.
1196
+ *
1197
+ * If no simplification can be performed due to the values, domains or assumptions
1198
+ * about its arguments, for example, return `undefined`.
255
1199
  *
256
- * The passed-in arguments have been simplified already,
257
- * except for those to which a `hold` apply.
258
1200
  */
259
- simplify?: (engine: ComputeEngine, ...args: Expression<T>[]) => Expression<T>;
1201
+ simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
260
1202
  /**
261
- * Make a numeric evaluation of the arguments.
1203
+ * Evaluate symbolically an expression.
262
1204
  *
263
- * The passed-in arguments have already been numerically evaluated
264
- * unless the arguments have a `hold` property.
1205
+ * The arguments have been symbolically evaluated, except the arguments to
1206
+ * which a `hold` apply.
1207
+ *
1208
+ * It is not necessary to further simplify or evaluate the arguments.
1209
+ *
1210
+ * If the expression cannot be evaluated, due to the values, domains, or
1211
+ * assumptions about its arguments, for example, return `undefined`.
265
1212
  *
266
- * If the function is `numeric` all the arguments are guaranteed to be
267
- * numbers and the function should return a number.
268
1213
  *
269
1214
  */
270
- evalNumber?: (engine: ComputeEngine, ...args: number[]) => number;
271
- /** Like `evalNumber()` but for `Complex` numbers */
272
- evalComplex?: (engine: ComputeEngine, ...args: (number | Complex)[]) => Complex;
273
- /** Live `evalNumber()` but for Decimal numbers (arbitrary large floating
274
- * point numbers).
275
- */
276
- evalDecimal?: (engine: ComputeEngine, ...args: (number | Decimal)[]) => Decimal;
1215
+ evaluate?: LambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
277
1216
  /**
278
- * Evaluate the arguments.
1217
+ * Evaluate numerically an expression.
279
1218
  *
280
- * This will be invoked by the `ce.evaluate()` function, and
281
- * after the `simplify()` and `evalNumber()` definition methods have been
282
- * called.
1219
+ * The arguments `args` have been simplified and evaluated, numerically
1220
+ * if possible, except the arguments to which a `hold` apply.
283
1221
  *
284
- * If a function must perform any computations that may take a long time
285
- * (>100ms), because they are computationally expensive, or because they
286
- * require a network fetch, defer these computations to `ce.evaluate()`
287
- * rather than `ce.simplify()`.
1222
+ * The arguments may be a combination of numbers, symbolic
1223
+ * expressions and other expressions.
288
1224
  *
289
- * If a synchronous `ce.evaluate()` function is provided it will be used and
290
- * `ce.evaluateAsync()` will not be called.
1225
+ * Perform as many calculations as possible, and return the result.
291
1226
  *
292
- * The arguments have been simplified and numerically evaluated, except
293
- * the arguments to which a `hold` apply.
294
- */
295
- evaluate?: (engine: ComputeEngine, ...args: Expression<T>[]) => Expression<T>;
296
- evaluateAsync?: (engine: ComputeEngine, ...args: Promise<Expression<T>>[]) => Promise<Expression<T>>;
297
- /** Return a compiled (optimized) function. */
298
- compile?: (engine: ComputeEngine, ...args: CompiledExpression<T>[]) => CompiledExpression<T>;
299
- /** Dimensional analysis */
300
- dimension?: (engine: ComputeEngine, ...args: Expression<T>[]) => Expression<T>;
301
- };
302
- export declare type SymbolFeatures = {
303
- /**
304
- * If true the value of the symbol is constant.
1227
+ * Return `undefined` if there isn't enough information to perform
1228
+ * the evaluation, for example one of the arguments is a symbol with
1229
+ * no value. If the handler returns `undefined`, symbolic evaluation of
1230
+ * the expression will be returned instead to the caller.
1231
+ *
1232
+ * Return `NaN` if there is enough information to perform the
1233
+ * evaluation, but a literal argument is out of range or
1234
+ * not of the expected type.
1235
+ *
1236
+ * Also return `NaN` if the result of the evaluation would be a complex
1237
+ * number, but complex numbers are not allowed (the `engine.numericMode`
1238
+ * is not `complex` or `auto`).
1239
+ *
1240
+ * If the `ce.numericMode` is `auto` or `complex`, you may return
1241
+ * a Complex number as a result. Otherwise, if the result is a complex
1242
+ * value, return `NaN`. If Complex are not allowed, none of the arguments
1243
+ * will be complex literals.
1244
+ *
1245
+ * If the `ce.numericMode` is `decimal` or `auto` and
1246
+ * `this.engine.precision` is > 15, you may return a Decimal number.
1247
+ * Otherwise, return a `machine` number approximation. If Decimal are
1248
+ * not allowed, none of the arguments will be Decimal literal.
1249
+ *
1250
+ * You may perform any necessary computations, including approximate
1251
+ * calculations on floating point numbers.
305
1252
  *
306
- * If false, the symbol is a variable.
307
1253
  */
308
- constant: boolean;
1254
+ N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
309
1255
  /**
310
- * If false, the value of the symbol is substituted during a `ce.simplify().
311
- * If true, the symbol is unchanged during a `ce.simplify()` and the value
312
- * is only used during a `ce.N()` or `ce.evaluate()`.
313
1256
  *
314
- * True by default;
315
- */
316
- hold?: boolean;
317
- };
318
- export declare type SymbolDefinition<T extends number = number> = BaseDefinition<T> & SymbolFeatures & {
319
- value?: Expression<T> | ((ce: ComputeEngine) => Expression<T>);
320
- /** For dimensional analysis, e.g. `Scalar`, `Meter`, `["Divide", "Meter", "Second"]` */
321
- unit?: Expression<T>;
322
- };
323
- export declare type CollectionDefinition<T extends number = number> = BaseDefinition<T> & {
324
- /** If true, the elements of the collection can be iterated over using
325
- * the `iterator() function
326
- */
327
- iterable?: boolean;
328
- iterator?: {
329
- next: () => Expression<T>;
330
- done: () => boolean;
331
- };
332
- /** If true, elements of the collection can be accessed with a numerical
333
- * index with the `at()` function
334
- */
335
- indexable?: boolean;
336
- at?: (index: number) => Expression<T>;
337
- /** If true, the size of the collection is finite.
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.
338
1277
  *
339
1278
  */
340
- countable: boolean;
341
- /** Return the number of elements in the collection.
342
- */
343
- size?: () => number;
344
- /** A predicate function to determine if an expression
345
- * is a member of the collection or not (answers `True`, `False` or `Maybe`).
346
- */
347
- isElementOf?: (expr: Expression<T>) => boolean;
348
- };
349
- export declare type SetDefinition<T extends number = number> = CollectionDefinition<T> & {
350
- /** The supersets of this set: they should be symbol with a `Set` domain */
351
- supersets: string[];
352
- /** If a set can be defined explicitely in relation to other sets,
353
- * the `value` represents that relationship.
354
- * For example `"NaturalNumber"` = `["Union", "PrimeNumber", "CompositeNumber"]`.
355
- */
356
- value?: Expression<T>;
357
- /**
358
- * A function that determins if a set is a subset of another.
359
- * The `rhs` argument is either the name of the symbol, or a function
360
- * with the head of the symbol.
1279
+ evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
1280
+ /** Dimensional analysis
1281
+ * @experimental
361
1282
  */
362
- isSubsetOf?: (engine: ComputeEngine, lhs: Expression<T>, rhs: Expression<T>) => boolean;
1283
+ evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1284
+ /** Return the sign of the function given a list of arguments. */
1285
+ sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
1286
+ /** Return a compiled (optimized) expression. */
1287
+ compile?: (expr: BoxedExpression) => CompiledExpression;
363
1288
  };
364
- export declare type Definition<T extends number = number> = SymbolDefinition<T> | FunctionDefinition | SetDefinition | CollectionDefinition<T>;
365
- export declare type CompiledExpression<T extends number = number> = {
366
- evaluate?: (scope: {
367
- [symbol: string]: T | Expression<T>;
368
- }) => Expression<T>;
369
- asyncEvaluate?: (scope: {
370
- [symbol: string]: T | Expression<T>;
371
- }) => Promise<T | Expression<T>>;
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];
1294
+ canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1295
+ simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1296
+ evaluate?: BoxedLambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1297
+ N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1298
+ evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
1299
+ evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1300
+ sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
1301
+ compile?: (expr: BoxedExpression) => CompiledExpression;
372
1302
  };
373
- export declare type Simplification = 'simplify-all' | 'simplify-arithmetic';
374
- export declare type NumericFormat = 'auto' | 'machine' | 'decimal' | 'complex';
375
1303
  /**
376
- * Create a `CustomEngine` instance to customize its behavior and the syntax
377
- * and operation dictionaries it uses.
1304
+ * When used in a `SymbolDefinition`, these flags are optional.
1305
+ *
1306
+ * If provided, they will override the value derived from
1307
+ * the symbol's value.
378
1308
  *
379
- * The constructor of `ComputeEngine` will compile and optimize the dictionary
380
- * upfront.
1309
+ * For example, it might be useful to override `algebraic = false`
1310
+ * for a transcendental number.
381
1311
  */
382
- export declare class ComputeEngine<T extends number = Numeric> {
1312
+ export declare type SymbolFlags = {
1313
+ number: boolean | undefined;
1314
+ integer: boolean | undefined;
1315
+ rational: boolean | undefined;
1316
+ algebraic: boolean | undefined;
1317
+ real: boolean | undefined;
1318
+ extendedReal: boolean | undefined;
1319
+ complex: boolean | undefined;
1320
+ extendedComplex: boolean | undefined;
1321
+ imaginary: boolean | undefined;
1322
+ positive: boolean | undefined;
1323
+ nonPositive: boolean | undefined;
1324
+ negative: boolean | undefined;
1325
+ nonNegative: boolean | undefined;
1326
+ zero: boolean | undefined;
1327
+ notZero: boolean | undefined;
1328
+ one: boolean | undefined;
1329
+ negativeOne: boolean | undefined;
1330
+ infinity: boolean | undefined;
1331
+ NaN: boolean | undefined;
1332
+ finite: boolean | undefined;
1333
+ even: boolean | undefined;
1334
+ odd: boolean | undefined;
1335
+ prime: boolean | undefined;
1336
+ composite: boolean | undefined;
1337
+ };
1338
+ export declare type SymbolDefinitionFlags = {
383
1339
  /**
384
- * Return dictionaries suitable for the specified categories, or `"all"`
385
- * for all categories (`"arithmetic"`, `"algebra"`, etc...).
386
- *
387
- * A symbol dictionary defines how the symbols and function names in a MathJSON
388
- * expression should be interpreted, i.e. how to evaluate and manipulate them.
1340
+ * If true the value of the symbol is constant.
389
1341
  *
1342
+ * If false, the symbol is a variable.
390
1343
  */
391
- static getDictionaries(categories: DictionaryCategory[] | 'all'): Readonly<Dictionary<any>>[];
1344
+ constant: boolean;
392
1345
  /**
393
- * The current scope.
394
- *
395
- * A scope is a dictionary that contains the definition of local symbols.
1346
+ * If false, the value of the symbol is substituted during canonicalization
1347
+ * or simplification.
396
1348
  *
397
- * Scopes form a stack, and definitions in more recent
398
- * scopes can obscure definitions from older scopes.
1349
+ * If true, the value is only replaced during a `ce.N()` or `ce.evaluate()`.
399
1350
  *
1351
+ * **Default:** `true`
400
1352
  */
401
- context: RuntimeScope<T>;
402
- readonly assumptions: ExpressionMap<T, boolean>;
403
- /** Absolute time beyond which evaluation should not proceed */
404
- deadline?: number;
405
- readonly timeLimit?: number;
406
- readonly iterationLimit?: number;
407
- readonly recursionLimit?: number;
408
- /** The default precision of the compute engine: the number of significant
409
- * digits when performing numeric evaluations, such as when calling `ce.N()`.
410
- *
411
- * To make calculations using machine floating point representation, set
412
- * `precision` to `"machine"` (15 by default).
413
- *
414
- * To make calculations using more digits, at the cost of expended memory
415
- * usage and slower computations, set the `precision` higher.
416
- *
417
- * Trigonometric operations are accurate for precision up to 1,000.
418
- *
419
- * Some functions, such as `ce.N()` have an option to specify the precision.
420
- * If no precision is specified in these functions, the precision of
421
- * the compute engine is used.
422
- *
1353
+ hold: boolean;
1354
+ };
1355
+ /**
1356
+ * A bound symbol (i.e. one with an associated definition) has either a domain
1357
+ * (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumber)
1358
+ */
1359
+ export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & Partial<SymbolDefinitionFlags> & {
1360
+ /** `value` can be a function since for some constants, such as
1361
+ * `Pi`, the actual value depends on the `precision` setting of the
1362
+ * `ComputeEngine` */
1363
+ value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
1364
+ domain?: string | BoxedExpression;
1365
+ };
1366
+ export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
1367
+ get value(): BoxedExpression | undefined;
1368
+ set value(val: BoxedExpression | undefined);
1369
+ at?: (index: string | number) => undefined | BoxedExpression;
1370
+ }
1371
+ export declare type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1372
+ export declare type CompiledExpression = {
1373
+ evaluate?: (scope: {
1374
+ [symbol: string]: BoxedExpression;
1375
+ }) => number | BoxedExpression;
1376
+ };
1377
+ export interface ComputeEngineStats {
1378
+ symbols: Set<BoxedExpression>;
1379
+ expressions: null | Set<BoxedExpression>;
1380
+ highwaterMark: number;
1381
+ }
1382
+ /** @internal */
1383
+ export interface IComputeEngine {
1384
+ /** @internal */
1385
+ readonly ZERO: BoxedExpression;
1386
+ /** @internal */
1387
+ readonly ONE: BoxedExpression;
1388
+ /** @internal */
1389
+ readonly TWO: BoxedExpression;
1390
+ /** @internal */
1391
+ readonly HALF: BoxedExpression;
1392
+ /** @internal */
1393
+ readonly NEGATIVE_ONE: BoxedExpression;
1394
+ /** @internal */
1395
+ readonly I: BoxedExpression;
1396
+ /** @internal */
1397
+ readonly NAN: BoxedExpression;
1398
+ /** @internal */
1399
+ readonly POSITIVE_INFINITY: BoxedExpression;
1400
+ /** @internal */
1401
+ readonly NEGATIVE_INFINITY: BoxedExpression;
1402
+ /** @internal */
1403
+ readonly COMPLEX_INFINITY: BoxedExpression;
1404
+ /** @internal */
1405
+ readonly DECIMAL_NAN: Decimal;
1406
+ /** @internal */
1407
+ readonly DECIMAL_ZERO: Decimal;
1408
+ /** @internal */
1409
+ readonly DECIMAL_ONE: Decimal;
1410
+ /** @internal */
1411
+ readonly DECIMAL_TWO: Decimal;
1412
+ /** @internal */
1413
+ readonly DECIMAL_HALF: Decimal;
1414
+ /** @internal */
1415
+ readonly DECIMAL_PI: Decimal;
1416
+ /** @internal */
1417
+ readonly DECIMAL_NEGATIVE_ONE: Decimal;
1418
+ /** The current scope */
1419
+ context: RuntimeScope;
1420
+ /** Absolute time beyond which evaluation should not proceed
1421
+ * @internal
423
1422
  */
1423
+ deadline?: number;
1424
+ /** @experimental */
1425
+ readonly timeLimit: number;
1426
+ /** @experimental */
1427
+ readonly iterationLimit: number;
1428
+ /** @experimental */
1429
+ readonly recursionLimit: number;
1430
+ defaultDomain: null | BoxedExpression;
1431
+ /** {@inheritDoc NumericMode} */
1432
+ numericMode: NumericMode;
1433
+ tolerance: number;
1434
+ chop(n: number): number;
1435
+ chop(n: Decimal): Decimal | 0;
1436
+ chop(n: Complex): Complex | 0;
1437
+ chop(n: number | Decimal | Complex): number | Decimal | Complex;
1438
+ /** @internal */
1439
+ decimal: (a: Decimal.Value) => Decimal;
1440
+ /** @internal */
1441
+ complex: (a: number | Complex, b?: number) => Complex;
424
1442
  set precision(p: number | 'machine');
425
1443
  get precision(): number;
1444
+ costFunction: (expr: BoxedExpression) => number;
426
1445
  /**
427
- * Internal format to represent numbers:
428
- * - `auto`: the best format is determined based on the calculations to perform
429
- * and the requested precision.
430
- * - `number`: use the machine format (64-bit float, 52-bit, about 15 digits
431
- * of precision).
432
- * - `decimal`: arbitrary precision floating-point numbers, as provided by the
433
- * "decimal.js" library
434
- * - `complex`: complex numbers: two 64-bit float, as provided by the
435
- * "complex.js" library
1446
+ * Associate a new definition to a symbol in the current context.
436
1447
  *
1448
+ * If a definition existed previously, it is replaced.
437
1449
  */
438
- numericFormat: NumericFormat;
1450
+ defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
1451
+ getSymbolDefinition(name: string, wikidata?: string): undefined | BoxedSymbolDefinition;
439
1452
  /**
440
- * Values smaller than the tolerance are considered to be zero for the
441
- * purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
442
- * equal to `a`.
1453
+ * Return `undefined` if no definition exist for this `head.
443
1454
  */
444
- tolerance: number;
1455
+ getFunctionDefinition(head: string, wikidata?: string): undefined | BoxedFunctionDefinition;
445
1456
  /**
446
- * Construct a new `ComputeEngine` environment.
1457
+ * Returned a boxed expression from the input.
447
1458
  *
448
- * If no `options.dictionaries` is provided a default set of dictionaries
449
- * is used. The `ComputeEngine.getDictionaries()` method can be called
450
- * to access some subset of dictionaries, e.g. for arithmetic, calculus, etc...
451
- * The order of the dictionaries matter: the definitions from the later ones
452
- * override the definitions from earlier ones. The first dictionary should
453
- * be the `'core'` dictionary which include some basic definitions such
454
- * as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
1459
+ * The result may not be canonical.
455
1460
  */
456
- constructor(options?: {
457
- dictionaries?: Readonly<Dictionary<T>>[];
458
- });
459
- /** Create a new scope and add it to the top of the scope stack */
460
- pushScope(dictionary: Readonly<Dictionary<T>>, scope?: Partial<Scope>): void;
461
- /** Remove the topmost scope from the scope stack.
1461
+ box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
1462
+ /** Return a canonical boxed number */
1463
+ number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
1464
+ /** Return a canonical boxed symbol */
1465
+ symbol(sym: string, metadata?: Metadata): BoxedExpression;
1466
+ /** Return a canonical boxed string */
1467
+ 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.
1471
+ *
1472
+ * Note that the result may not be a function, or may have a different
1473
+ * `head` than the one specified.
1474
+ *
1475
+ * For example `ce.fn("Add", [ce.number(2), ce.number(3)]))` \( \to \) 5
1476
+ *
462
1477
  */
463
- popScope(): void;
1478
+ fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
464
1479
  /**
465
- * Call this function if an unexpected condition occurs during execution of a
466
- * function in the engine.
1480
+ * This is a primitive to create a boxed function. It doesn't perform
1481
+ * any checks or normalization on its arguments.
467
1482
  *
468
- * An `ErrorSignal` is a problem that cannot be recovered from.
1483
+ * In general, consider using `fn()` or `box()` instead.
469
1484
  *
470
- * A `WarningSignal` indicates a minor problem that does not prevent the
471
- * execution to continue.
1485
+ * 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.
1488
+ */
1489
+ _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1490
+ /** Shortcut for `this.fn("Error"...)`.
472
1491
  *
1492
+ * The result is canonical.
473
1493
  */
474
- signal(sig: ErrorSignal | WarningSignal): void;
475
- /**
476
- * Return false if the execution should stop.
1494
+ error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): any;
1495
+ /** Shortcut for `this.fn("Add"...)`.
477
1496
  *
478
- * This can occur if:
479
- * - an error has been signaled
480
- * - the time limit or memory limit has been exceeded
1497
+ * The result is canonical.
481
1498
  */
482
- shouldContinueExecution(): boolean;
483
- checkContinueExecution(): void;
484
- getFunctionDefinition(name: string): FunctionDefinition | null;
485
- getSymbolDefinition(name: string): SymbolDefinition<T> | null;
486
- getSetDefinition(name: string): SetDefinition | null;
487
- getCollectionDefinition(name: string): CollectionDefinition<T> | null;
488
- getDefinition(name: string): Definition<T> | null;
489
- /** Format the expression to the canonical form.
1499
+ add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1500
+ /** Shortcut for `this.fn("Multiply"...)`
490
1501
  *
491
- * In the canonical form, some operations are simplified (subtractions
492
- * becomes additions of negative, division become multiplications of inverse,
493
- * etc...) and terms are ordered using a deglex order. This can make
494
- * subsequent operations easier.
1502
+ * The result is canonical.
495
1503
  */
496
- canonical(expr: Expression<T> | null): Expression<T> | null;
497
- /** Format the expression according to the specified forms.
1504
+ mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1505
+ /** Shortcut for `this.fn("Power"...)`
498
1506
  *
499
- * If no form is provided, the expression is formatted with the 'canonical'
500
- * form.
1507
+ * The result is canonical.
1508
+ */
1509
+ power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
1510
+ /** Shortcut for `this.fn("Divide", [1, expr])`
501
1511
  *
1512
+ * The result is canonical.
502
1513
  */
503
- format(expr: Expression<T> | null, forms?: Form | Form[]): Expression<T> | null;
504
- /**
505
- * Evaluate the expression `exp` asynchronously.
1514
+ inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1515
+ /** Shortcut for `this.fn("Negate", [expr])`
506
1516
  *
507
- * Evaluating some expressions can take a very long time. Some can invole
508
- * making network queries. Therefore to avoid blocking the main event loop,
509
- * a promise is returned.
1517
+ * The result is canonical.
1518
+ */
1519
+ negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1520
+ /** Shortcut for `this.fn("Divide", [num, denom])`
510
1521
  *
511
- * Use `result = await engine.evaluate(expr)` to get the result without
512
- * blocking.
1522
+ * The result is canonical.
513
1523
  */
514
- evaluate(expr: Expression<T>, options?: {
515
- timeLimit?: number;
516
- iterationLimit?: number;
517
- }): Promise<Expression<T> | null>;
518
- /**
519
- * Simplify an expression.
1524
+ divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
1525
+ /** Shortcut for `this.fn("Pair"...)`
1526
+ *
1527
+ * The result is canonical.
520
1528
  */
521
- simplify(exp: Expression<T>, options?: {
522
- timeLimit?: number;
523
- iterationLimit?: number;
524
- simplifications?: Simplification[];
525
- }): Expression<T> | null;
526
- /**
527
- * Return a numerical approximation of an expression.
1529
+ pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
1530
+ /** Shortcut for `this.fn("Tuple"...)`
1531
+ *
1532
+ * The result is canonical.
528
1533
  */
529
- N(exp: Expression<T>, options?: {
530
- precision?: number;
531
- }): T | Expression<T> | null;
1534
+ tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1535
+ rules(rules: Rule[]): BoxedRuleSet;
1536
+ pattern(expr: LatexString | SemiBoxedExpression): Pattern;
532
1537
  /**
533
- * Determines if the predicate is satisfied based on the known assumptions.
1538
+ * Parse a string of LaTeX and return a corresponding `BoxedExpression`.
534
1539
  *
535
- * Return `undefined` if the value of the predicate cannot be determined.
536
- *
537
- * ```js
538
- * ce.is(["Equal", "x", 0]);
539
- * ce.is(["Equal", 3, 4]);
540
- * ```
1540
+ * The result may not be canonical.
541
1541
  *
542
1542
  */
543
- is(symbol: Expression<T>, domain: Domain): boolean | undefined;
544
- is(predicate: Expression<T>): boolean | undefined;
545
- is(arg1: Expression<T>, arg2?: Domain): boolean | undefined;
546
- /**
547
- * Return a list of all the assumptions that match a pattern.
548
- *
549
- * ```js
550
- * ce.assume(x, 'PositiveInteger');
551
- * ce.ask(['Greater', 'x', '_val'])
552
- * // -> [{'val': 0}]
553
- * ```
1543
+ parse(s: LatexString | string): BoxedExpression;
1544
+ parse(s: null): null;
1545
+ parse(s: LatexString | string | null): null | BoxedExpression;
1546
+ /** Serialize a `BoxedExpression` or a `MathJSON` expression to
1547
+ * a LaTeX string
554
1548
  */
555
- ask(pattern: Expression<T>): Substitution<T>[];
1549
+ serialize(expr: SemiBoxedExpression): LatexString;
556
1550
  /**
557
- * Apply repeatedly a set of rules to an expression.
1551
+ * Options to control the serailization of MathJSON expression to LaTeX
1552
+ * when using `this.latex` or `this.engine.serialize()`.
1553
+ *
1554
+ *
1555
+ * {@inheritDoc NumberFormattingOptions}
1556
+ * {@inheritDoc ParseLatexOptions}
1557
+ * {@inheritDoc SerializeLatexOptions}
1558
+ *
558
1559
  */
559
- replace(rules: RuleSet<T>, expr: Expression<T>): Expression<T>;
1560
+ get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
1561
+ set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
1562
+ /** {@inheritDoc JsonSerializationOptions} */
1563
+ get jsonSerializationOptions(): JsonSerializationOptions;
1564
+ set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
560
1565
  /**
561
1566
  * Add an assumption.
562
1567
  *
563
- * Return `contradiction` if the new assumption is incompatible with previous
1568
+ * Note that the assumption is put into canonical form before being added.
1569
+ *
1570
+ * @param symbol - The symbol to make an assumption about
1571
+ *
1572
+ * Returns:
1573
+ * - `contradiction` if the new assumption is incompatible with previous
564
1574
  * ones.
1575
+ * - `tautology` if the new assumption is redundant with previous ones.
1576
+ * - `ok` if the assumption was successfully added to the assumption set.
565
1577
  *
566
- * Return `tautology` if the new assumption is redundant with previous ones.
567
- *
568
- * Return `ok` if the assumption was successfully added to the assumption set.
569
- *
570
- * Note that the assumption is put into normal form before being added.
571
- *
572
- */
573
- assume(symbol: Expression<T>, domain: Domain): 'contradiction' | 'tautology' | 'ok';
574
- assume(predicate: Expression<T>): 'contradiction' | 'tautology' | 'ok';
575
- assume(arg1: Expression<T>, arg2?: Domain): 'contradiction' | 'tautology' | 'ok';
576
- parse(s: string): Expression<T>;
577
- serialize(x: Expression<T>): string;
578
- getRules(topic: string | string[]): RuleSet;
579
- /** Return the domain of the expression */
580
- domain(expr: Expression<T>): Expression<T> | null;
581
- /** Return the variables in the expression */
582
- getVars(expr: Expression<T>): Set<string>;
583
- chop(n: Numeric): Numeric;
584
- isZero(x: Expression<T>): boolean | undefined;
585
- isNotZero(x: Expression<T>): boolean | undefined;
586
- isNumeric(x: Expression<T>): boolean | undefined;
587
- isInfinity(x: Expression<T>): boolean | undefined;
588
- isFinite(x: Expression<T>): boolean | undefined;
589
- isNonNegative(x: Expression<T>): boolean | undefined;
590
- isPositive(x: Expression<T>): boolean | undefined;
591
- isNegative(x: Expression<T>): boolean | undefined;
592
- isNonPositive(x: Expression<T>): boolean | undefined;
593
- isInteger(x: Expression<T>): boolean | undefined;
594
- isRational(x: Expression<T>): boolean | undefined;
595
- isAlgebraic(x: Expression<T>): boolean | undefined;
596
- isReal(x: Expression<T>): boolean | undefined;
597
- isExtendedReal(x: Expression<T>): boolean | undefined;
598
- isComplex(x: Expression<T>): boolean | undefined;
599
- isOne(x: Expression<T>): boolean | undefined;
600
- isNegativeOne(x: Expression<T>): boolean | undefined;
601
- isElement(x: Expression<T>, set: Expression<T>): boolean | undefined;
602
- isSubsetOf(lhs: Domain | null, rhs: Domain | null): boolean;
603
- isEqual(lhs: Expression<T>, rhs: Expression<T>): boolean | undefined;
604
- isLess(lhs: Expression<T>, rhs: Expression<T>): boolean | undefined;
605
- isLessEqual(lhs: Expression<T>, rhs: Expression<T>): boolean | undefined;
606
- isGreater(lhs: Expression<T>, rhs: Expression<T>): boolean | undefined;
607
- isGreaterEqual(lhs: Expression<T>, rhs: Expression<T>): boolean | undefined;
1578
+ *
1579
+ */
1580
+ assume(symbol: LatexString | SemiBoxedExpression, domain: BoxedExpression): AssumeResult;
1581
+ assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
1582
+ assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
1583
+ /** Remove all assumptions about one or more symbols */
1584
+ forget(symbol?: string | string[]): void;
1585
+ get assumptions(): ExpressionMapInterface<boolean>;
1586
+ ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
1587
+ pushScope(options?: {
1588
+ dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
1589
+ assumptions?: (LatexString | Expression | BoxedExpression)[];
1590
+ scope?: Partial<Scope>;
1591
+ }): void;
1592
+ popScope(): void;
1593
+ /**
1594
+ * When `condition` is false, signal.
1595
+ *
1596
+ * - `condition` - If `true`, do nothing. If `false`, signal.
1597
+ *
1598
+ * @experimental
1599
+ */
1600
+ assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): any;
1601
+ signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
1602
+ signal(sig: WarningSignal): void;
1603
+ /** @internal */
1604
+ shouldContinueExecution(): boolean;
1605
+ /** @internal */
1606
+ checkContinueExecution(): void;
1607
+ /** @internal */
1608
+ cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
1609
+ readonly stats: ComputeEngineStats;
1610
+ /** @internal */
1611
+ purge(): void;
1612
+ /** @internal */
1613
+ _register(expr: BoxedExpression): void;
1614
+ /** @internal */
1615
+ _unregister(expr: BoxedExpression): void;
608
1616
  }
609
- /**
610
- * Transform an expression by applying one or more rewriting rules to it,
611
- * recursively.
612
- *
613
- * There are many ways to symbolically manipulate an expression, but
614
- * transformations with `form` have the following characteristics:
615
- *
616
- * - they don't require calculations or assumptions about the domain of free
617
- * variables or the value of constants
618
- * - the output expression is expressed with more primitive functions,
619
- * for example subtraction is replaced with addition
620
- *
621
- *
622
- */
623
- export declare function format<T extends number = number>(expr: Expression<T>, forms: Form[], options?: {
624
- dictionaries?: Readonly<Dictionary<T>>[];
625
- }): Expression<T>;
626
- /**
627
- * Apply the definitions in the supplied dictionary to an expression
628
- * and return the result.
629
- *
630
- * Unlike `format` this may entail performing calculations and irreversible
631
- * transformations.
632
- *
633
- * See also `[ComputeEngine.evaluate()](#(ComputeEngine%3Aclass).(evaluate%3Ainstance))`.
634
- *
635
- * @param dictionaries - An optional set of functions and constants to use
636
- * when evaluating the expression. Evaluating the expression may modify the
637
- * scope, for example if the expression is an assignment or definition.
638
- */
639
- export declare function evaluate<T extends number = number>(expr: Expression<T>, options?: {
640
- dictionaries?: Readonly<Dictionary<T>>[];
641
- }): Promise<Expression<T> | null>;
642
- /**
643
- * A given mathematical expression can be represented in multiple equivalent
644
- * ways as a MathJSON expression.
645
- *
646
- * Learn more about [Canonical Forms](https://cortexjs.io/guides/compute-engine/forms/).
647
- */
648
- export declare type Form = 'canonical' | 'canonical-add' | 'canonical-boolean' | 'canonical-constants' | 'canonical-divide' | 'canonical-domain' | 'canonical-exp' | 'canonical-list' | 'canonical-multiply' | 'canonical-power' | 'canonical-negate' | 'canonical-number' | 'canonical-rational' | 'canonical-root' | 'canonical-subtract' | 'canonical-domain' | 'flatten' | 'json' | 'object-literal' | 'sorted' | 'stripped-metadata' | 'sum-product';
1617
+ export declare function getVars(expr: BoxedExpression): string[];