@cortex-js/compute-engine 0.7.0 → 0.9.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 (83) hide show
  1. package/dist/compute-engine.esm.js +8291 -7307
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +41 -88
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -5
  9. package/dist/types/common/utils.d.ts +1 -0
  10. package/dist/types/compute-engine/assume.d.ts +6 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +67 -68
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +74 -16
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +10 -5
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -4
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +45 -36
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +22 -19
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +8 -7
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -6
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +21 -15
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +9 -9
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
  27. package/dist/types/compute-engine/compute-engine.d.ts +65 -35
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +2 -8
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -9
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +14 -6
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -6
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  53. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  54. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  55. package/dist/types/compute-engine/library/core.d.ts +1 -1
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +1 -1
  58. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  61. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  62. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/numerics/{numeric-decimal.d.ts → numeric-bignum.d.ts} +10 -6
  64. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric.d.ts +10 -6
  66. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/rationals.d.ts +56 -0
  68. package/dist/types/compute-engine/public.d.ts +622 -506
  69. package/dist/types/compute-engine/rules.d.ts +7 -1
  70. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  71. package/dist/types/compute-engine/solve.d.ts +17 -0
  72. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
  74. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/product.d.ts +30 -12
  77. package/dist/types/compute-engine/symbolic/sum.d.ts +13 -7
  78. package/dist/types/compute-engine/symbolic/utils.d.ts +7 -29
  79. package/dist/types/compute-engine.d.ts +2 -2
  80. package/dist/types/math-json/math-json-format.d.ts +2 -2
  81. package/dist/types/math-json/utils.d.ts +11 -41
  82. package/dist/types/math-json.d.ts +3 -3
  83. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -13,6 +13,7 @@ import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../comm
13
13
  import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
14
14
  import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
15
15
  export * from './latex-syntax/public';
16
+ export declare type Rational = [number, number] | [Decimal, Decimal];
16
17
  /**
17
18
  * Metadata that can be associated with a `BoxedExpression`
18
19
  */
