@cortex-js/compute-engine 0.20.2 → 0.22.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 (107) hide show
  1. package/README.md +6 -3
  2. package/dist/compute-engine.esm.js +6744 -4603
  3. package/dist/compute-engine.js +6744 -4603
  4. package/dist/compute-engine.min.esm.js +10 -10
  5. package/dist/compute-engine.min.js +10 -10
  6. package/dist/math-json.esm.js +2 -2
  7. package/dist/math-json.js +2 -2
  8. package/dist/math-json.min.esm.js +2 -2
  9. package/dist/math-json.min.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +1 -1
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/signals.d.ts +1 -1
  13. package/dist/types/common/utils.d.ts +1 -1
  14. package/dist/types/compute-engine/assume.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -1
  16. package/dist/types/compute-engine/boxed-expression/box.d.ts +3 -3
  17. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +11 -3
  21. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +2 -1
  26. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +69 -0
  27. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
  28. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/order.d.ts +8 -2
  30. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  33. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  34. package/dist/types/compute-engine/compile.d.ts +1 -1
  35. package/dist/types/compute-engine/compute-engine.d.ts +270 -33
  36. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  37. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  38. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +2 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/{definitions-inequalities.d.ts → definitions-relational-operators.d.ts} +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
  56. package/dist/types/compute-engine/latex-syntax/public.d.ts +5 -2
  57. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  59. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  60. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
  62. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  63. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +3 -3
  64. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  65. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  66. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  67. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  68. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  69. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  70. package/dist/types/compute-engine/library/core.d.ts +2 -1
  71. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  72. package/dist/types/compute-engine/library/library.d.ts +1 -1
  73. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  74. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  75. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  77. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  78. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  79. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  80. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  81. package/dist/types/compute-engine/library/utils.d.ts +5 -5
  82. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  83. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  85. package/dist/types/compute-engine/numerics/numeric.d.ts +3 -3
  86. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  87. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  88. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  89. package/dist/types/compute-engine/public.d.ts +68 -286
  90. package/dist/types/compute-engine/rules.d.ts +9 -13
  91. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  92. package/dist/types/compute-engine/solve.d.ts +2 -1
  93. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
  96. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  97. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  98. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  99. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  100. package/dist/types/compute-engine/symbolic/tensor-fields.d.ts +168 -0
  101. package/dist/types/compute-engine/symbolic/tensors.d.ts +103 -0
  102. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  103. package/dist/types/compute-engine.d.ts +2 -2
  104. package/dist/types/math-json/math-json-format.d.ts +1 -1
  105. package/dist/types/math-json/utils.d.ts +1 -1
  106. package/dist/types/math-json.d.ts +2 -2
  107. package/package.json +2 -1
@@ -1,13 +1,14 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import type { LibraryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
5
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue, DomainLiteral } from './public';
5
+ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue, DomainLiteral, ArrayValue, CanonicalForm } from './public';
6
6
  /**
7
7
  *
8
- * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
8
+ * To use the CortexJS Compute Engine, create a `ComputeEngine` instance, or if using a
9
+ * mathfield, use the default Compute Engine instance from the `MathfieldElement` class: `ce = MathfieldElement.computeEngine`.
9
10
  *
10
- * Use the instance to create expressions with `ce.parse()` and `ce.box()`.
11
+ * Use the instance to create boxed expressions with `ce.parse()` and `ce.box()`.
11
12
  *
12
13
  *
13
14
  * ```ts
@@ -19,7 +20,6 @@ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefi
19
20
  * expr = ce.box(["Expand", ["Power", ["Add", "a", "b"], 2]]);
20
21
  * console.log(expr.evaluate().latex);
21
22
  * // ➔ "a^2 + 2ab + b^2"
22
- *
23
23
  * ```
24
24
  */
