@cortex-js/compute-engine 0.26.4 → 0.28.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 (145) hide show
  1. package/dist/compute-engine.esm.js +9785 -8316
  2. package/dist/compute-engine.js +9785 -8316
  3. package/dist/compute-engine.min.esm.js +57 -50
  4. package/dist/compute-engine.min.js +57 -50
  5. package/dist/math-json.esm.js +287 -7
  6. package/dist/math-json.js +287 -7
  7. package/dist/math-json.min.esm.js +287 -7
  8. package/dist/math-json.min.js +4 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/buffer.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +2 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +20 -0
  14. package/dist/types/common/json5.d.ts +3 -0
  15. package/dist/types/common/one-of.d.ts +1 -1
  16. package/dist/types/common/signals.d.ts +1 -1
  17. package/dist/types/common/styled-text.d.ts +1 -1
  18. package/dist/types/common/syntax-highlighter.d.ts +1 -1
  19. package/dist/types/common/terminal.d.ts +1 -1
  20. package/dist/types/common/type/boxed-type.d.ts +13 -0
  21. package/dist/types/common/type/parse.d.ts +1 -1
  22. package/dist/types/common/type/primitive.d.ts +2 -1
  23. package/dist/types/common/type/serialize.d.ts +1 -1
  24. package/dist/types/common/type/subtype.d.ts +1 -1
  25. package/dist/types/common/type/types.d.ts +39 -49
  26. package/dist/types/common/type/utils.d.ts +3 -7
  27. package/dist/types/common/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/assume.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +16 -9
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +3 -2
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +13 -6
  38. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +12 -8
  39. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +4 -4
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +5 -4
  43. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +7 -6
  44. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +4 -4
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +2 -1
  46. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/compare.d.ts +3 -3
  48. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/hold.d.ts +3 -2
  53. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/public.d.ts +109 -64
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/tensor-fields.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +7 -1
  68. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/validate.d.ts +3 -3
  70. package/dist/types/compute-engine/collection-utils.d.ts +3 -1
  71. package/dist/types/compute-engine/compile.d.ts +9 -8
  72. package/dist/types/compute-engine/compute-engine.d.ts +29 -16
  73. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  74. package/dist/types/compute-engine/debug.d.ts +3 -0
  75. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  90. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/public.d.ts +11 -6
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -1
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +3 -3
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -2
  97. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  98. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  99. package/dist/types/compute-engine/library/collections.d.ts +3 -2
  100. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  101. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  102. package/dist/types/compute-engine/library/core.d.ts +1 -1
  103. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  104. package/dist/types/compute-engine/library/library.d.ts +1 -1
  105. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  106. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  107. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  108. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  109. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  110. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  111. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  112. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  113. package/dist/types/compute-engine/library/utils.d.ts +3 -5
  114. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  115. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  116. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  117. package/dist/types/compute-engine/numeric-value/public.d.ts +1 -1
  118. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  119. package/dist/types/compute-engine/numerics/bignum.d.ts +1 -1
  120. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +9 -1
  124. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -2
  125. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/numeric.d.ts +2 -3
  127. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  131. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  132. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  133. package/dist/types/compute-engine/private.d.ts +29 -0
  134. package/dist/types/compute-engine/public.d.ts +1 -1
  135. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  136. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  137. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  138. package/dist/types/compute-engine/tensor/tensors.d.ts +2 -2
  139. package/dist/types/compute-engine.d.ts +3 -2
  140. package/dist/types/math-json/identifiers.d.ts +1 -1
  141. package/dist/types/math-json/types.d.ts +6 -6
  142. package/dist/types/math-json/utils.d.ts +3 -3
  143. package/dist/types/math-json.d.ts +3 -3
  144. package/package.json +3 -3
  145. package/dist/types/common/suggest.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import { NumericValue } from '../numeric-value/public';
3
3
  /** Combine rational expressions into a single fraction */