@@ -23,18 +24,19 @@ export declare type Metadata = {
23
24
  /**
24
25
  * The numeric evaluation mode:
25
26
  *
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
- *
27
+ <div class=symbols-table>
28
+
29
+ | Mode | |
30
+ | :--- | :----- |
31
+ | `"auto"`| Use bignum or complex numbers. |
32
+ | `"machine"` | **IEEE 754-2008**, 64-bit floating point numbers: 52-bit mantissa, about 15 digits of precision |
33
+ | `"bignum"` | Arbitrary precision floating point numbers, as provided by the "decimal.js" library |
34
+ | `"complex"` | Complex number represented by two machine numbers, a real and an imaginary part, as provided by the "complex.js" library |
35
+
36
+ </div>
37
37
  */
38
+ export declare type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
39
+ /** Options for `BoxedExpression.simplify()` */
38
40
  export declare type SimplifyOptions = EvaluateOptions & {
39
41
  recursive?: boolean;
40
42
  rules?: BoxedRuleSet;
@@ -207,7 +209,14 @@ export declare type JsonSerializationOptions = {
207
209
  *
208
210
  * **Default**: `true`
209
211
  */
210
- repeatingDecimal: boolean;
212
+ repeatingDecimals: boolean;
213
+ /** Number literals are serialized with this precision.
214
+ * If `"auto"`, the same precision as the compute engine calculations is used
215
+ * If `"max"`, all available digits are serialized
216
+ *
217
+ * **Default**: `"auto"`
218
+ */
219
+ precision: 'auto' | 'max' | number;
211
220
  };
212
221
  /**
213
222
  * **Theory of Operations**
@@ -231,584 +240,582 @@ export interface BoxedExpression {
231
240
  readonly engine: IComputeEngine;
232
241
  /** From `Object.valueOf()`, return a primitive value for the expression.
233
242
  *
234
- * If the expression is a machine number, or a Decimal that can be
243
+ * If the expression is a machine number, or bignum or rational that can be
235
244
  * converted to a machine number, return a `number`.
236
245
  *
237
- * If the expression is a rational number, return `[number, number]`.
238
- *
239
246
  * If the expression is a symbol, return the name of the symbol as a `string`.
240
247
  *
241
248
  * Otherwise return a LaTeX representation of the expression.
242
249
  *
243
- * @category Object Methods
250
+ * @category Primitive Methods
244
251
  */
245
- valueOf(): number | string | [number, number];
252
+ valueOf(): number | string | boolean;
246
253
  /** From `Object.toString()`, return a LaTeX representation of the expression.
247
254
  *
248
- * @category Object Methods
255
+ * Used when coercing a `BoxedExpression` to a `String`.
256
+ *
257
+ * @category Primitive Methods
249
258
  */
250
259
  toString(): string;
251
- /** From `Object.toJSON()`, equivalent to `JSON.stringify(this.json)`
252
- *
253
- * @category Object Methods
260
+ /** Similar to`expr.valueOf()` but includes a hint.
261
+ * @category Primitive Methods
254
262
  */
255
- toJSON(): string;
256
- /** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
263
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
264
+ /** Used by `JSON.stringify()` to serialize this object to JSON.
257
265
  *
258
- * @category Object Methods
266
+ * Method version of `expr.json`.
259
267
  *
268
+ * @category Primitive Methods
260
269
  */
261
- is(rhs: unknown): boolean;
262
- /** @internal */
263
- get hash(): number;
264
- /** An optional short description of the symbol or function head.
265
- *
266
- * May include markdown. Each string is a paragraph. */
267
- readonly description: string[];
268
- /** An optional URL pointing to more information about the symbol or function head */
269
- readonly url: string;
270
- /** All boxed expressions have a head.
270
+ toJSON(): Expression;
271
+ /** If `true`, this expression is in a canonical form.
271
272
  *
272
- * If not a function this can be `Symbol`, `String`, `Number` or `Dictionary`.
273
+ * **Note** applicable to canonical and non-canonical expressions.
273
274
  *
274
- * If the head expression can be represented as a string, it is returned
275
- * as a string.
276
- */
277
- get head(): BoxedExpression | string;
278
- /**
279
- * If `this.isPure` is `true`, this is a synonym for `this.evaluate()`.
280
- * Otherwise, it returns `undefined`.
281
- */
282
- get value(): BoxedExpression | undefined;
283
- /** Only the value of variables can be changed (symbols that are not constants) */
284
- set value(value: BoxedExpression | number | undefined);
285
- /** An approximation of the value of this expression. Floating-point
286
- * operations may be performed.
287
- *
288
- * Just like `this.value`, it returns `undefined` for impure expressions.
289
- */
290
- get numericValue(): BoxedExpression | undefined;
291
- /** If true, the value of the expression never changes and evaluating it has
292
- * no side-effects.
293
- * If false, the value of the expression may change, if the
294
- * value of other expression changes or for other reasons.
295
- *
296
- * If `this.isPure` is `false`, `this.value` is undefined. Call
297
- * `this.evaluate()` to determine the value of the expression instead.
298
- *
299
- * As an example, the `Random` function is not pure.
300
275
  */
301
- get isPure(): boolean;
302
- /** True if the expression is a free variable, that is a symbol with no value */
303
- get isFree(): boolean;
304
- /** True if the expression is a constant, that is a symbol with an immutable value */
305
- get isConstant(): boolean;
306
- /**
307
- * If `true`, this expression represents a value that was not calculated
308
- * or that does not reference another expression.
309
- * This means the expression is either a number, a string or a dictionary.
310
- * Functions and symbols are not literals.
311
- */
312
- get isLiteral(): boolean;
313
- /** If `true`, this expression is in a canonical form */
314
276
  get isCanonical(): boolean;
315
277
  /** For internal use only, set when a canonical expression is created.
316
278
  * @internal
317
279
  */
318
280
  set isCanonical(val: boolean);
319
- /** All the subexpressions matching the head */
320
- getSubexpressions(head: string): BoxedExpression[];
321
- /** All the subexpressions in this expression, recursively */
322
- get subexpressions(): BoxedExpression[];
323
- /** All the symbols in the expression, recursively */
324
- get symbols(): BoxedExpression[];
325
- /** All the `["Error"]` subexpressions */
326
- get errors(): BoxedExpression[];
327
- /** `ops` is the list of arguments of the function, its "tail"
281
+ /** MathJSON representation of this expression.
328
282
  *
329
- * @category Function Expression
283
+ * **Note** applicable to canonical and non-canonical expressions.
330
284
  *
331
285
  */
332
- get ops(): null | BoxedExpression[];
333
- /** If this expression is a function, the number of operands, otherwise 0.
334
- *
335
- * Note that a function can have 0 operands, so to check if this expression
336
- * is a function, check if `this.ops !== null` instead.
337
- *
338
- * @category Function Expression
339
- *
286
+ readonly json: Expression;
287
+ /**
288
+ * The scope in which this expression has been defined.
289
+ * Is null when the expression is not canonical.
340
290
  */
341
- get nops(): number;
342
- /** First operand, i.e.`this.ops[0]`
343
- *
344
- *
345
- * @category Function Expression
291
+ readonly scope: RuntimeScope | null;
292
+ /** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
346
293
  *
294
+ * @category Primitive Methods
347
295
  *
348
296
  */
349
- get op1(): BoxedExpression;
350
- /** Second operand, i.e.`this.ops[0]`
351
- *
297
+ is(rhs: unknown): boolean;
298
+ /** @internal */
299
+ readonly hash: number;
300
+ /** LaTeX representation of this expression.
352
301
  *
353
- * @category Function Expression
302
+ * The serialization can be customized with `ComputeEngine.latexOptions`
354
303
  *
304
+ * **Note** applicable to canonical and non-canonical expressions.
355
305
  *
356
306
  */
357
- get op2(): BoxedExpression;
358
- /** Third operand, i.e. `this.ops[2]`
359
- *
360
- *
361
- * @category Function Expression
362
- *
307
+ get latex(): LatexString;
308
+ /**
363
309
  *
310
+ * **Note** applicable to canonical and non-canonical expressions.
311
+ * @internal
364
312
  */
365
- get op3(): BoxedExpression;
366
- /** The keys of the dictionary.
367
- *
368
- * If this expression not a dictionary, return `null`
313
+ set latex(val: string);
314
+ /** If this expression is a symbol, return the name of the symbol as a string.
315
+ * Otherwise, return `null`.
369
316
  *
370
- * @category Dictionary Expression
317
+ * **Note** applicable to canonical and non-canonical expressions.
318
+
319
+ * @category Symbol Expression
371
320
  *
372
321
  */
373
- get keys(): IterableIterator<string> | null;
322
+ readonly symbol: string | null;
374
323
  /**
324
+ * If this is the `Nothing` symbol, return `true`.
375
325
  *
376
- * @category Dictionary Expression
326
+ * **Note** applicable to canonical and non-canonical expressions.
377
327
  */
378
- get keysCount(): number;
379
- /**
380
- * If this expression is a dictionary, return the value of the `key` entry.
328
+ readonly isNothing: boolean;
329
+ /** If this expression is a string, return the value of the string.
330
+ * Otherwise, return `null`.
381
331
  *
382
- * @category Dictionary Expression
332
+ * **Note** applicable to canonical and non-canonical expressions.
333
+
334
+ * @category String Expression
383
335
  *
384
336
  */
385
- getKey(key: string): BoxedExpression | undefined;
386
- /**
387
- * If this expression is a dictionary, return true if the dictionary has a
388
- * `key` entry.
337
+ readonly string: string | null;
338
+ /** All the subexpressions matching the head
389
339
  *
390
- * @category Dictionary Expression
340
+ * **Note** applicable to canonical and non-canonical expressions.
391
341
  *
392
342
  */
393
- hasKey(key: string): boolean;
394
- /**
395
- * Return the value of this number or symbol, if stored as a machine number.
343
+ getSubexpressions(head: string): BoxedExpression[];
344
+ /** All the subexpressions in this expression, recursively
396
345
  *
397
- * Note it is possible for `machineValue` to be `null`, and for `isNotZero` to be true.
398
- * For example, when a symbol has been defined with an assumption.
346
+ * **Note** applicable to canonical and non-canonical expressions.
399
347
  *
400
- * If `machineValue` is not `null`, then `decimalValue`, `rationalValue`
401
- * and `complexValue` are `null.
348
+ */
349
+ readonly subexpressions: BoxedExpression[];
350
+ /** All the symbols in the expression, recursively
402
351
  *
403
- * @category Numeric Expression
352
+ * **Note** applicable to canonical and non-canonical expressions.
404
353
  *
405
354
  */
406
- get machineValue(): number | null;
407
- /** If the value of this expression is a rational number, return it.
408
- * Otherwise, return `[null, null]`.
409
- *
410
- * If `rationalValue` is not `[null, null]`, then `machineValue`, `decimalValue`
411
- * and `complexValue` are `null.
355
+ readonly symbols: BoxedExpression[];
356
+ /** All the `["Error"]` subexpressions
412
357
  *
413
- * @category Numeric Expression
358
+ * **Note** applicable to canonical and non-canonical expressions.
414
359
  *
415
360
  */
416
- get rationalValue(): [numer: number, denom: number] | [null, null];
417
- /** If the value of this expression is a `Decimal` number, return it.
418
- * Otherwise, return `null`.
419
- *
420
- * A `Decimal` number is an arbitrarily long floating point number.
361
+ readonly errors: BoxedExpression[];
362
+ /** All boxed expressions have a head.
421
363
  *
422
- * If `decimalValue` is not `null`, then `machineValue`
423
- * and `complexValue` are `null` and `rationalValue` is `[null, null]`.
364
+ * If not a function this can be `Symbol`, `String`, `Number` or `Dictionary`.
424
365
  *
425
- * @category Numeric Expression
366
+ * If the head expression can be represented as a string, it is returned
367
+ * as a string.
426
368
  *
369
+ * **Note** applicable to canonical and non-canonical expressions. The head
370
+ * of a non-canonical expression may be different than the head of its
371
+ * canonical counterpart. For example the canonical counterpart of `["Divide", 5, 7]` is `["Rational", 5, 5]`.
427
372
  */
428
- get decimalValue(): Decimal | null;
429
- /** If the value of this expression is a `Complex` number, return it.
430
- * Otherwise, return `null`.
373
+ readonly head: BoxedExpression | string;
374
+ /** The list of arguments of the function, its "tail".
431
375
  *
432
- * If `complexValue` is not `null`, then `machineValue`, `rationalValue`
433
- * and `decimalValue` are `null.
376
+ * If the expression is not a function, return `null`.
434
377
  *
435
- * @category Numeric Expression
378
+ * **Note** applicable to canonical and non-canonical expressions.
436
379
  *
380
+ * @category Function Expression
437
381
  *
438
382
  */
439
- get complexValue(): Complex | null;
440
- /** Return an approximation of the numeric value of this expression as
441
- * a 64-bit floating point number.
383
+ readonly ops: null | BoxedExpression[];
384
+ /** If this expression is a function, the number of operands, otherwise 0.
442
385
  *
443
- * If the value is a machine number, return it exactly.
386
+ * Note that a function can have 0 operands, so to check if this expression
387
+ * is a function, check if `this.ops !== null` instead.
444
388
  *
445
- * If the value is a rational number, return the numerator divided by the
446
- * denominator.
389
+ * **Note** applicable to canonical and non-canonical expressions.
447
390
  *
448
- * If the value is a Decimal number that can be represented by a machine
449
- * number, return this value. There might be a small loss of precision due
450
- * to the limitations of the binary representation of numbers as machine
451
- * numbers.
391
+ * @category Function Expression
452
392
  *
453
- * If the value of this expression cannot be represented by a float,
454
- * return `null`.
393
+ */
394
+ readonly nops: number;
395
+ /** First operand, i.e.`this.ops[0]`
455
396
  *
456
- * @category Numeric Expression
397
+ * **Note** applicable to canonical and non-canonical expressions.
398
+ *
399
+ * @category Function Expression
457
400
  *
458
401
  *
459
402
  */
460
- get asFloat(): number | null;
461
- /**
462
- * If the value of this expression is an integer with a 'small' absolute value,
463
- * return this value. Otherwise, return `null`.
403
+ readonly op1: BoxedExpression;
404
+ /** Second operand, i.e.`this.ops[1]`
464
405
  *
465
- * Some calculations, for example to put in canonical forms, are only
466
- * performed if they are safe from overflow. This method makes it easy
467
- * to check for this, whether the value is a Decimal or a number.
406
+ * **Note** applicable to canonical and non-canonical expressions.
468
407
  *
469
- * By default, "small" is less than 1,000,000.
408
+ * @category Function Expression
470
409
  *
471
- * @category Numeric Expression
472
410
  *
473
411
  */
474
- get asSmallInteger(): number | null;
475
- /**
476
- * If the value of this an expression is a small integer or a rational,
477
- * return this value. Otherwise, return `[null, null`].
412
+ readonly op2: BoxedExpression;
413
+ /** Third operand, i.e. `this.ops[2]`
478
414
  *
479
- * @category Numeric Expression
415
+ * **Note** applicable to canonical and non-canonical expressions.
480
416
  *
481
- */
482
- get asRational(): [number, number] | [null, null];
483
- /**
484
- * Return the following, depending on the value of this expression:
417
+ * @category Function Expression
485
418
  *
486
- * * `-1` if it is < 0
487
- * * `0` if it is = 0
488
- * * `+1` if it is > 0
489
- * * `undefined` this value may be positive, negative or zero. We don't know
490
- * right now (a symbol with an Integer domain, but no currently assigned
491
- * value, for example)
492
- * * `null` this value will never be positive, negative or zero (`NaN`,
493
- * a string or a complex number for example)
494
419
  *
495
- * Note that complex numbers have no natural ordering,
496
- * so if the value is a complex number, `sgn` is either 0, or `null`
420
+ */
421
+ readonly op3: BoxedExpression;
422
+ /** `true` if this expression or any of its subexpressions is an `["Error"]`
423
+ * expression.
497
424
  *
498
- * If a symbol, this does take assumptions into account, that is `this.sgn`
499
- * will return `1` if `isPositive` is `true`, even if this expression has
500
- * no value
425
+ * **Note** applicable to canonical and non-canonical expressions. For
426
+ * non-canonical expression, this may indicate a syntax error while parsing
427
+ * LaTeX. For canonical expression, this may indicate argument domain
428
+ * mismatch, or missing or unexpected arguments.
501
429
  *
502
- * @category Numeric Expression
430
+ * @category Symbol Expression
503
431
  *
504
432
  */
505
- get sgn(): -1 | 0 | 1 | undefined | null;
506
- /** If this expression is a symbol, return the name of the symbol as a string.
507
- * Otherwise, return `null`.
433
+ readonly isValid: boolean;
434
+ /**
435
+ * If `true`, this expression represents a value that was not calculated
436
+ * and that does not reference another expression.
508
437
  *
509
- * @category Symbol Expression
438
+ * This means the expression is either a number, a string or a dictionary.
439
+ * Functions and symbols are not literals.
510
440
  *
441
+ * **Note** applicable to canonical and non-canonical expressions.
511
442
  */
512
- get symbol(): string | null;
443
+ readonly isLiteral: boolean;
513
444
  /**
514
- * If this is the `Nothing`, return `true`.
515
- */
516
- get isNothing(): boolean;
517
- /** `true` if this expression or any subexpression is an `["Error"]`
518
- * expression.
445
+ * An exact value is not further transformed when evaluated. To get an
446
+ * approximate evaluation of an exact value, use `.N()`.
519
447
  *
520
- * @category Symbol Expression
448
+ * Non-exact values includes:
449
+ * - numbers with a fractional part
450
+ * - complex numbers with a real or imaginary fractional part
521
451
  *
522
452
  */
523
- get isValid(): boolean;
524
- /** If this expression is a string, return the value of the string.
525
- * Otherwise, return `null`.
453
+ readonly isExact: boolean;
454
+ /** If true, the value of the expression never changes and evaluating it has
455
+ * no side-effects.
456
+ * If false, the value of the expression may change, if the
457
+ * value of other expression changes or for other reasons.
526
458
  *
527
- * @category String Expression
459
+ * If `this.isPure` is `false`, `this.value` is undefined. Call
460
+ * `this.evaluate()` to determine the value of the expression instead.
528
461
  *
462
+ * As an example, the `Random` function is not pure.
463
+ *
464
+ * **Note** applicable to canonical and non-canonical expressions.
529
465
  */
530
- get string(): string | null;
531
- /** `true` if the value of this expression is a number.
466
+ readonly isPure: boolean;
467
+ /** True if the expression is a free variable, that is a symbol with no value */
468
+ readonly isFree: boolean;
469
+ /** True if the expression is a constant, that is a symbol with an immutable value */
470
+ readonly isConstant: boolean;
471
+ /**
472
+ * Return the canonical form of this expression.
532
473
  *
533
- * `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
474
+ * If this is a function expressin, a definition is associated with the
475
+ * canonical expression.
534
476
  *
535
- * Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
536
- * **is** a number.
477
+ * When determining the canonical form the following function definition
478
+ * flags are applied:
479
+ * - `associative`: \\( f(a, f(b), c) \longrightarrow f(a, b, c) \\)
480
+ * - `idempotent`: \\( f(f(a)) \longrightarrow f(a) \\)
481
+ * - `involution`: \\( f(f(a)) \longrightarrow a \\)
482
+ * - `commutative`: sort the arguments.
483
+ *
484
+ * If his expression is already canonical, the value of canonical is
485
+ * `this`.
537
486
  *
538
- * @category Expression Properties
539
487
  */
540
- get isNumber(): boolean | undefined;
541
- /** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
488
+ get canonical(): BoxedExpression;
489
+ /**
490
+ * If this expression is a function, apply the function `fn` to all its operands.
542
491
  *
492
+ * Replace the head of this expression with `head`, if defined.
543
493
  *
544
- * @category Expression Properties
494
+ * If this expression is a dictionary, return a new dictionary with the values
495
+ * modified by `fn`.
545
496
  *
546
- */
547
- get isInteger(): boolean | undefined;
548
- /** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
497
+ * If `head` is provided, return a function expression with the modified
498
+ * dictionary as operand, otherwise return the modified dictionary.
549
499
  *
550
- * Note that every integer is also a rational.
500
+ * **Note** applicable to canonical and non-canonical expressions.
551
501
  *
502
+ * */
503
+ apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
504
+ /**
505
+ * Replace all the symbols in the expression as indicated.
552
506
  *
553
- * @category Expression Properties
507
+ * Note the same effect can be achieved with `this.replace()`, but
508
+ * using `this.subs()` is more efficient, and simpler.
509
+ *
510
+ * **Note** applicable to canonical and non-canonical expressions.
554
511
  *
555
512
  */
556
- get isRational(): boolean | undefined;
513
+ subs(sub: Substitution, options?: {
514
+ canonical?: boolean;
515
+ }): BoxedExpression;
557
516
  /**
558
- * The value of this expression is a number that is the root of a non-zero
559
- * univariate polynomial with rational coefficients.
517
+ * Transform the expression by applying the rules:
518
+ * if the `lhs` of a rule matches, it is replaced by its `rhs`.
560
519
  *
561
- * All integers and rational numbers are algebraic.
520
+ * If no rules apply, return `null`.
562
521
  *
563
- * Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
522
+ * See also `subs` for a simple substitution.
564
523
  *
565
524
  *
566
- * @category Expression Properties
525
+ * **Note** applicable to canonical and non-canonical expressions.
567
526
  *
568
527
  */
569
- get isAlgebraic(): boolean | undefined;
528
+ replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
570
529
  /**
571
- * The value of this expression is real number: finite and not imaginary.
572
- *
573
- * `isFinite && !isImaginary`
574
- *
530
+ * True if the expression includes a symbol `v` or a function head `v`.
575
531
  *
576
- * @category Expression Properties
532
+ * **Note** applicable to canonical and non-canonical expressions.
577
533
  */
578
- get isReal(): boolean | undefined;
579
- /** Real or ±Infinity
534
+ has(v: string | string[]): boolean;
535
+ /** Structural/symbolic equality (weak equality).
580
536
  *
581
- * `isReal || isInfinity`
537
+ * `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
582
538
  *
539
+ * **Note** applicable to canonical and non-canonical expressions.
583
540
  *
584
- * @category Expression Properties
541
+ * @category Relational Operator
585
542
  */
586
- get isExtendedReal(): boolean | undefined;
587
- /**
588
- * The value of this expression is a number, but not `NaN` or any Infinity
543
+ isSame(rhs: BoxedExpression): boolean;
544
+ /** Attempt to match this expression to the `rhs` expression.
589
545
  *
590
- * `isReal || isImaginary`
546
+ * If `rhs` does not match, return `null`.
591
547
  *
548
+ * Otherwise return an object literal.
592
549
  *
593
- * @category Expression Properties
550
+ * If this expression includes wildcards (symbols with a name that starts
551
+ * with `_`), the object literal will include a prop for each matching named
552
+ * wildcard.
594
553
  *
595
- */
596
- get isComplex(): boolean | undefined;
597
- /** `isReal || isImaginary || isInfinity`
554
+ * If `rhs` matches this pattern but there are no named wildcards, return
555
+ * the empty object literal, `{}`.
598
556
  *
557
+ * **Note** applicable to canonical and non-canonical expressions.
599
558
  *
600
- * @category Expression Properties
601
559
  */
602
- get isExtendedComplex(): boolean | undefined;
603
- /** The value of this expression is a number with a imaginary part
560
+ match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
561
+ /**
562
+ * "Not a Number".
563
+ *
564
+ * A value representing undefined result of computations, such as `0/0`,
565
+ * as per the floating point format standard IEEE-754.
604
566
  *
567
+ * Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
568
+ * number).
605
569
  *
606
570
  * @category Expression Properties
571
+ *
607
572
  */
608
- get isImaginary(): boolean | undefined;
573
+ readonly isNaN: boolean | undefined;
609
574
  /**
575
+ * The numeric value of this expression is 0.
576
+ *
610
577
  * @category Expression Properties
611
578
  */
612
- get isZero(): boolean | undefined;
579
+ readonly isZero: boolean | undefined;
613
580
  /**
581
+ * The numeric value of this expression is not 0.
614
582
  * @category Expression Properties
615
583
  */
616
- get isNotZero(): boolean | undefined;
584
+ readonly isNotZero: boolean | undefined;
617
585
  /**
586
+ * The numeric value of this expression is not 1.
618
587
  * @category Expression Properties
619
588
  */
620
- get isOne(): boolean | undefined;
589
+ readonly isOne: boolean | undefined;
621
590
  /**
591
+ * The numeric value of this expression is not -1.
622
592
  * @category Expression Properties
623
593
  */
624
- get isNegativeOne(): boolean | undefined;
625
- /** ±Infinity or Complex Infinity
626
- *
627
- * @category Expression Properties
628
- */
629
- get isInfinity(): boolean | undefined;
630
- /**
631
- * "Not a Number".
632
- *
633
- * A value representing undefined result of computations, such as `0/0`,
634
- * as per the floating point format standard IEEE-754.
635
- *
636
- * Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
637
- * number).
594
+ readonly isNegativeOne: boolean | undefined;
595
+ /** The numeric value of this expression is ±Infinity or Complex Infinity
638
596
  *
639
597
  * @category Expression Properties
640
- *
641
598
  */
642
- get isNaN(): boolean | undefined;
599
+ readonly isInfinity: boolean | undefined;
643
600
  /** This expression is a number, but not ±Infinity and not `NaN`
644
601
  *
645
602
  * @category Expression Properties
646
603
  */
647
- get isFinite(): boolean | undefined;
604
+ readonly isFinite: boolean | undefined;
648
605
  /**
649
606
  * @category Expression Properties
650
607
  */
651
- get isEven(): boolean | undefined;
608
+ readonly isEven: boolean | undefined;
652
609
  /**
653
610
  * @category Expression Properties
654
611
  */
655
- get isOdd(): boolean | undefined;
612
+ readonly isOdd: boolean | undefined;
656
613
  /**
657
614
  * @category Expression Properties
658
615
  */
659
- get isPrime(): boolean | undefined;
616
+ readonly isPrime: boolean | undefined;
660
617
  /**
661
618
  * @category Expression Properties
662
619
  */
663
- get isComposite(): boolean | undefined;
664
- /** Structural/symbolic equality (weak equality).
620
+ readonly isComposite: boolean | undefined;
621
+ /**
622
+ * Return the value of this expression, if a number literal.
665
623
  *
666
- * `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
624
+ * Note it is possible for `numericValue` to be `null`, and for `isNotZero`
625
+ * to be true. For example, when a symbol has been defined with an assumption.
626
+ *
627
+ * @category Numeric Expression
667
628
  *
668
- * @category Relational Operator
669
629
  */
670
- isSame(rhs: BoxedExpression): boolean;
630
+ readonly numericValue: number | Decimal | Complex | Rational | null;
671
631
  /**
672
- * True if the expression includes a symbol `v` or a function head `v`.
673
- */
674
- has(v: string | string[]): boolean;
675
- /** Attempt to match this expression to the `rhs` expression.
676
- *
677
- * If `rhs` does not match, return `null`.
678
- *
679
- * Otherwise return an object literal.
632
+ * Return the following, depending on the value of this expression:
680
633
  *
681
- * If this expression includes wildcards (symbols with a name that starts
682
- * with `_`), the object literal will include a prop for each matching named
683
- * wildcard.
634
+ * * `-1` if it is < 0
635
+ * * `0` if it is = 0
636
+ * * `+1` if it is > 0
637
+ * * `undefined` this value may be positive, negative or zero. We don't know
638
+ * right now (a symbol with an Integer domain, but no currently assigned
639
+ * value, for example)
640
+ * * `null` this value will never be positive, negative or zero (`NaN`,
641
+ * a string or a complex number for example)
684
642
  *
685
- * If `rhs` matches this pattern but there are no named wildcards, return
686
- * the empty object literal, `{}`.
687
- */
688
- match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
689
- /** Mathematical equality (strong equality), that is the value
690
- * of this expression and of `rhs` are numerically equal.
643
+ * Note that complex numbers have no natural ordering,
644
+ * so if the value is a complex number, `sgn` is either 0, or `null`
691
645
  *
692
- * Both expressions are numerically evaluated.
646
+ * If a symbol, this does take assumptions into account, that is `this.sgn`
647
+ * will return `1` if `isPositive` is `true`, even if this expression has
648
+ * no value
693
649
  *
694
- * Numbers whose difference is less than `engine.tolerance` are
695
- * considered equal. This tolerance is set when the `engine.precision` is
696
- * changed to be such that the last two digits are ignored.
650
+ * @category Numeric Expression
697
651
  *
698
- * @category Relational Operator
699
652
  */
700
- isEqual(rhs: BoxedExpression): boolean;
653
+ readonly sgn: -1 | 0 | 1 | undefined | null;
701
654
  /** If the expressions cannot be compared, return `undefined`
655
+ *
656
+ * The numeric value of both expressions are compared.
702
657
  *
703
658
  * @category Relational Operator
704
659
  */
705
660
  isLess(rhs: BoxedExpression): boolean | undefined;
706
661
  /**
662
+ * The numeric value of both expressions are compared.
707
663
  * @category Relational Operator
708
664
  */
709
665
  isLessEqual(rhs: BoxedExpression): boolean | undefined;
710
666
  /**
667
+ * The numeric value of both expressions are compared.
711
668
  * @category Relational Operator
712
669
  */
713
670
  isGreater(rhs: BoxedExpression): boolean | undefined;
714
671
  /**
672
+ * The numeric value of both expressions are compared.
715
673
  * @category Relational Operator
716
674
  */
717
675
  isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
718
- /** The value of this expression is > 0, same as `isGreater(0)`
676
+ /** The numeric value of this expression is > 0, same as `isGreater(0)`
719
677
  *
720
678
  * @category Expression Properties
721
679
  */
722
- get isPositive(): boolean | undefined;
723
- /** The value of this expression is >= 0, same as `isGreaterEqual(0)`
680
+ readonly isPositive: boolean | undefined;
681
+ /** The numeric value of this expression is >= 0, same as `isGreaterEqual(0)`
724
682
  *
725
683
  * @category Expression Properties
726
684
  */
727
- get isNonNegative(): boolean | undefined;
728
- /** The value of this expression is < 0, same as `isLess(0)`
685
+ readonly isNonNegative: boolean | undefined;
686
+ /** The numeric value of this expression is < 0, same as `isLess(0)`
729
687
  *
730
688
  * @category Expression Properties
731
689
  */
732
- get isNegative(): boolean | undefined;
733
- /** The value of this expression is <= 0, same as `isLessEqual(0)`
690
+ readonly isNegative: boolean | undefined;
691
+ /** The numeric value of this expression is <= 0, same as `isLessEqual(0)`
734
692
  *
735
693
  * @category Expression Properties
736
694
  */
737
- get isNonPositive(): boolean | undefined;
738
- /** Wikidata identifier */
739
- get wikidata(): string;
740
- set wikidata(val: string);
741
- /** MathJSON representation of this expression */
742
- get json(): Expression;
743
- /** LaTeX representation of this expression */
744
- get latex(): LatexString;
745
- set latex(val: string);
695
+ readonly isNonPositive: boolean | undefined;
696
+ /** The keys of the dictionary.
697
+ *
698
+ * If this expression not a dictionary, return `null`
699
+ *
700
+ * @category Dictionary Expression
701
+ *
702
+ */
703
+ readonly keys: IterableIterator<string> | null;
704
+ /**
705
+ *
706
+ * @category Dictionary Expression
707
+ */
708
+ readonly keysCount: number;
709
+ /**
710
+ * If this expression is a dictionary, return the value of the `key` entry.
711
+ *
712
+ * @category Dictionary Expression
713
+ *
714
+ */
715
+ getKey(key: string): BoxedExpression | undefined;
716
+ /**
717
+ * If this expression is a dictionary, return true if the
718
+ * dictionary has a `key` entry.
719
+ *
720
+ * @category Dictionary Expression
721
+ *
722
+ */
723
+ hasKey(key: string): boolean;
724
+ /** Wikidata identifier.
725
+ *
726
+ * **Note** `undefined` if not a canonical expression.
727
+ *
728
+ *
729
+ */
730
+ get wikidata(): string | undefined;
731
+ set wikidata(val: string | undefined);
732
+ /** An optional short description if the symbol or function head.
733
+ *
734
+ * May include markdown. Each string is a paragraph.
735
+ *
736
+ * **Note** `undefined` if not a canonical expression.
737
+ *
738
+ */
739
+ readonly description: undefined | string[];
740
+ /** An optional URL pointing to more information about the symbol or
741
+ * function head
742
+ *
743
+ * **Note** `undefined` if not a canonical expression.
744
+ *
745
+ */
746
+ readonly url: string | undefined;
746
747
  /** Expressions with a higher complexity score are sorted
747
748
  * first in commutative functions
749
+ *
750
+ * **Note** `undefined` if not a canonical expression.
748
751
  */
749
- get complexity(): number;
750
- /** The domain of this expression. If a function expression, this the domain
751
- * of the value of the function(the codomain of the function), if a symbol
752
- * the domain of the value of the symbol.
752
+ readonly complexity: number | undefined;
753
+ /**
754
+ * For symbols and functions, a possible definition associated with the
755
+ * expression. `basedDefinition` is the base class of symbol and function
756
+ * definition.
757
+ *
758
+ * **Note** `undefined` if not a canonical expression.
759
+ *
753
760
  */
754
- get domain(): BoxedDomain;
755
- /** Symbols that represent a variable (or a function name), can have their
756
- * domain modified */
757
- set domain(domain: BoxedDomain | string);
761
+ readonly basedDefinition: BoxedBaseDefinition | undefined;
758
762
  /**
759
- * The domain of this expression, without accounting for any inferred domain
760
- * or `defaultDomain`. If no domain has been explicitly set via assignment
761
- * or via an `.assume()` directive, the `expr.explicitDomain` is `null.
763
+ * For functions, a possible definition associated with the expression.
762
764
  *
763
- * This is useful to determine if the domain of an expression is inferred.
765
+ * **Note** `undefined` if not a canonical expression or not a function.
764
766
  *
765
- * In most cases you'll want to use `.domain` instead.
766
767
  */
767
- get explicitDomain(): BoxedDomain | null;
768
- /** For symbols and functions, a possible definition associated with the
769
- * expression. `basedDefinition` is the base class of symbol and function
770
- * definition. */
771
- get basedDefinition(): BoxedBaseDefinition | undefined;
772
- get functionDefinition(): BoxedFunctionDefinition | undefined;
773
- get symbolDefinition(): BoxedSymbolDefinition | undefined;
768
+ readonly functionDefinition: BoxedFunctionDefinition | undefined;
774
769
  /**
775
- * Return the canonical form of this expression.
770
+ * For symbols, a possible definition associated with the expression.
776
771
  *
777
- * If a function, consider the function definition flags:
778
- * - `associative`: \\( f(a, f(b), c) \longrightarrow f(a, b, c) \\)
779
- * - `idempotent`: \\( f(f(a)) \longrightarrow f(a) \\)
780
- * - `involution`: \\( f(f(a)) \longrightarrow a \\)
781
- * - `commutative`: sort the arguments.
772
+ * **Note** `undefined` if not a symbol
782
773
  *
783
- * Additionally, some simplifications involving exact computations on
784
- * small integers may be performed.
774
+ */
775
+ readonly symbolDefinition: BoxedSymbolDefinition | undefined;
776
+ /**
777
+ * The domain of this expression, without accounting for any inferred domain
778
+ * or `ce.defaultDomain`. If no domain has been explicitly set via assignment
779
+ * or via an `.assume()` directive, the `expr.explicitDomain` is `undefined`.
785
780
  *
786
- * For example:
787
- * - \\( 2 + x + 1 \longrightarrow x + 3 \\)
788
- * - \\( \sqrt{4} \longrightarrow 2 \\)
789
- * - \\(\frac{4}{10} \longrightarrow \frac{2}{5} \\).
781
+ * This is useful to determine if the domain of an expression is inferred.
782
+ *
783
+ * In most cases you'll want to use `expr.domain` instead.
790
784
  *
791
- * However, no calculation is performed involving floating point numbers, so
792
- * \\( \sqrt(2) \longrightarrow \sqrt(2) \\).
785
+ * **Note** `undefined` if not a canonical expression or not a function.
793
786
  *
794
- * Determining the canonical form does not depend on the values assigned to,
795
- * or assumptions about, symbols.
796
787
  */
797
- get canonical(): BoxedExpression;
788
+ readonly explicitDomain: BoxedDomain | undefined;
789
+ /**
790
+ * Update the definition associated with this expression, taking
791
+ * into account the specified scope.
792
+ *
793
+ * **Note**: applicable only to canonical expressions
794
+ *
795
+ * @internal
796
+ */
797
+ bind(scope: RuntimeScope | null): void;
798
798
  /**
799
- * Return a simpler form of this expression.
800
799
  *
801
- * The expression is first converted to canonical form. Then a series of
802
- * rewriting rules are applied repeatedly, until no rules apply.
800
+ * @internal
801
+ */
802
+ unbind(): void;
803
+ /**
804
+ * Return a simpler form of the canonical form of this expression.
803
805
  *
804
- * If a custom `simplify` handler is associated with this function definition,
805
- * it is invoked.
806
+ * A series of rewriting rules are applied repeatedly, until no more rules
807
+ * apply.
808
+ *
809
+ * If a custom `simplify` handler is associated with this function
810
+ * definition, it is invoked.
806
811
  *
807
812
  * The values assigned to symbols and the assumptions about symbols may be
808
813
  * used, for example `arg.isInteger` or `arg.isPositive`.
809
814
  *
810
- * No calculations involving floating point numbers are performed but exact
811
- * calculations may be performed, for example
815
+ * No calculations involving decimal numbers (numbers that are not
816
+ * integers) are performed but exact calculations may be performed,
817
+ * for example:
818
+ *
812
819
  * \\( \sin(\frac{\pi}{4}) \longrightarrow \frac{\sqrt{2}}{2} \\).
813
820
  *
814
821
  * The result is in canonical form.
@@ -816,33 +823,37 @@ export interface BoxedExpression {
816
823
  */
817
824
  simplify(options?: SimplifyOptions): BoxedExpression;
818
825
  /**
819
- * Return the value of this expression.
820
- *
821
- * The expression is first converted to canonical form.
826
+ * Return the value of the canonical form of this expression.
822
827
  *
823
828
  * A pure expression always return the same value and has no side effects.
824
- * If `this.isPure` is `true`, `this.value` and `this.evaluate()` are synonyms.
825
- * For an impure expression, `this.value` is undefined.
829
+ * If `expr.isPure` is `true`, `expr.value` and `expr.evaluate()` are
830
+ * synonyms.
831
+ *
832
+ * For an impure expression, `expr.value` is undefined.
826
833
  *
827
834
  * Evaluating an impure expression may have some side effects, for
828
- * example modifying the `ComputeEngine` environment, such as its set of assumptions.
835
+ * example modifying the `ComputeEngine` environment, such as its set of
836
+ * assumptions.
829
837
  *
830
- * Only exact calculations are performed, no floating point calculations.
831
- * To perform approximate floating point calculations, use `this.N()` instead.
838
+ * Only exact calculations are performed, no approximate calculations on
839
+ * decimal numbers (non-integer numbers). Constants, rational numbers and
840
+ * square root of rational numbers are preserved.
832
841
  *
833
- * The result of `this.evaluate()` may be the same as `this.simplify()`.
842
+ * To perform approximate calculations, use `expr.N()` instead.
843
+ *
844
+ * The result of `expr.evaluate()` may be the same as `expr.simplify()`.
834
845
  *
835
846
  * The result is in canonical form.
836
847
  *
837
848
  */
838
849
  evaluate(options?: EvaluateOptions): BoxedExpression;
839
- /** Return a numeric approximation of this expression.
850
+ /** Return a numeric approximation of the canonical form of this expression.
840
851
  *
841
- * The expression is first converted to canonical form.
852
+ * Any necessary calculations, including on decimal numbers (non-integers),
853
+ * are performed.
842
854
  *
843
- * Any necessary calculations, including on floating point numbers,
844
- * are performed. The calculations are performed according
845
- * to the `numericMode` and `precision` properties of the `ComputeEngine`.
855
+ * The calculations are performed according to the `numericMode` and
856
+ * `precision` properties of the `ComputeEngine`.
846
857
  *
847
858
  * To only perform exact calculations, use `this.evaluate()` instead.
848
859
  *
@@ -854,46 +865,131 @@ export interface BoxedExpression {
854
865
  N(options?: NOptions): BoxedExpression;
855
866
  solve(vars: Iterable<string>): null | BoxedExpression[];
856
867
  /**
857
- * If this expression is a function, apply the function `fn` to all its operands.
868
+ * Synonym for `evaluate()`. If the expression is pure, the value may be
869
+ * cached.
858
870
  *
859
- * Replace the head of this expression with `head`, if defined.
871
+ * It returns `undefined` for expressions that are not pure or that may
872
+ * not be evaluated.
860
873
  *
861
- * If this expression is a dictionary, return a new dictionary with the values
862
- * modified by `fn`.
874
+ * **Note**: If non-canonical, return the value of its canonical counterpart
875
+ */
876
+ get value(): BoxedExpression | undefined;
877
+ /** Only the value of variables can be changed (symbols that are not
878
+ * constants).
863
879
  *
864
- * If `head` is provided, return a function
865
- * with the modified dictionary as operand, otherwise return the
866
- * modified dictionary. */
867
- apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
880
+ * **Note**: If non-canonical, does nothing.
881
+ *
882
+ */
883
+ set value(value: BoxedExpression | number | undefined);
884
+ /** The domain of the value of this expression.
885
+ *
886
+ * If a function expression, the domain of the value of the function (the codomain of the function).
887
+ *
888
+ * If a symbol the domain of the value of the symbol.
889
+ *
890
+ * Use `expr.head` to determine if an expression is a symbol or function.
891
+ *
892
+ * **Note**: If non-canonical, return the domain of its canonical
893
+ * counterpart
894
+ */
895
+ get domain(): BoxedDomain;
896
+ /** Modify the domain of a symbol that represent a variable
897
+ * (or a function name).
898
+ *
899
+ * **Note**: If non-canonical, does nothing.
900
+ *
901
+ */
902
+ set domain(domain: BoxedExpression | DomainExpression | BoxedDomain);
903
+ /** `true` if the value of this expression is a number.
904
+ *
905
+ * `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
906
+ *
907
+ * Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
908
+ * **is** a number.
909
+ *
910
+ * @category Domain Properties
911
+ */
912
+ readonly isNumber: boolean | undefined;
913
+ /** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
914
+ *
915
+ *
916
+ * @category Domain Properties
917
+ *
918
+ */
919
+ readonly isInteger: boolean | undefined;
920
+ /** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
921
+ *
922
+ * Note that every integer is also a rational.
923
+ *
924
+ *
925
+ * @category Domain Properties
926
+ *
927
+ */
928
+ readonly isRational: boolean | undefined;
868
929
  /**
869
- * Transform the expression by according to the rules:
870
- * the matching `lhs` of a rule is replaced by its `rhs`.
930
+ * The value of this expression is a number that is the root of a non-zero
931
+ * univariate polynomial with rational coefficients.
871
932
  *
872
- * If no rules apply, return `null`.
933
+ * All integers and rational numbers are algebraic.
934
+ *
935
+ * Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
936
+ *
937
+ *
938
+ * @category Domain Properties
873
939
  *
874
- * See also `subs` for a simple substitution.
875
940
  */
876
- replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
941
+ readonly isAlgebraic: boolean | undefined;
877
942
  /**
878
- * Replace all the symbols in the expression as indicated.
943
+ * The value of this expression is real number: finite and not imaginary.
879
944
  *
880
- * Note the same effect can be achieved with `this.replace()`, but
881
- * using `this.subs()` is more efficient, and simpler.
945
+ * `isFinite && !isImaginary`
882
946
  *
947
+ *
948
+ * @category Domain Properties
883
949
  */
884
- subs(sub: Substitution): BoxedExpression;
950
+ readonly isReal: boolean | undefined;
951
+ /** Real or ±Infinity
952
+ *
953
+ * `isReal || isInfinity`
954
+ *
955
+ *
956
+ * @category Domain Properties
957
+ */
958
+ readonly isExtendedReal: boolean | undefined;
885
959
  /**
886
- * Update the definition associated with this expression, taking
887
- * into account the specified scope.
960
+ * The value of this expression is a number, but not `NaN` or any Infinity
961
+ *
962
+ * `isReal || isImaginary`
963
+ *
964
+ *
965
+ * @category Domain Properties
888
966
  *
889
- * @internal
890
967
  */
891
- bind(scope: RuntimeScope | null): void;
892
- /** Purge any cached values.
968
+ readonly isComplex: boolean | undefined;
969
+ /** `isReal || isImaginary || isInfinity`
893
970
  *
894
- * @internal
971
+ *
972
+ * @category Domain Properties
895
973
  */
896
- unbind(): void;
974
+ readonly isExtendedComplex: boolean | undefined;
975
+ /** The value of this expression is a number with a imaginary part
976
+ *
977
+ *
978
+ * @category Domain Properties
979
+ */
980
+ readonly isImaginary: boolean | undefined;
981
+ /** Mathematical equality (strong equality), that is the value
982
+ * of this expression and of `rhs` are numerically equal.
983
+ *
984
+ * The numeric value of both expressions are compared.
985
+ *
986
+ * Numbers whose difference is less than `engine.tolerance` are
987
+ * considered equal. This tolerance is set when the `engine.precision` is
988
+ * changed to be such that the last two digits are ignored.
989
+ *
990
+ * @category Relational Operator
991
+ */
992
+ isEqual(rhs: BoxedExpression): boolean;
897
993
  }
898
994
  /** A semi boxed expression is an MathJSON expression which can include some
899
995
  * boxed terms.
@@ -901,29 +997,18 @@ export interface BoxedExpression {
901
997
  * This is convenient when creating new expressions from portions
902
998
  * of an existing `BoxedExpression` while avoiding unboxing and reboxing.
903
999
  */
904
- export declare type SemiBoxedExpression = BoxedExpression | number | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | string | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[];
905
- export declare type LambdaExpression = SemiBoxedExpression;
906
- export declare type BoxedLambdaExpression = BoxedExpression;
907
- export declare type PatternMatchOption = {
1000
+ export declare type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
1001
+ export declare type PatternMatchOptions = {
1002
+ substitution?: BoxedSubstitution;
908
1003
  recursive?: boolean;
909
1004
  numericTolerance?: number;
910
1005
  exact?: boolean;
911
1006
  };
912
1007
  export interface Pattern extends BoxedExpression {
913
- /**
914
- * If `expr` does not match the pattern, return `null`.
915
- *
916
- * Otherwise, return a substitution describing the values that the named
917
- * wildcard in the pattern should be changed to in order for the pattern to be
918
- * equal to the expression. If there are no named wildcards and the expression
919
- * matches the pattern, and empty object literal `{}` is returned.
920
- */
921
- match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
922
1008
  /** If `expr` matches the pattern, return `true`, otherwise `false` */
923
- test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
1009
+ test(expr: BoxedExpression, options?: PatternMatchOptions): boolean;
924
1010
  /** Return the number of exprs that matched the pattern */
925
- count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOption): number;
926
- subs(sub: Substitution): Pattern;
1011
+ count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOptions): number;
927
1012
  }