25
25
  export declare class ComputeEngine implements IComputeEngine {
@@ -82,12 +82,6 @@ export declare class ComputeEngine implements IComputeEngine {
82
82
  * @internal */
83
83
  private _useRawJsonSerializationOptions;
84
84
  private _rawJsonSerializationOptions;
85
- /** The domain of unknown symbols. If `null` unknown symbols do not have a
86
- * definition automatically associated with them.
87
- *
88
- * @internal
89
- */
90
- private _defaultDomain;
91
85
  /** @internal */
92
86
  private _commonSymbols;
93
87
  /** @internal */
@@ -106,6 +100,13 @@ export declare class ComputeEngine implements IComputeEngine {
106
100
  *
107
101
  */
108
102
  context: RuntimeScope | null;
103
+ /** In strict mode (the default) the Compute Engine performs
104
+ * validation of domains and signature and may report errors.
105
+ *
106
+ * When strict mode is off, results may be incorrect or generate JavaScript
107
+ * errors if the input is not valid.
108
+ *
109
+ */
109
110
  strict: boolean;
110
111
  /** Absolute time beyond which evaluation should not proceed.
111
112
  * @internal
@@ -205,7 +206,102 @@ export declare class ComputeEngine implements IComputeEngine {
205
206
  chop(n: number): number;
206
207
  chop(n: Decimal): Decimal | 0;
207
208
  chop(n: Complex): Complex | 0;
209
+ /** Create an arbitrary precision number.
210
+ *
211
+ * The return value is an object with methods to perform arithmetic
212
+ * operations:
213
+ * - `toNumber()`: convert to a JavaScript `number` with potential loss of precision
214
+ * - `add()`
215
+ * - `sub()`
216
+ * - `neg()` (unary minus)
217
+ * - `mul()`
218
+ * - `div()`
219
+ * - `pow()`
220
+ * - `sqrt()` (square root)
221
+ * - `cbrt()` (cube root)
222
+ * - `exp()` (e^x)
223
+ * - `log()`
224
+ * - `ln()` (natural logarithm)
225
+ * - `mod()`
226
+
227
+ * - `abs()`
228
+ * - `ceil()`
229
+ * - `floor()`
230
+ * - `round()`
231
+
232
+ * - `equals()`
233
+ * - `gt()`
234
+ * - `gte()`
235
+ * - `lt()`
236
+ * - `lte()`
237
+ *
238
+ * - `cos()`
239
+ * - `sin()`
240
+ * - `tanh()`
241
+ * - `acos()`
242
+ * - `asin()`
243
+ * - `atan()`
244
+ * - `cosh()`
245
+ * - `sinh()`
246
+ * - `acosh()`
247
+ * - `asinh()`
248
+ * - `atanh()`
249
+ *
250
+ * - `isFinite()`
251
+ * - `isInteger()`
252
+ * - `isNaN()`
253
+ * - `isNegative()`
254
+ * - `isPositive()`
255
+ * - `isZero()`
256
+ * - `sign()` (1, 0 or -1)
257
+ *
258
+ */
208
259
  bignum(a: Decimal.Value | bigint): Decimal;
260
+ /** Create a complex number.
261
+ * The return value is an object with methods to perform arithmetic
262
+ * operations:
263
+ * - `re` (real part, as a JavaScript `number`)
264
+ * - `im` (imaginary part, as a JavaScript `number`)
265
+ * - `add()`
266
+ * - `sub()`
267
+ * - `neg()` (unary minus)
268
+ * - `mul()`
269
+ * - `div()`
270
+ * - `pow()`
271
+ * - `sqrt()` (square root)
272
+ * - `exp()` (e^x)
273
+ * - `log()`
274
+ * - `ln()` (natural logarithm)
275
+ * - `mod()`
276
+
277
+ * - `abs()`
278
+ * - `ceil()`
279
+ * - `floor()`
280
+ * - `round()`
281
+
282
+ * - `arg()` the angle of the complex number
283
+ * - `inverse()` the inverse of the complex number 1/z
284
+ * - `conjugate()` the conjugate of the complex number
285
+
286
+ * - `equals()`
287
+ *
288
+ * - `cos()`
289
+ * - `sin()`
290
+ * - `tanh()`
291
+ * - `acos()`
292
+ * - `asin()`
293
+ * - `atan()`
294
+ * - `cosh()`
295
+ * - `sinh()`
296
+ * - `acosh()`
297
+ * - `asinh()`
298
+ * - `atanh()`
299
+ *
300
+ * - `isFinite()`
301
+ * - `isNaN()`
302
+ * - `isZero()`
303
+ * - `sign()` (1, 0 or -1)
304
+ */
209
305
  complex(a: number | Decimal | Complex, b?: number | Decimal): Complex;
210
306
  isBignum(a: unknown): a is Decimal;
211
307
  isComplex(a: unknown): a is Complex;
@@ -230,10 +326,26 @@ export declare class ComputeEngine implements IComputeEngine {
230
326
  */
231
327
  lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
232
328
  /**
233
- * Add (or replace) a definition for a symbol in the current scope.
329
+ * Associate a new definition to a symbol in the current context.
330
+ *
331
+ * If a definition existed previously, it is replaced.
332
+ *
333
+ *
334
+ * For internal use. Use `ce.declare()` instead.
335
+ *
336
+ * @internal
234
337
  */
235
338
  defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
236
339
  _defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
340
+ /**
341
+ * Associate a new delookupSymbolfinition to a function in the current context.
342
+ *
343
+ * If a definition existed previously, it is replaced.
344
+ *
345
+ * For internal use. Use `ce.declare()` instead.
346
+ *
347
+ * @internal
348
+ */
237
349
  defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
238
350
  _defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
239
351
  /**
@@ -245,38 +357,57 @@ export declare class ComputeEngine implements IComputeEngine {
245
357
  *
246
358
  *
247
359
  */
248
- pushScope(scope?: Partial<Scope>): IComputeEngine;
249
- /** Remove the topmost scope from the scope stack.
250
- */
251
- popScope(): IComputeEngine;
360
+ pushScope(scope?: Partial<Scope>): ComputeEngine;
361
+ /** Remove the most recent scope from the scope stack, and set its
362
+ * parent scope as current. */
363
+ popScope(): ComputeEngine;
364
+ /** Set the current scope, return the previous scope. */
252
365
  swapScope(scope: RuntimeScope | null): RuntimeScope | null;
366
+ /**
367
+ * Reset the value of any identifiers that have been assigned a value
368
+ * in the current scope.
369
+ * @internal */
253
370
  resetContext(): void;
371
+ /** @internal */
254
372
  _printScope(options?: {
255
373
  details?: boolean;
256
374
  maxDepth?: number;
257
375
  }, scope?: RuntimeScope | null, depth?: number): RuntimeScope | null;
258
376
  /**
259
- * Declare one or more identifiers:
377
+ * Declare an identifier: specify their domain, and other attributes,
378
+ * including optionally a value.
379
+ *
380
+ * Once the domain of an identifier has been declared, it cannot be changed.
381
+ * The domain information is used to calculate the canonical form of
382
+ * expressions and ensure they are valid. If the domain could be changed
383
+ * after the fact, previously valid expressions could become invalid.
384
+ *
385
+ * Use the `Anyting` domain for a very generic domain.
260
386
  *
261
- * associate an identifier with a definition, at minimum a domain, optionally
262
- * a value and some other flags.
263
387
  */
264
- declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
388
+ declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): ComputeEngine;
265
389
  declare(identifiers: {
266
390
  [id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
267
- }): IComputeEngine;
268
- /**
269
- * Assign a value to one or more identifiers.
391
+ }): ComputeEngine;
392
+ /** Assign a value to an identifier in the current scope.
393
+ * Use `undefined` to reset the identifier to no value.
270
394
  *
271
- * Domain of value must be compatible with existing domain.
395
+ * The identifier should be a valid MathJSON identifier
396
+ * not a LaTeX string.
272
397
  *
273
- * Declare identifier if it hasn't been declared yet.
398
+ * The identifier can take the form "f(x, y") to create a function
399
+ * with two parameters, "x" and "y".
274
400
  *
401
+ * If the id was not previously declared, an automatic declaration
402
+ * is done. The domain of the identifier is inferred from the value.
403
+ * To more precisely define the domain of the identifier, use `ce.declare()`
404
+ * instead, which allows you to specify the domain, value and other
405
+ * attributes of the identifier.
275
406
  */
276
- assign(id: string, value: AssignValue): IComputeEngine;
407
+ assign(id: string, value: AssignValue): ComputeEngine;
277
408
  assign(ids: {
278
409
  [id: string]: AssignValue;
279
- }): IComputeEngine;
410
+ }): ComputeEngine;
280
411
  /**
281
412
  * Same as assign(), but for internal use:
282
413
  * - skips validity checks
@@ -285,7 +416,7 @@ export declare class ComputeEngine implements IComputeEngine {
285
416
  *
286
417
  * @internal
287
418
  */
288
- _assign(id: string, value: AssignValue): IComputeEngine;
419
+ _assign(id: string, value: AssignValue): ComputeEngine;
289
420
  get assumptions(): ExpressionMapInterface<boolean>;
290
421
  /**
291
422
  * Return false if the execution should stop.
@@ -301,53 +432,143 @@ export declare class ComputeEngine implements IComputeEngine {
301
432
  checkContinueExecution(): void;
302
433
  /** @internal */
303
434
  cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
435
+ /**
436
+ * Return a boxed expression from the input.
437
+ */
304
438
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
305
- canonical?: boolean;
439
+ canonical?: boolean | CanonicalForm | CanonicalForm[];
306
440
  }): BoxedExpression;