4
4
  export declare function together(op: BoxedExpression): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  /**
3
3
  *
4
4
  * Make all the arguments canonical.
@@ -1,9 +1,10 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  /** Apply the function `f` to each operand of the expression `expr`,
3
- * account for the 'hold' property of the function definition:
3
+ * account for the 'lazy' property of the function definition:
4
4
  *
5
5
  * Account for `Hold`, `ReleaseHold`, `Sequence`, `Symbol` and `Nothing`.
6
6
  *
7
7
  * If `f` returns `null`, the element is not added to the result
8
8
  */
9
9
  export declare function holdMap(expr: BoxedExpression, f: (x: BoxedExpression) => BoxedExpression | null): ReadonlyArray<BoxedExpression>;
10
+ export declare function holdMapAsync(expr: BoxedExpression, f: (x: BoxedExpression) => Promise<BoxedExpression | null>): Promise<ReadonlyArray<BoxedExpression>>;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  /**
3
3
  * The function attempts to match a subject expression to a
4
4
  * [pattern](/compute-engine/guides/patterns-and-rules/).
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare function canonicalNegate(expr: BoxedExpression): BoxedExpression;
3
3
  /**
4
4
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { Rational } from '../numerics/rationals';
3
3
  import type { BoxedExpression } from './public';
4
4
  export declare function asRational(expr: BoxedExpression): Rational | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import { Rational } from '../numerics/rationals';
3
3
  import { NumericValue } from '../numeric-value/public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { Expression, MathJsonNumber, MathJsonString, MathJsonSymbol, MathJsonFunction, MathJsonIdentifier } from '../../math-json';
3
3
  import type { SerializeLatexOptions, LatexDictionaryEntry, ParseLatexOptions } from '../latex-syntax/public';
4
4
  import type { IndexedLatexDictionary } from '../latex-syntax/dictionary/definitions';
@@ -8,6 +8,8 @@ import { BigNum, IBigNum } from '../numerics/bignum';
8
8
  import { Type, TypeString } from '../../common/type/types';
9
9
  import { AbstractTensor } from '../tensor/tensors';
10
10
  import { OneOf } from '../../common/one-of';
11
+ import { CompiledType, JSSource } from '../compile';
12
+ import { BoxedType } from '../../common/type/boxed-type';
11
13
  /**
12
14
  * :::info[THEORY OF OPERATIONS]
13
15
  *
@@ -899,8 +901,9 @@ export interface BoxedExpression {
899
901
  * If the type of this expression is already known, return `false`.
900
902
  *
901
903
  * If the type was not set, set it to the inferred type, return `true`
902
- * If the type was previously inferred, adjust it by widening it,
903
- * return `true`
904
+ * If the type was previously inferred, widen it and return `true`.
905
+ *
906
+ * If the type cannot be inferred, return `false`.
904
907
  *
905
908
  * @internal
906
909
  */