928
1013
  export interface ExpressionMapInterface<U> {
929
1014
  has(expr: BoxedExpression): boolean;
@@ -1000,7 +1085,7 @@ export declare type Scope = {
1000
1085
  iterationLimit?: number;
1001
1086
  };
1002
1087
  export declare type RuntimeScope = Scope & {
1003
- parentScope: RuntimeScope;
1088
+ parentScope?: RuntimeScope;
1004
1089
  symbolTable?: RuntimeSymbolTable;
1005
1090
  assumptions: undefined | ExpressionMapInterface<boolean>;
1006
1091
  /** The location of the call site that created this scope */
@@ -1141,12 +1226,6 @@ export declare type FunctionDefinitionFlags = {
1141
1226
  * and its value is numeric.
1142
1227
  */
1143
1228
  numeric: boolean;
1144
- /**
1145
- * When true, evaluating the function create a temporary scope.
1146
- * This is used for example by the `Lambda` function to keep track of the
1147
- * inferred domain of its wildcard `_` arguments
1148
- */
1149
- scoped: boolean;
1150
1229
  };
1151
1230
  /**
1152
1231
  *
@@ -1163,76 +1242,89 @@ export declare type FunctionSignature = {
1163
1242
  /**
1164
1243
  * Return the canonical form of the expression with the arguments `args`.
1165
1244
  *
1166
- * All the arguments that are not subject to a hold are in canonical form.
1167
- * Any `Nothing` argument has been removed.
1245
+ * The arguments (`args`) may not be in canonical form. If necessary, they
1246
+ * can be put in canonical form.
1168
1247
  *
1169
- * If the function is associative, idempotent or an involution,
1170
- * it should handle its arguments accordingly. Notably, if it
1171
- * is commutative, the arguments should be sorted in canonical order.
1248
+ * This handler should validate the domain and number of the arguments.
1249
+ * If a required argument is missing, it should be indicated with a
1250
+ * `["Error", "'missing"]` expression. If more arguments than expected
1251
+ * are present, this should be indicated with a `unexpected-argument` error.
1252
+ * If the domain of an argument is not compatible, it should be indicated with
1253
+ * a `incompatible-domain` error.
1172
1254
  *
1173
- * The handler can make transformations based on the value of the arguments
1174
- * that are literal and either rational numbers (i.e.
1175
- * `arg.isLiteral && arg.isRational`) or integers (i.e.
1176
- * `isLiteral && arg.isInteger`).
1255
+ * `["Sequence"]` expressions are not folded and need to be handled
1256
+ * explicitly.
1177
1257
  *
1178
- * The handler should not consider the value of the arguments
1179
- * that are symbols or functions.
1258
+ * If the function is associative, idempotent or an involution,
1259
+ * this handler should account for it. Notably, if it is commutative, the
1260
+ * arguments should be sorted in canonical order.
1180
1261
  *
1181
- * The handler should not consider any assumptions about any of the
1182
- * arguments that are symbols or functions i.e. `arg.isZero`,
1183
- * `arg.isInteger`, etc...
1262
+ * The handler can make transformations based on the value of the arguments
1263
+ * that are exact (i.e. `arg.isExact`).
1184
1264
  *
1185
- * The handler should not make transformations based on the value of
1186
- * floating point numbers.
1265
+ * The handler should not consider the value or any assumptions about any
1266
+ * of the arguments that are symbols or functions (i.e. `arg.isZero`,
1267
+ * `arg.isInteger`, etc...) since those may change over time.
1187
1268
  *
1188
1269
  * The result of the handler should be a canonical expression.
1189
1270
  *
1271
+ * If the arguments do not match, they should be replaced with an appropriate
1272
+ * `["Error"]` expression. If the expression cannot be put in canonical form,
1273
+ * the handler should return `null`.
1274
+ *
1190
1275
  */
1191
- canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1276
+ canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
1192
1277
  /**
1193
1278
  * Rewrite an expression into a simpler form.
1194
1279
  *
1195
1280
  * The arguments are in canonical form and have been simplified.
1196
1281
  *
1197
- * The handler can use the values assigned to symbols and the assumptions about
1198
- * symbols, for example with `arg.machineValue`, `arg.isInteger` or
1282
+ * The handler can use the values assigned to symbols and the assumptions
1283
+ * about symbols, for example with `arg.numericValue`, `arg.isInteger` or
1199
1284
  * `arg.isPositive`.
1200
1285
  *
1201
1286
  * Even though a symbol may not have a value, there may be some information
1202
1287
  * about it reflected for example in `this.isZero` or `this.isPrime`.
1203
1288
  *
1204
1289
  * The handler should not perform approximate numeric calculations, such
1205
- * as calculations involving floating point numbers. Making exact
1206
- * calculations on integers or rationals is OK. It is recommended, but not
1207
- * required, that the calculations be limited to `this.smallIntegerValue`
1208
- * (i.e. numeric representations of the expression as an integer of small
1209
- * magnitude).
1290
+ * as calculations involving decimal numbers (non-integers). Making exact
1291
+ * calculations on integers or rationals is OK.
1210
1292
  *
1211
1293
  * This handler should not have any side-effects: do not modify
1212
1294
  * the environment of the `ComputeEngine` instance, do not perform I/O,
1213
1295
  * do not do calculations that depend on random values.
1214
1296
  *
1215
- * If no simplification can be performed due to the values, domains or assumptions
1216
- * about its arguments, for example, return `undefined`.
1297
+ * If no simplification can be performed due to the values, domains or
1298
+ * assumptions about its arguments, for example, return `undefined`.
1217
1299
  *
1218
1300
  */
1219
1301
  simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1220
1302
  /**
1221
- * Evaluate symbolically an expression.
1303
+ * Evaluate symbolically a function expression.
1222
1304
  *
1223
1305
  * The arguments have been symbolically evaluated, except the arguments to
1224
1306
  * which a `hold` apply.
1225
1307
  *
1226
1308
  * It is not necessary to further simplify or evaluate the arguments.
1227
1309
  *
1228
- * If the expression cannot be evaluated, due to the values, domains, or
1229
- * assumptions about its arguments, for example, return `undefined`.
1310
+ * If performing numerical calculations, if all the arguments are exact,
1311
+ * return an exact expression. If any of the arguments is not exact, that is
1312
+ * if it is a literal decimal (non-integer) number, return an approximation.
1313
+ * In this case, the value may be the same as `expr.N()`.
1230
1314
  *
1315
+ * When doing an exact calculation:
1316
+ * - do not reduce rational numbers to decimal (floating point approximation)
1317
+ * - do not down convert bignums to machine numbers
1318
+ * - do not reduce square roots of rational numbers
1319
+ * - do not reduce constants with a `hold` attribute
1231
1320
  *
1321
+ * If the expression cannot be evaluated, due to the values, domains, or
1322
+ * assumptions about its arguments, for example, return `undefined` or
1323
+ * an `["Error"]` expression.
1232
1324
  */
1233
- evaluate?: LambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1325
+ evaluate?: SemiBoxedExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1234
1326
  /**
1235
- * Evaluate numerically an expression.
1327
+ * Evaluate numerically a function expression.
1236
1328
  *
1237
1329
  * The arguments `args` have been simplified and evaluated, numerically
1238
1330
  * if possible, except the arguments to which a `hold` apply.
@@ -1251,19 +1343,22 @@ export declare type FunctionSignature = {
1251
1343
  * evaluation, but a literal argument is out of range or
1252
1344
  * not of the expected type.
1253
1345
  *
1254
- * Also return `NaN` if the result of the evaluation would be a complex
1255
- * number, but complex numbers are not allowed (the `engine.numericMode`
1256
- * is not `complex` or `auto`).
1346
+ * Note that regardless of the current value of `ce.numericMode`, the
1347
+ * arguments may be boxed numbers representing machine numbers, bignum
1348
+ * numbers, complex numbers, rationals or big rationals.
1349
+ *
1350
+ * Use the value of `ce.numericMode` to determine how to perform
1351
+ * the numeric evaluation.
1257
1352
  *
1258
- * If the `ce.numericMode` is `auto` or `complex`, you may return
1259
- * a Complex number as a result. Otherwise, if the result is a complex
1260
- * value, return `NaN`. If Complex are not allowed, none of the arguments
1261
- * will be complex literals.
1353
+ * If the numeric mode does not allow complex numbers (the
1354
+ * `engine.numericMode` is not `"complex"` or `"auto"`) and the result of
1355
+ * the evaluation would be a complex number, return `NaN` instead.
1262
1356
  *
1263
- * If the `ce.numericMode` is `decimal` or `auto` and
1264
- * `this.engine.precision` is > 15, you may return a Decimal number.
1265
- * Otherwise, return a `machine` number approximation. If Decimal are
1266
- * not allowed, none of the arguments will be Decimal literal.
1357
+ * If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should be done
1358
+ * using bignums.
1359
+ *
1360
+ * Otherwise, `ce.numericMode` is `"machine", the evaluation should be
1361
+ * performed using machine numbers.
1267
1362
  *
1268
1363
  * You may perform any necessary computations, including approximate
1269
1364
  * calculations on floating point numbers.
@@ -1274,17 +1369,17 @@ export declare type FunctionSignature = {
1274
1369
  * @experimental
1275
1370
  */
1276
1371
  evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1277
- /** Return the sign of the function given a list of arguments. */
1372
+ /** Return the sign of the function expression. */
1278
1373
  sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
1279
1374
  /** Return a compiled (optimized) expression. */
1280
1375
  compile?: (expr: BoxedExpression) => CompiledExpression;
1281
1376
  };
1282
1377
  export declare type BoxedFunctionSignature = {
1283
1378
  domain: BoxedDomain;
1284
- codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null);
1285
- canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1379
+ codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
1380
+ canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
1286
1381
  simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1287
- evaluate?: BoxedLambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1382
+ evaluate?: BoxedExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
1288
1383
  N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
1289
1384
  evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
1290
1385
  sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
@@ -1377,7 +1472,7 @@ export declare type SymbolDefinitionFlags = {
1377
1472
  */
1378
1473
  constant: boolean;
1379
1474
  /**
1380
- * If false, the value of the symbol is substituted during canonicalization
1475
+ * If `false`, the value of the symbol is substituted during canonicalization
1381
1476
  * or simplification.
1382
1477
  *
1383
1478
  * If true, the value is only replaced during a `ce.N()` or `ce.evaluate()`.
@@ -1421,8 +1516,6 @@ export interface IComputeEngine {
1421
1516
  /** @internal */
1422
1517
  readonly _ONE: BoxedExpression;
1423
1518
  /** @internal */
1424
- readonly _TWO: BoxedExpression;
1425
- /** @internal */
1426
1519
  readonly _HALF: BoxedExpression;
1427
1520
  /** @internal */
1428
1521
  readonly _NEGATIVE_ONE: BoxedExpression;
@@ -1437,19 +1530,19 @@ export interface IComputeEngine {
1437
1530
  /** @internal */
1438
1531
  readonly _COMPLEX_INFINITY: BoxedExpression;
1439
1532
  /** @internal */
1440
- readonly _DECIMAL_NAN: Decimal;
1533
+ readonly _BIGNUM_NAN: Decimal;
1441
1534
  /** @internal */
1442
- readonly _DECIMAL_ZERO: Decimal;
1535
+ readonly _BIGNUM_ZERO: Decimal;
1443
1536
  /** @internal */
1444
- readonly _DECIMAL_ONE: Decimal;
1537
+ readonly _BIGNUM_ONE: Decimal;
1445
1538
  /** @internal */
1446
- readonly _DECIMAL_TWO: Decimal;
1539
+ readonly _BIGNUM_TWO: Decimal;
1447
1540
  /** @internal */
1448
- readonly _DECIMAL_HALF: Decimal;
1541
+ readonly _BIGNUM_HALF: Decimal;
1449
1542
  /** @internal */
1450
- readonly _DECIMAL_PI: Decimal;
1543
+ readonly _BIGNUM_PI: Decimal;
1451
1544
  /** @internal */
1452
- readonly _DECIMAL_NEGATIVE_ONE: Decimal;
1545
+ readonly _BIGNUM_NEGATIVE_ONE: Decimal;
1453
1546
  /** The current scope */
1454
1547
  context: RuntimeScope | null;
1455
1548
  /** Absolute time beyond which evaluation should not proceed
@@ -1471,7 +1564,7 @@ export interface IComputeEngine {
1471
1564
  chop(n: Complex): Complex | 0;
1472
1565
  chop(n: number | Decimal | Complex): number | Decimal | Complex;
1473
1566
  /** @internal */
1474
- decimal: (a: Decimal.Value) => Decimal;
1567
+ bignum: (a: Decimal.Value) => Decimal;
1475
1568
  /** @internal */
1476
1569
  complex: (a: number | Complex, b?: number) => Complex;
1477
1570
  set precision(p: number | 'machine');
@@ -1491,17 +1584,23 @@ export interface IComputeEngine {
1491
1584
  defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
1492
1585
  lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1493
1586
  /** Return `undefined` if no definition exist for this `head` */
1494
- lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
1587
+ lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
1495
1588
  /**
1496
1589
  * Return a boxed expression from the input.
1497
- *
1498
- * The result may not be canonical.
1499
1590
  */
1500
- box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
1501
- /** Return a canonical boxed number */
1502
- number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
1591
+ box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
1592
+ canonical?: boolean;
1593
+ }): BoxedExpression;
1594
+ /** Return a boxed number */
1595
+ number(value: number | string | MathJsonNumber | Decimal | Complex | [num: number, denom: number] | [num: Decimal, denom: Decimal], options?: {
1596
+ metadata?: Metadata;
1597
+ canonical?: boolean;
1598
+ }): BoxedExpression;
1503
1599
  /** Return a canonical boxed symbol */
1504
- symbol(sym: string, metadata?: Metadata): BoxedExpression;
1600
+ symbol(sym: string, options?: {
1601
+ metadata?: Metadata;
1602
+ canonical?: boolean;
1603
+ }): BoxedExpression;
1505
1604
  /** Return a canonical boxed string */
1506
1605
  string(s: string, metadata?: Metadata): BoxedExpression;
1507
1606
  /** Return a canonical boxed domain.
@@ -1510,8 +1609,6 @@ export interface IComputeEngine {
1510
1609
  *
1511
1610
  */
1512
1611
  domain(domain: SemiBoxedExpression | BoxedDomain | string, metadata?: Metadata): BoxedDomain;
1513
- /** Return a canonical lambda expression */
1514
- lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
1515
1612
  /**
1516
1613
  * Return a canonical expression.
1517
1614
  *
@@ -1527,7 +1624,7 @@ export interface IComputeEngine {
1527
1624
  * This is a primitive to create a boxed function. It doesn't perform
1528
1625
  * any checks or normalization on its arguments.
1529
1626
  *
1530
- * In general, consider using `fn()` or `box()` instead.
1627
+ * In general, consider using `ce.fn()` or `ce.box()` instead.
1531
1628
  *
1532
1629
  * The result is canonical, but the caller has to ensure that all the
1533
1630
  * conditions are met (i.e. `ops` properly normalized and sorted, all
@@ -1539,6 +1636,10 @@ export interface IComputeEngine {
1539
1636
  * The result is canonical.
1540
1637
  */
1541
1638
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
1639
+ /**
1640
+ * Add a`["Hold"]` wrapper to `expr.
1641
+ */
1642
+ hold(expr: SemiBoxedExpression): BoxedExpression;
1542
1643
  /** Shortcut for `this.fn("Add"...)`.
1543
1644
  *
1544
1645
  * The result is canonical.
@@ -1553,7 +1654,8 @@ export interface IComputeEngine {
1553
1654
  *
1554
1655
  * The result is canonical.
1555
1656
  */
1556
- power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
1657
+ power(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
1658
+ sqrt(base: BoxedExpression, metadata?: Metadata): any;
1557
1659
  /** Shortcut for `this.fn("Divide", [1, expr])`
1558
1660
  *
1559
1661
  * The result is canonical.
@@ -1587,9 +1689,15 @@ export interface IComputeEngine {
1587
1689
  * The result may not be canonical.
1588
1690
  *
1589
1691
  */
1590
- parse(s: LatexString | string): BoxedExpression;
1591
- parse(s: null): null;
1592
- parse(s: LatexString | string | null): null | BoxedExpression;
1692
+ parse(s: LatexString | string, options?: {
1693
+ canonical?: boolean;
1694
+ }): BoxedExpression;
1695
+ parse(s: null, options?: {
1696
+ canonical?: boolean;
1697
+ }): null;
1698
+ parse(s: LatexString | string | null, options?: {
1699
+ canonical?: boolean;
1700
+ }): null | BoxedExpression;
1593
1701
  /** Serialize a `BoxedExpression` or a `MathJSON` expression to
1594
1702
  * a LaTeX string
1595
1703
  */
@@ -1607,8 +1715,22 @@ export interface IComputeEngine {
1607
1715
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
1608
1716
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
1609
1717
  /** {@inheritDoc JsonSerializationOptions} */
1610
- get jsonSerializationOptions(): JsonSerializationOptions;
1718
+ get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
1611
1719
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
1720
+ pushScope(options?: {
1721
+ symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
1722
+ assumptions?: (LatexString | Expression | BoxedExpression)[];
1723
+ scope?: Partial<Scope>;
1724
+ }): void;
1725
+ popScope(): void;
1726
+ /** Assign a value to an identifier in the current scope */
1727
+ set(identifiers: {
1728
+ [identifier: string]: SemiBoxedExpression;
1729
+ }): void;
1730
+ /** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope*/
1731
+ let(identifiers: {
1732
+ [identifier: string]: SymbolDefinition | FunctionDefinition;
1733
+ }): void;
1612
1734
  /**
1613
1735
  * Add an assumption.
1614
1736
  *
@@ -1630,13 +1752,7 @@ export interface IComputeEngine {
1630
1752
  /** Remove all assumptions about one or more symbols */
1631
1753
  forget(symbol?: string | string[]): void;
1632
1754
  get assumptions(): ExpressionMapInterface<boolean>;
1633
- ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
1634
- pushScope(options?: {
1635
- symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
1636
- assumptions?: (LatexString | Expression | BoxedExpression)[];
1637
- scope?: Partial<Scope>;
1638
- }): void;
1639
- popScope(): void;
1755
+ ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
1640
1756
  /**
1641
1757
  * When `condition` is false, signal.
1642
1758
  *