307
441
  canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
442
+ /**
443
+ * Return a function expression.
444
+ *
445
+ * Note that the result may not be a function, or may have a different
446
+ * `head` than the one specified.
447
+ *
448
+ * For example:
449
+ * `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
450
+ *
451
+ */
308
452
  fn(head: string, ops: BoxedExpression[], options?: {
309
453
  canonical: boolean;
310
454
  }): BoxedExpression;
311
455
  /** @internal */
312
456
  _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
457
+ /**
458
+ *
459
+ * Shortcut for `this.fn("Error"...)`.
460
+ *
461
+ * The result is canonical.
462
+ */
313
463
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
314
464
  domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
465
+ /**
466
+ * Add a`["Hold"]` wrapper to `expr.
467
+ */
315
468
  hold(expr: SemiBoxedExpression): BoxedExpression;
469
+ /** Shortcut for `this.fn("Add"...)`.
470
+ *
471
+ * The result is canonical.
472
+ */
316
473
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
474
+ /** Shortcut for `this.fn("Negate", [expr])`
475
+ *
476
+ * The result is canonical.
477
+ */
317
478
  neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
479
+ /** Shortcut for `this.fn("Multiply"...)`
480
+ *
481
+ * The result is canonical.
482
+ */
318
483
  mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