@@ -916,8 +919,8 @@ export interface BoxedExpression {
916
919
  *
917
920
  * Reset the cached value associated with this expression.
918
921
  *
919
- * Use when the environment has changed, for example the numeric mode
920
- * or precision, to force the expression to be re-evaluated.
922
+ * Use when the environment, for example the precision, has changed to
923
+ * force the expression to be re-evaluated.
921
924
  *
922
925
  * @internal
923
926
  */
@@ -972,7 +975,14 @@ export interface BoxedExpression {
972
975
  * The result is in canonical form.
973
976
  *
974
977
  */
975
- evaluate(options?: EvaluateOptions): BoxedExpression;
978
+ evaluate(options?: Partial<EvaluateOptions>): BoxedExpression;
979
+ /** Asynchronous version of `evaluate()`.
980
+ *
981
+ * The `options` argument can include a `signal` property, which is an
982
+ * `AbortSignal` object. If the signal is aborted, a `CancellationError` is thrown.
983
+ *
984
+ */
985
+ evaluateAsync(options?: Partial<EvaluateOptions>): Promise<BoxedExpression>;
976
986
  /** Return a numeric approximation of the canonical form of this expression.
977
987
  *
978
988
  * Any necessary calculations, including on decimal numbers (non-integers),
@@ -998,13 +1008,18 @@ export interface BoxedExpression {
998
1008
  *
999
1009
  * ```javascript
1000
1010
  * const expr = ce.parse('x^2 + y^2');
1001
- * const f = expr.compile('javascript');
1011
+ * const f = expr.compile();
1002
1012
  * console.log(f({x: 2, y: 3}));
1003
1013
  * ```
1004
1014
  */
1005
- compile(to?: 'javascript', options?: {
1006
- optimize: ('simplify' | 'evaluate')[];
1007
- }): ((args: Record<string, any>) => any | undefined) | undefined;
1015
+ compile(options?: {
1016
+ to?: 'javascript';
1017
+ optimize?: ('simplify' | 'evaluate')[];
1018
+ functions?: Record<MathJsonIdentifier, JSSource | ((...any: any[]) => any)>;
1019
+ vars?: Record<MathJsonIdentifier, CompiledType>;
1020
+ imports?: unknown[];
1021
+ preamble?: string;
1022
+ }): (args?: Record<string, CompiledType>) => CompiledType;
1008
1023
  /**
1009
1024
  * If this is an equation, solve the equation for the variables in vars.
1010
1025
  * Otherwise, solve the equation `this = 0` for the variables in vars.
@@ -1017,7 +1032,7 @@ export interface BoxedExpression {
1017
1032
  *
1018
1033
  *
1019
1034
  */
1020
- solve(vars: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
1035
+ solve(vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
1021
1036
  /**
1022
1037
  * Return a JavaScript primitive representing the value of this expression.
1023
1038
  *
@@ -1059,8 +1074,8 @@ export interface BoxedExpression {
1059
1074
  * :::
1060
1075
  *
1061
1076
  */
1062
- get type(): Type;
1063
- set type(type: Type);
1077
+ get type(): BoxedType;
1078
+ set type(type: Type | TypeString | BoxedType);
1064
1079
  /** `true` if the value of this expression is a number.
1065
1080
  *
1066
1081
  *
@@ -1219,6 +1234,9 @@ export interface BoxedBaseDefinition {
1219
1234
  * This field is usually undefined, but its value is set by `getDefinition()`
1220
1235
  */
1221
1236
  scope: RuntimeScope | undefined;
1237
+ /** If this is the definition of a collection, the set of primitive operations
1238
+ * that can be performed on this collection (counting the number of elements,
1239
+ * enumerating it, etc...). */
1222
1240
  collection?: Partial<CollectionHandlers>;
1223
1241
  /** When the environment changes, for example the numerical precision,
1224
1242
  * call `reset()` so that any cached values can be recalculated.
@@ -1329,7 +1347,14 @@ export type CollectionHandlers = {
1329
1347
  */
1330
1348
  export type FunctionDefinitionFlags = {
1331
1349
  /**
1332
- * If `true`, the arguments of the functions are held unevaluated.
1350
+ * If `true`, the arguments to this function are not automatically
1351
+ * evaluated. The default is `false` (the arguments are evaluated).
1352
+ *
1353
+ * This can be useful for example for functions that take symbolic
1354
+ * expressions as arguments, such as `D` or `Integrate`.
1355
+ *
1356
+ * This is also useful for functions that take an argument that is
1357
+ * potentially an infinite collection.
1333
1358
  *
1334
1359
  * It will be up to the `evaluate()` handler to evaluate the arguments as
1335
1360
  * needed. This is conveninent to pass symbolic expressions as arguments
@@ -1338,7 +1363,7 @@ export type FunctionDefinitionFlags = {
1338
1363
  * This also applies to the `canonical()` handler.
1339
1364
  *
1340
1365
  */
1341
- hold: boolean;
1366
+ lazy: boolean;
1342
1367
  /** If `true`, the function is applied element by element to lists, matrices
1343
1368
  * (`["List"]` or `["Tuple"]` expressions) and equations (relational
1344
1369
  * operators).
@@ -1413,12 +1438,29 @@ export type Hold = 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1413
1438
  */
1414
1439
  export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1415
1440
  complexity: number;
1416
- hold: boolean;
1441
+ /** If true, the signature was inferred from usage and may be modified
1442
+ * as more information becomes available.
1443
+ */
1417
1444
  inferredSignature: boolean;
1418
- signature: Type;
1445
+ /** The type of the arguments and return value of this function */
1446
+ signature: BoxedType;
1447
+ /** If present, this handler can be used to more precisely determine the
1448
+ * return type based on the type of the arguments. The arguments themselves
1449
+ * should *not* be evaluated, only their types should be used.
1450
+ */
1419
1451
  type?: (ops: ReadonlyArray<BoxedExpression>, options: {
1420
1452
  engine: IComputeEngine;
1421
- }) => Type | TypeString | undefined;
1453
+ }) => Type | TypeString | BoxedType | undefined;
1454
+ /** If present, this handler can be used to determine the sign of the
1455
+ * return value of the function, based on the sign and type of its
1456
+ * arguments.
1457
+ *
1458
+ * The arguments themselves should *not* be evaluated, only their types and
1459
+ * sign should be used.
1460
+ *
1461
+ * This can be used in some case for example to determine when certain
1462
+ * simplifications are valid.
1463
+ */
1422
1464
  sgn?: (ops: ReadonlyArray<BoxedExpression>, options: {
1423
1465
  engine: IComputeEngine;
1424
1466
  }) => Sign | undefined;
@@ -1427,9 +1469,12 @@ export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFl
1427
1469
  canonical?: (ops: ReadonlyArray<BoxedExpression>, options: {
1428
1470
  engine: IComputeEngine;
1429
1471
  }) => BoxedExpression | null;
1430
- evaluate?: (ops: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
1431
- engine: IComputeEngine;
1472
+ evaluate?: (ops: ReadonlyArray<BoxedExpression>, options: Partial<EvaluateOptions> & {
1473
+ engine?: IComputeEngine;
1432
1474
  }) => BoxedExpression | undefined;
1475
+ evaluateAsync?: (ops: ReadonlyArray<BoxedExpression>, options?: Partial<EvaluateOptions> & {
1476
+ engine?: IComputeEngine;
1477
+ }) => Promise<BoxedExpression | undefined>;
1433
1478
  evalDimension?: (ops: ReadonlyArray<BoxedExpression>, options: {
1434
1479
  engine: IComputeEngine;
1435
1480
  }) => BoxedExpression;
@@ -1499,7 +1544,7 @@ export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttrib
1499
1544
  neq?: (a: BoxedExpression) => boolean | undefined;
1500
1545
  cmp?: (a: BoxedExpression) => '=' | '>' | '<' | undefined;
1501
1546
  inferredType: boolean;
1502
- type: Type;
1547
+ type: BoxedType;
1503
1548
  }
1504
1549
  /**
1505
1550
  * Given an expression and set of wildcards, return a new expression.
@@ -1658,7 +1703,8 @@ export type SimplifyOptions = {
1658
1703
  * @category Boxed Expression
1659
1704
  */
1660
1705
  export type EvaluateOptions = {
1661
- numericApproximation?: boolean;
1706
+ numericApproximation: boolean;
1707
+ signal: AbortSignal;
1662
1708
  };
1663
1709
  /**
1664
1710
  * Metadata that can be associated with a `BoxedExpression`
@@ -1686,7 +1732,7 @@ export type ArrayValue = boolean | number | string | BigNum | BoxedExpression |
1686
1732
  /** @category Assumptions */
1687
1733
  export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1688
1734
  /** @category Compute Engine */
1689
- export type AssignValue = boolean | number | string | LatexString | SemiBoxedExpression | ((args: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
1735
+ export type AssignValue = boolean | number | SemiBoxedExpression | ((args: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
1690
1736
  engine: IComputeEngine;
1691
1737
  }) => BoxedExpression) | undefined;
1692
1738
  /** @internal */
@@ -1728,14 +1774,30 @@ export interface IComputeEngine extends IBigNum {
1728
1774
  /** Absolute time beyond which evaluation should not proceed
1729
1775
  * @internal
1730
1776
  */
1731
- deadline?: number;
1777
+ _deadline?: number;
1778
+ /** Time remaining before _deadline */
1779
+ _timeRemaining: number;
1780
+ /** @private */
1732
1781
  generation: number;
1733
- /** @hidden */
1734
- readonly timeLimit: number;
1735
- /** @hidden */
1736
- readonly iterationLimit: number;
1737
- /** @hidden */
1738
- readonly recursionLimit: number;
1782
+ /** Throw a `CancellationError` when the duration of an evaluation exceeds
1783
+ * the time limit.
1784
+ *
1785
+ * Time in milliseconds, default 2000 ms = 2 seconds.
1786
+ *
1787
+ */
1788
+ timeLimit: number;
1789
+ /** Throw `CancellationError` `iteration-limit-exceeded` when the iteration limit
1790
+ * in a loop is exceeded. Default: no limits.
1791
+ *
1792
+ * @experimental
1793
+ */
1794
+ iterationLimit: number;
1795
+ /** Signal `recursion-depth-exceeded` when the recursion depth for this
1796
+ * scope is exceeded.
1797
+ *
1798
+ * @experimental
1799
+ */
1800
+ recursionLimit: number;
1739
1801
  chop(n: number): number;
1740
1802
  chop(n: BigNum): BigNum | 0;
1741
1803
  chop(n: number | BigNum): number | BigNum;
@@ -1776,10 +1838,11 @@ export interface IComputeEngine extends IBigNum {
1776
1838
  }): BoxedExpression;
1777
1839
  string(s: string, metadata?: Metadata): BoxedExpression;
1778
1840
  error(message: string | string[], where?: string): BoxedExpression;
1779
- typeError(expectedType: Type, actualType: undefined | Type, where?: SemiBoxedExpression): BoxedExpression;
1841
+ typeError(expectedType: Type, actualType: undefined | Type | BoxedType, where?: SemiBoxedExpression): BoxedExpression;
1780
1842
  hold(expr: SemiBoxedExpression): BoxedExpression;
1781
1843
  tuple(...elements: ReadonlyArray<number>): BoxedExpression;
1782
1844
  tuple(...elements: ReadonlyArray<BoxedExpression>): BoxedExpression;
1845
+ type(type: Type | TypeString | BoxedType): BoxedType;
1783
1846
  rules(rules: Rule | ReadonlyArray<Rule | BoxedRule> | BoxedRuleSet | undefined | null, options?: {
1784
1847
  canonical?: boolean;
1785
1848
  }): BoxedRuleSet;
@@ -1927,11 +1990,11 @@ export type LatexString = string;
1927
1990
  * value.
1928
1991
  * - `recursive`: if true, match recursively, otherwise match only the top
1929
1992
  * level.
1930
- * - `exact`: if true, only match expressions that are structurally identical.
1931
- * If false, match expressions that are structurally identical or equivalent.
1993
+ * - `useVariations`: if false, only match expressions that are structurally identical.
1994
+ * If true, match expressions that are structurally identical or equivalent.
1932
1995
  *
1933
- * For example, when false, `["Add", '_a', 2]` matches `2`, with a value of
1934
- * `_a` of `0`. If true, the expression does not match. **Default**: `true`
1996
+ * For example, when true, `["Add", '_a', 2]` matches `2`, with a value of
1997
+ * `_a` of `0`. If false, the expression does not match. **Default**: `false`
1935
1998
  *
1936
1999
  * @category Pattern Matching
1937
2000
  *
@@ -2040,34 +2103,7 @@ export type RuntimeIdentifierDefinitions = Map<string, OneOf<[BoxedSymbolDefinit
2040
2103
  *
2041
2104
  * @category Compute Engine
2042
2105
  */
2043
- export type Scope = {
2044
- /** Signal `timeout` when the execution time for this scope is exceeded.
2045
- *
2046
- * Time in seconds, default 2s.
2047
- *
2048
- * @experimental
2049
- */
2050
- timeLimit: number;
2051
- /** Signal `out-of-memory` when the memory usage for this scope is exceeded.
2052
- *
2053
- * Memory is in Megabytes, default: 1Mb.
2054
- *
2055
- * @experimental
2056
- */
2057
- memoryLimit: number;
2058
- /** Signal `recursion-depth-exceeded` when the recursion depth for this
2059
- * scope is exceeded.
2060
- *
2061
- * @experimental
2062
- */
2063
- recursionLimit: number;
2064
- /** Signal `iteration-limit-exceeded` when the iteration limit
2065
- * in a loop is exceeded. Default: no limits.
2066
- *
2067
- * @experimental
2068
- */
2069
- iterationLimit: number;
2070
- };
2106
+ export type Scope = {};
2071
2107
  /** @category Compute Engine */
2072
2108
  export type RuntimeScope = Scope & {
2073
2109
  parentScope?: RuntimeScope;
@@ -2123,7 +2159,7 @@ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlag
2123
2159
  */
2124
2160
  type?: (ops: ReadonlyArray<BoxedExpression>, options: {
2125
2161
  engine: IComputeEngine;
2126
- }) => Type;
2162
+ }) => Type | TypeString | BoxedType | undefined;
2127
2163
  /** Return the sign of the function expression.
2128
2164
  *
2129
2165
  * If the sign cannot be determined, return `undefined`.
@@ -2231,6 +2267,13 @@ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlag
2231
2267
  evaluate?: ((ops: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
2232
2268
  engine: IComputeEngine;
2233
2269
  }) => BoxedExpression | undefined) | BoxedExpression;
2270
+ /**
2271
+ * An option asynchronous version of `evaluate`.
2272
+ *
2273
+ */
2274
+ evaluateAsync?: (ops: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
2275
+ engine: IComputeEngine;
2276
+ }) => Promise<BoxedExpression | undefined>;
2234
2277
  /** Dimensional analysis
2235
2278
  * @experimental
2236
2279
  */
@@ -2239,6 +2282,8 @@ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlag
2239
2282
  }) => BoxedExpression;
2240
2283
  /** Return a compiled (optimized) expression. */
2241
2284
  compile?: (expr: BoxedExpression) => CompiledExpression;
2285
+ eq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
2286
+ neq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
2242
2287
  collection?: Partial<CollectionHandlers>;
2243
2288
  };
