@cortex-js/compute-engine 0.20.2 → 0.21.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 (102) hide show
  1. package/dist/compute-engine.esm.js +585 -153
  2. package/dist/compute-engine.js +585 -153
  3. package/dist/compute-engine.min.esm.js +10 -10
  4. package/dist/compute-engine.min.js +10 -10
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/order.d.ts +8 -2
  27. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  30. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  31. package/dist/types/compute-engine/compile.d.ts +1 -1
  32. package/dist/types/compute-engine/compute-engine.d.ts +265 -29
  33. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  34. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  35. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +2 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
  53. package/dist/types/compute-engine/latex-syntax/public.d.ts +5 -2
  54. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  57. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  62. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  63. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  64. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  65. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  66. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  67. package/dist/types/compute-engine/library/core.d.ts +1 -1
  68. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  69. package/dist/types/compute-engine/library/library.d.ts +1 -1
  70. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  71. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  72. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  73. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  74. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  75. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  76. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  77. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  78. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  79. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  80. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  81. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  82. package/dist/types/compute-engine/numerics/numeric.d.ts +3 -3
  83. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  85. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  86. package/dist/types/compute-engine/public.d.ts +8 -260
  87. package/dist/types/compute-engine/rules.d.ts +1 -1
  88. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  89. package/dist/types/compute-engine/solve.d.ts +1 -1
  90. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  92. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  96. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  97. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  98. package/dist/types/compute-engine.d.ts +2 -2
  99. package/dist/types/math-json/math-json-format.d.ts +1 -1
  100. package/dist/types/math-json/utils.d.ts +1 -1
  101. package/dist/types/math-json.d.ts +2 -2
  102. package/package.json +2 -1
@@ -1,13 +1,14 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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 } 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,39 +432,114 @@ 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
439
  canonical?: boolean;
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
+ */
324
513
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
514
+ array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
325
515
  string(s: string, metadata?: Metadata): BoxedExpression;
516
+ /** Return a boxed symbol */
326
517
  symbol(name: string, options?: {
327
518
  metadata?: Metadata;
328
519
  canonical?: boolean;
329
520
  }): BoxedExpression;
521
+ /** Return a canonical boxed domain.
522
+ *
523
+ * If the domain is invalid, may return an `["Error"]` expression
524
+ *
525
+ */
330
526
  domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
527
+ /**
528
+ * This function tries to avoid creating a boxed number if `num` corresponds
529
+ * to a common value for which we have a shared instance (-1, 0, NaN, etc...)
530
+ */
331
531
  number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
332
532
  canonical?: boolean;
333
533
  metadata?: Metadata;
334
534
  }): BoxedExpression;
335
535
  rules(rules: Rule[]): BoxedRuleSet;
336
536
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
537
+ /**
538
+ * Parse a string of LaTeX and return a corresponding `BoxedExpression`.
539
+ *
540
+ * The result may not be canonical.
541
+ *
542
+ */
337
543
  parse(latex: LatexString | string, options?: {
338
544
  canonical?: boolean;
339
545
  }): BoxedExpression;
@@ -343,11 +549,25 @@ export declare class ComputeEngine implements IComputeEngine {
343
549
  parse(latex: LatexString | string | null, options?: {
344
550
  canonical?: boolean;
345
551
  }): null | BoxedExpression;
552
+ /** Serialize a `BoxedExpression` or a `MathJSON` expression to
553
+ * a LaTeX string
554
+ */
346
555
  serialize(x: Expression | BoxedExpression, options?: {
347
556
  canonical?: boolean;
348
557
  }): string;
558
+ /**
559
+ * Options to control the serialization of MathJSON expression to LaTeX
560
+ * when using `this.latex` or `this.engine.serialize()`.
561
+ *
562
+ *
563
+ * {@inheritDoc NumberFormattingOptions}
564
+ * {@inheritDoc ParseLatexOptions}
565
+ * {@inheritDoc SerializeLatexOptions}
566
+ *
567
+ */
349
568
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
350
569
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
570
+ /** {@inheritDoc JsonSerializationOptions} */
351
571
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
352
572
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
353
573
  rawJson(expr: BoxedExpression): Expression;
@@ -366,6 +586,22 @@ export declare class ComputeEngine implements IComputeEngine {
366
586
  *
367
587
  */
368
588
  verify(_query: SemiBoxedExpression): boolean;
589
+ /**
590
+ * Add an assumption.
591
+ *
592
+ * Note that the assumption is put into canonical form before being added.
593
+ *
594
+ * @param symbol - The symbol to make an assumption about
595
+ *
596
+ * Returns:
597
+ * - `contradiction` if the new assumption is incompatible with previous
598
+ * ones.
599
+ * - `tautology` if the new assumption is redundant with previous ones.
600
+ * - `ok` if the assumption was successfully added to the assumption set.
601
+ *
602
+ *
603
+ */
369
604
  assume(predicate: SemiBoxedExpression): AssumeResult;
605
+ /** Remove all assumptions about one or more symbols */
370
606
  forget(symbol: undefined | string | string[]): void;
371
607
  }
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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.21.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.21.0 */
2
2
  /***
3
3
  * ## THEORY OF OPERATIONS
4
4
  *
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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.21.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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.21.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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.21.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.21.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.21.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.21.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.21.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.21.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.21.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.21.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.21.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.21.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.21.0 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
4
  * - combine literal integers and rationals
@@ -1,4 +1,4 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  /**
3
3
  *
4
4
  */
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export type CanonicalArithmeticFunctions = 'Add' | 'Negate' | 'Sqrt' | 'Multiply' | 'Divide' | 'Power' | 'Ln';
3
3
  export declare const ARITHMETIC_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const CALCULUS_LIBRARY: IdentifierDefinitions[];
@@ -1,3 +1,3 @@
1
- /* 0.20.2 */
1
+ /* 0.21.0 */
2
2
  export declare const DEFAULT_LINSPACE_COUNT = 50;
3
3
  export declare const COLLECTIONS_LIBRARY: IdentifierDefinitions;