484
+ /** Shortcut for `this.fn("Divide", [num, denom])`
485
+ *
486
+ * The result is canonical.
487
+ */
319
488
  div(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
320
- sqrt(base: BoxedExpression, metadata?: Metadata): BoxedExpression;
489
+ /** Shortcut for `this.fn("Sqrt"...)`
490
+ *
491
+ * The result is canonical.
492
+ */
493
+ sqrt(base: BoxedExpression, metadata?: Metadata): any;
494
+ /** Shortcut for `this.fn("Power"...)`
495
+ *
496
+ * The result is canonical.
497
+ */
321
498
  pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
499
+ /** Shortcut for `this.fn("Divide", [1, expr])`
500
+ *
501
+ * The result is canonical.
502
+ */
322
503
  inv(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
504
+ /** Shortcut for `this.fn("Pair"...)`
505
+ *
506
+ * The result is canonical.
507
+ */
323
508
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
509
+ /** Shortcut for `this.fn("Tuple"...)`
510
+ *
511
+ * The result is canonical.
512
+ */
513
+ tuple(elements: number[], metadata?: Metadata): BoxedExpression;
324
514
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
515
+ array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
325
516
  string(s: string, metadata?: Metadata): BoxedExpression;
517
+ /** Return a boxed symbol */
326
518
  symbol(name: string, options?: {
327
519
  metadata?: Metadata;
328
520
  canonical?: boolean;
329
521
  }): BoxedExpression;
522
+ /** Return a canonical boxed domain.
523
+ *
524
+ * If the domain is invalid, may return an `["Error"]` expression
525
+ *
526
+ */
330
527
  domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
528
+ /**
529
+ * This function tries to avoid creating a boxed number if `num` corresponds
530
+ * to a common value for which we have a shared instance (-1, 0, NaN, etc...)
531
+ */
331
532
  number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
332
533
  canonical?: boolean;
333
534
  metadata?: Metadata;
334
535
  }): BoxedExpression;
335
536
  rules(rules: Rule[]): BoxedRuleSet;
336
537
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
538
+ /**
539
+ * Parse a string of LaTeX and return a corresponding `BoxedExpression`.
540
+ *
541
+ * The result may not be canonical.
542
+ *
543
+ */
337
544
  parse(latex: LatexString | string, options?: {
338
- canonical?: boolean;
545
+ canonical?: boolean | CanonicalForm | CanonicalForm[];
339
546
  }): BoxedExpression;
340
547
  parse(s: null, options?: {
341
- canonical?: boolean;
548
+ canonical?: boolean | CanonicalForm | CanonicalForm[];
342
549
  }): null;
343
550
  parse(latex: LatexString | string | null, options?: {
344
- canonical?: boolean;
551
+ canonical?: boolean | CanonicalForm | CanonicalForm[];
345
552
  }): null | BoxedExpression;
553
+ /** Serialize a `BoxedExpression` or a `MathJSON` expression to
554
+ * a LaTeX string
555
+ */
346
556
  serialize(x: Expression | BoxedExpression, options?: {
347
557
  canonical?: boolean;
348
558
  }): string;
559
+ /**
560
+ * Options to control the serialization of MathJSON expression to LaTeX
561
+ * when using `this.latex` or `this.engine.serialize()`.
562
+ *
563
+ *
564
+ * {@inheritDoc NumberFormattingOptions}
565
+ * {@inheritDoc ParseLatexOptions}
566
+ * {@inheritDoc SerializeLatexOptions}
567
+ *
568
+ */
349
569
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
350
570
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
571
+ /** {@inheritDoc JsonSerializationOptions} */
351
572
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
352
573
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
353
574
  rawJson(expr: BoxedExpression): Expression;