2244
2289
  /**
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare const ConditionParent: {
3
3
  boolean: string;
4
4
  string: string;
@@ -1,3 +1,3 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { BoxedExpression, IComputeEngine, JsonSerializationOptions } from '../public';
3
3
  export declare function serializeJson(ce: IComputeEngine, expr: BoxedExpression, options: Readonly<JsonSerializationOptions>): Expression;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare function sgn(expr: BoxedExpression): Sign | undefined;
3
3
  export declare function positiveSign(s: Sign | undefined): boolean | undefined;
4
4
  export declare function nonNegativeSign(s: Sign | undefined): boolean | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  type InternalSimplifyOptions = SimplifyOptions & {
3
3
  useVariations: boolean;
4
4
  };
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import { Rule } from '../public';
3
3
  export declare const UNIVARIATE_ROOTS: Rule[];
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { BoxedExpression, IComputeEngine } from '../public';
3
3
  export type DataTypeMap = {
4
4
  float64: number;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare class Terms {
3
3
  private engine;
4
4
  private terms;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  export declare function Fu(exp: BoxedExpression): RuleStep | undefined;
3
3
  /** Assuming x in an expression in radians, convert to current angular unit. */
4
4
  export declare function radiansToAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
@@ -7,4 +7,10 @@ export declare function processInverseFunction(ce: IComputeEngine, xs: ReadonlyA
7
7
  export declare function trigSign(operator: string, x: BoxedExpression): Sign | undefined;
8
8
  export declare function isConstructible(x: string | BoxedExpression): boolean;
9
9
  export declare function constructibleValues(operator: string, x: BoxedExpression | undefined): undefined | BoxedExpression;
10
+ /**
11
+ * Return the angle in the range [0, 2π) that is equivalent to the given angle.
12
+ *
13
+ * @param x
14
+ * @returns
15
+ */
10
16
  export declare function canonicalAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import { Type } from '../../common/type/types';
3
3
  export declare function isBoxedExpression(x: unknown): x is BoxedExpression;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { IComputeEngine } from '../public';
3
3
  import { Type } from '../../common/type/types';
4
4
  /**
@@ -28,7 +28,7 @@ export declare function checkNumericArgs(ce: IComputeEngine, ops: ReadonlyArray<
28
28
  flatten?: string;
29
29
  }): ReadonlyArray<BoxedExpression>;
30
30
  /**
31
- * Check that an argument is of the expected domain.
31
+ * Check that an argument is of the expected type.
32
32
  *
33
33
  * Converts the arguments to canonical
34
34
  */
@@ -46,4 +46,4 @@ export declare function checkPure(ce: IComputeEngine, arg: BoxedExpression | Box
46
46
  * arguments.
47
47
  *
48
48
  */
49
- export declare function validateArguments(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>, def: BoxedFunctionDefinition): ReadonlyArray<BoxedExpression> | null;
49
+ export declare function validateArguments(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>, signature: Type, lazy?: boolean, threadable?: boolean): ReadonlyArray<BoxedExpression> | null;
@@ -1,4 +1,4 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  /** If a collection has fewer than this many elements, eagerly evaluate it.
3
3
  *
4
4
  * For example, evaluate the Union of two sets with 10 elements each will
@@ -58,6 +58,7 @@ export declare function length(col: BoxedExpression): number | undefined;
58
58
  *
59
59
  */
60
60
  export declare function iterator(expr: BoxedExpression): Iterator<BoxedExpression> | undefined;
61
+ export declare function repeat(value: BoxedExpression, count?: number): Iterator<BoxedExpression>;
61
62
  /**
62
63
  *
63
64
  * @param expr
@@ -66,3 +67,4 @@ export declare function iterator(expr: BoxedExpression): Iterator<BoxedExpressio
66
67
  */
67
68
  export declare function at(expr: BoxedExpression, index: number): BoxedExpression | undefined;
68
69
  export declare function defaultCollectionHandlers(def: undefined | Partial<CollectionHandlers>): Partial<CollectionHandlers> | undefined;
70
+ export declare function zip(items: ReadonlyArray<BoxedExpression>): Iterator<BoxedExpression[]>;
@@ -1,30 +1,31 @@
1
- /* 0.26.4 */
1
+ /* 0.28.0 */
2
2
  import type { BoxedExpression } from './public';
3
3
  export type CompiledType = boolean | number | string | object;
4
- type JSSource = string;
4
+ export type JSSource = string;
5
5
  export type CompiledOperators = Record<MathJsonIdentifier, [
6
6
  op: string,
7
7
  prec: number
8
8
  ]>;
9
+ export type CompiledFunction = string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
9
10
  export type CompiledFunctions = {
10
- [id: MathJsonIdentifier]: string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
11
+ [id: MathJsonIdentifier]: CompiledFunction;
11
12
  };
12
13
  export type CompileTarget = {
13
14
  operators?: (op: MathJsonIdentifier) => [op: string, prec: number];
14
- functions?: (id: MathJsonIdentifier) => string | ((...args: CompiledType[]) => string);
15
+ functions?: (id: MathJsonIdentifier) => CompiledFunction | undefined;
15
16
  var: (id: MathJsonIdentifier) => string | undefined;
16
17
  string: (str: string) => string;
17
18
  number: (n: number) => string;
18
19
  ws: (s?: string) => string;
20
+ preamble: string;
19
21
  indent: number;
20
22
  };
21
23
  /** This is an extension of the Function class that allows us to pass
22
24
  * a custom scope for "global" functions. */
23
25
  export declare class ComputeEngineFunction extends Function {
24
26
  private sys;
25
- constructor(body: string);
27
+ constructor(body: string, preamble?: string);
26
28
  }
27
- export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
28
- export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
29
+ export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): (_?: Record<string, CompiledType>) => CompiledType;
30
+ export declare function compileToJavascript(expr: BoxedExpression, functions?: Record<MathJsonIdentifier, JSSource | Function>, vars?: Record<MathJsonIdentifier, JSSource>, imports?: unknown[], preamble?: string): (_?: Record<string, CompiledType>) => CompiledType;
29
31
  export declare function compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): JSSource;
30
- export {};