@@ -366,6 +587,22 @@ export declare class ComputeEngine implements IComputeEngine {
366
587
  *
367
588
  */
368
589
  verify(_query: SemiBoxedExpression): boolean;
590
+ /**
591
+ * Add an assumption.
592
+ *
593
+ * Note that the assumption is put into canonical form before being added.
594
+ *
595
+ * @param symbol - The symbol to make an assumption about
596
+ *
597
+ * Returns:
598
+ * - `contradiction` if the new assumption is incompatible with previous
599
+ * ones.
600
+ * - `tautology` if the new assumption is redundant with previous ones.
601
+ * - `ok` if the assumption was successfully added to the assumption set.
602
+ *
603
+ *
604
+ */
369
605
  assume(predicate: SemiBoxedExpression): AssumeResult;
606
+ /** Remove all assumptions about one or more symbols */
370
607
  forget(symbol: undefined | string | string[]): void;
371
608
  }
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedDomain, BoxedFunctionSignature, DomainLiteral, FunctionSignature, IComputeEngine, Rational } from './public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  /***
3
3
  * ## THEORY OF OPERATIONS
4
4
  *
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
3
3
  export declare const DELIMITERS_SHORTHAND: {
4
4
  '(': string;
@@ -24,3 +24,4 @@ export declare const DELIMITERS_SHORTHAND: {
24
24
  '\u23B0': string;
25
25
  '\u23B1': string;
26
26
  };
27
+ export declare function latexToDelimiterShorthand(s: string): string | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export type CommonEntry = {
4
4
  /** Note: a name is required if a serialize handler is provided */
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { Serializer } from './serializer';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { WarningSignalHandler } from '../../common/signals';
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { Parser } from './public';
3
3
  /** For error handling, if we have a identifier prefix, assume
4
4
  * the identifier is invalid (it would have been captured by
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
@@ -120,7 +120,7 @@ export declare class _Parser implements Parser {
120
120
  */
121
121
  parseTabular(): null | Expression[][];
122
122
  /** Parse a group as a a string, for example for `\operatorname` or `\begin` */
123
- parseStringGroup(): string | null;
123
+ parseStringGroup(optional?: boolean): string | null;
124
124
  /** Parse an environment: `\begin{env}...\end{end}`
125
125
  */
126
126
  private parseEnvironment;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -578,8 +578,11 @@ export interface Parser {
578
578
  *
579
579
  * LaTeX commands are typically not allowed inside a string group (for example,
580
580
  * `\alpha` would result in an error), but we do not enforce this.
581
+ *
582
+ * If `optional` is true, this should be an optional group in square brackets
583
+ * otherwise it is a regular group in braces.
581
584
  */
582
- parseStringGroup(): string | null;
585
+ parseStringGroup(optional?: boolean): string | null;
583
586
  /**
584
587
  * A symbol can be:
585
588
  * - a single-letter identifier: `x`
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { NumberFormattingOptions } from './public';
3
3
  export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
3
3
  export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
4
4
  export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  import { WarningSignalHandler } from '../../common/signals';
3
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
4
4
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -7,5 +7,5 @@ export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[])
7
7
  export declare function domainAdd(_ce: IComputeEngine, args: (undefined | BoxedDomain)[]): BoxedDomain | null | undefined;
8
8
  export declare function simplifyAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
9
9
  export declare function evalAdd(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression;
10
- export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
11
- export declare function evalSummation(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression | undefined, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
10
+ export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, indexingSet: BoxedExpression | undefined): BoxedExpression;
11
+ export declare function evalSummation(ce: IComputeEngine, expr: BoxedExpression, indexingSet: BoxedExpression | undefined, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.22.0 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
4
  * - combine literal integers and rationals
@@ -14,5 +14,5 @@
14
14
  export declare function canonicalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
15
15
  export declare function simplifyMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
16
16
  export declare function evalMultiply(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression | undefined;
17
- export declare function canonicalProduct(ce: IComputeEngine, body: BoxedExpression | undefined, range: BoxedExpression | undefined): BoxedExpression;
18
- export declare function evalMultiplication(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression | undefined, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
17
+ export declare function canonicalProduct(ce: IComputeEngine, body: BoxedExpression | undefined, indexingSet: BoxedExpression | undefined): BoxedExpression;
18
+ export declare function evalMultiplication(ce: IComputeEngine, expr: BoxedExpression, indexingSet: BoxedExpression | undefined, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;