@cortex-js/compute-engine 0.25.1 → 0.26.2

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 (153) hide show
  1. package/README.md +5 -8
  2. package/dist/compute-engine.esm.js +26338 -22472
  3. package/dist/compute-engine.js +26348 -22470
  4. package/dist/compute-engine.min.esm.js +89 -23
  5. package/dist/compute-engine.min.js +89 -23
  6. package/dist/math-json.esm.js +22 -139
  7. package/dist/math-json.js +22 -139
  8. package/dist/math-json.min.esm.js +22 -139
  9. package/dist/math-json.min.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +30 -4
  11. package/dist/types/common/buffer.d.ts +9 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/one-of.d.ts +9 -0
  14. package/dist/types/common/signals.d.ts +1 -1
  15. package/dist/types/common/styled-text.d.ts +28 -0
  16. package/dist/types/common/suggest.d.ts +1 -0
  17. package/dist/types/common/syntax-highlighter.d.ts +40 -0
  18. package/dist/types/common/terminal.d.ts +19 -0
  19. package/dist/types/common/type/parse.d.ts +4 -0
  20. package/dist/types/common/type/primitive.d.ts +8 -0
  21. package/dist/types/common/type/serialize.d.ts +2 -0
  22. package/dist/types/common/type/subtype.d.ts +6 -0
  23. package/dist/types/common/type/types.d.ts +249 -0
  24. package/dist/types/common/type/utils.d.ts +39 -0
  25. package/dist/types/common/utils.d.ts +2 -1
  26. package/dist/types/compute-engine/assume.d.ts +13 -13
  27. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
  28. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
  33. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  34. package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
  35. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
  36. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
  37. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +42 -37
  38. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  39. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
  41. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
  42. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
  43. package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
  44. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  46. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  47. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
  49. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  50. package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
  51. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
  52. package/dist/types/compute-engine/{symbolic → boxed-expression}/negate.d.ts +4 -4
  53. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
  54. package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
  55. package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
  56. package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
  57. package/dist/types/compute-engine/boxed-expression/public.d.ts +911 -634
  58. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  59. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  60. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
  61. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  62. package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
  63. package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
  64. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  65. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
  67. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
  68. package/dist/types/compute-engine/collection-utils.d.ts +24 -2
  69. package/dist/types/compute-engine/compile.d.ts +3 -3
  70. package/dist/types/compute-engine/compute-engine.d.ts +132 -165
  71. package/dist/types/compute-engine/cost-function.d.ts +11 -1
  72. package/dist/types/compute-engine/function-utils.d.ts +5 -5
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  88. package/dist/types/compute-engine/latex-syntax/parse.d.ts +26 -31
  89. package/dist/types/compute-engine/latex-syntax/public.d.ts +24 -18
  90. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  91. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
  93. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  94. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
  95. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  96. package/dist/types/compute-engine/library/collections.d.ts +24 -1
  97. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  98. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  99. package/dist/types/compute-engine/library/core.d.ts +1 -3
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  101. package/dist/types/compute-engine/library/library.d.ts +2 -4
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  103. package/dist/types/compute-engine/library/logic.d.ts +5 -1
  104. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  105. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  106. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  107. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  108. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  109. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  110. package/dist/types/compute-engine/library/utils.d.ts +46 -40
  111. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
  112. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
  113. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
  114. package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
  115. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  116. package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
  117. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  118. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
  124. package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  128. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  129. package/dist/types/compute-engine/public.d.ts +8 -4
  130. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
  131. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  132. package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
  133. package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
  134. package/dist/types/compute-engine.d.ts +4 -2
  135. package/dist/types/math-json/identifiers.d.ts +11 -0
  136. package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
  137. package/dist/types/math-json/utils.d.ts +15 -23
  138. package/dist/types/math-json.d.ts +3 -3
  139. package/package.json +3 -3
  140. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
  141. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
  142. package/dist/types/compute-engine/boxed-expression/coefficient-field.d.ts +0 -56
  143. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  144. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  145. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -16
  146. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  147. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  148. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  149. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  150. package/dist/types/compute-engine/rules.d.ts +0 -20
  151. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  152. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  153. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -1,12 +1,16 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { Decimal } from 'decimal.js';
3
- import { MathJsonIdentifier, MathJsonNumber } from '../math-json/math-json-format';
3
+ import { Expression, MathJsonIdentifier, MathJsonNumber } from '../math-json/types';
4
4
  import type { LibraryCategory, LatexDictionaryEntry, LatexString, ParseLatexOptions } from './latex-syntax/public';
5
- import { AssumeResult, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, RuntimeScope, Scope, SymbolDefinition, BoxedRuleSet, Rule, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, BoxedSubstitution, AssignValue, DomainLiteral, ArrayValue, AngularUnit, CanonicalOptions } from './public';
5
+ import { AssumeResult, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, RuntimeScope, Scope, SymbolDefinition, BoxedRuleSet, Rule, ComputeEngineStats, Metadata, FunctionDefinition, BoxedSubstitution, AssignValue, AngularUnit, CanonicalOptions } from './public';
6
6
  import { Rational } from './numerics/rationals';
7
- import { IndexedLatexDictionary } from './latex-syntax/dictionary/definitions';
8
- import { BoxedExpression, SemiBoxedExpression } from './boxed-expression/public';
7
+ import { type IndexedLatexDictionary } from './latex-syntax/dictionary/definitions';
8
+ import { BoxedExpression, BoxedRule, EvaluateOptions, SemiBoxedExpression } from './boxed-expression/public';
9
9
  import './boxed-expression/serialize';
10
+ import { ExactNumericValueData, NumericValue, NumericValueData } from './numeric-value/public';
11
+ import { Type, TypeString } from '../common/type/types';
12
+ import { OneOf } from '../common/one-of';
13
+ import { BigNum } from './numerics/bignum';
10
14
  /**
11
15
  *
12
16
  * To use the Compute Engine, create a `ComputeEngine` instance:
@@ -40,11 +44,6 @@ import './boxed-expression/serialize';
40
44
  *
41
45
  */
42
46
  export declare class ComputeEngine implements IComputeEngine {
43
- readonly Anything: BoxedDomain;
44
- readonly Void: BoxedDomain;
45
- readonly Strings: BoxedDomain;
46
- readonly Booleans: BoxedDomain;
47
- readonly Numbers: BoxedDomain;
48
47
  readonly True: BoxedExpression;
49
48
  readonly False: BoxedExpression;
50
49
  readonly Pi: BoxedExpression;
@@ -54,13 +53,14 @@ export declare class ComputeEngine implements IComputeEngine {
54
53
  readonly One: BoxedExpression;
55
54
  readonly Half: BoxedExpression;
56
55
  readonly NegativeOne: BoxedExpression;
56
+ readonly Two: BoxedExpression;
57
57
  readonly I: BoxedExpression;
58
58
  readonly NaN: BoxedExpression;
59
59
  readonly PositiveInfinity: BoxedExpression;
60
60
  readonly NegativeInfinity: BoxedExpression;
61
61
  readonly ComplexInfinity: BoxedExpression;
62
62
  /** The symbol separating the whole part of a number from its fractional
63
- * part.
63
+ * part in a LaTeX string.
64
64
  *
65
65
  * Commonly a period (`.`) in English, but a comma (`,`) in many European
66
66
  * languages. For the comma, use `"{,}"` so that the spacing is correct.
@@ -86,14 +86,13 @@ export declare class ComputeEngine implements IComputeEngine {
86
86
  _BIGNUM_NEGATIVE_ONE: Decimal;
87
87
  /** @internal */
88
88
  private _precision;
89
- /** @internal */
90
- private _numericMode;
91
89
  /** @ internal */
92
90
  private _angularUnit;
93
91
  /** @internal */
94
92
  private _tolerance;
95
93
  /** @internal */
96
94
  private _bignumTolerance;
95
+ private _negBignumTolerance;
97
96
  /** @internal */
98
97
  private _cache;
99
98
  /** @internal */
@@ -104,8 +103,6 @@ export declare class ComputeEngine implements IComputeEngine {
104
103
  private _commonSymbols;
105
104
  /** @internal */
106
105
  private _commonNumbers;
107
- /** @internal */
108
- private _commonDomains;
109
106
  /**
110
107
  * The current scope.
111
108
  *
@@ -118,6 +115,14 @@ export declare class ComputeEngine implements IComputeEngine {
118
115
  *
119
116
  */
120
117
  context: RuntimeScope | null;
118
+ /**
119
+ * Generation.
120
+ *
121
+ * The generation is incremented each time the context changes.
122
+ * It is used to invalidate caches.
123
+ * @internal
124
+ */
125
+ generation: number;
121
126
  /** In strict mode (the default) the Compute Engine performs
122
127
  * validation of domains and signature and may report errors.
123
128
  *
@@ -141,11 +146,45 @@ export declare class ComputeEngine implements IComputeEngine {
141
146
  * manipulate them.
142
147
  *
143
148
  */
144
- /** @private */
149
+ /** @internal */
145
150
  private _latexDictionaryInput;
146
- /** @private */
151
+ /** @internal */
147
152
  _indexedLatexDictionary: IndexedLatexDictionary;
153
+ /** @internal */
154
+ _bignum: Decimal.Constructor;
148
155
  static getStandardLibrary(categories?: LibraryCategory[] | LibraryCategory | 'all'): readonly IdentifierDefinitions[];
156
+ /**
157
+ * Return a LaTeX dictionary suitable for the specified category, or `"all"`
158
+ * for all categories (`"arithmetic"`, `"algebra"`, etc...).
159
+ *
160
+ * A LaTeX dictionary is needed to translate between LaTeX and MathJSON.
161
+ *
162
+ * Each entry in the dictionary indicate how a LaTeX token (or string of
163
+ * tokens) should be parsed into a MathJSON expression.
164
+ *
165
+ * For example an entry can define that the `\pi` LaTeX token should map to the
166
+ * symbol `"Pi"`, or that the token `-` should map to the function
167
+ * `["Negate",...]` when in a prefix position and to the function
168
+ * `["Subtract", ...]` when in an infix position.
169
+ *
170
+ * Furthermore, the information in each dictionary entry is used to serialize
171
+ * the LaTeX string corresponding to a MathJSON expression.
172
+ *
173
+ * Use with `ce.latexDictionary` to set the dictionary. You can complement
174
+ * it with your own definitions, for example with:
175
+ *
176
+ * ```ts
177
+ * ce.latexDictionary = [
178
+ * ...ce.getLatexDictionary("all"),
179
+ * {
180
+ * kind: "function",
181
+ * identifierTrigger: "concat",
182
+ * parse: "Concatenate"
183
+ * }
184
+ * ];
185
+ * ```
186
+ */
187
+ static getLatexDictionary(domain?: LibraryCategory | 'all'): readonly Readonly<LatexDictionaryEntry>[];
149
188
  /**
150
189
  * Construct a new `ComputeEngine` instance.
151
190
  *
@@ -160,13 +199,9 @@ export declare class ComputeEngine implements IComputeEngine {
160
199
  * as domains (`Booleans`, `Numbers`, etc...) that are used by later
161
200
  * dictionaries.
162
201
  *
163
- * @param options.numericMode The default mode is `"auto"`. Use `"machine"`
164
- * to perform numeric calculations using 64-bit floats. Use `"bignum"` to
165
- * perform calculations using arbitrary precision floating point numbers.
166
- * Use `"auto"` or `"complex"` to allow calculations on complex numbers.
167
202
  *
168
- * @param options.numericPrecision Specific how many digits of precision
169
- * for the numeric calculations. Default is 100.
203
+ * @param options.precision Specific how many digits of precision
204
+ * for the numeric calculations. Default is 300.
170
205
  *
171
206
  * @param options.tolerance If the absolute value of the difference of two
172
207
  * numbers is less than `tolerance`, they are considered equal. Used by
@@ -174,9 +209,8 @@ export declare class ComputeEngine implements IComputeEngine {
174
209
  */
175
210
  constructor(options?: {
176
211
  ids?: readonly IdentifierDefinitions[];
177
- numericMode?: NumericMode;
178
- numericPrecision?: number;
179
- tolerance?: number;
212
+ precision?: number | 'machine';
213
+ tolerance?: number | 'auto';
180
214
  });
181
215
  get latexDictionary(): Readonly<LatexDictionaryEntry[]>;
182
216
  set latexDictionary(dic: Readonly<LatexDictionaryEntry[]>);
@@ -195,8 +229,6 @@ export declare class ComputeEngine implements IComputeEngine {
195
229
  _unregister(_expr: BoxedExpression): void;
196
230
  /** @internal */
197
231
  get stats(): ComputeEngineStats;
198
- /** @internal */
199
- _bignum: Decimal.Constructor;
200
232
  get precision(): number;
201
233
  /** The precision, or number of significant digits, of numeric
202
234
  * calculations when the numeric mode is `"auto"` or `"bignum"`.
@@ -209,12 +241,10 @@ export declare class ComputeEngine implements IComputeEngine {
209
241
  * Trigonometric operations are accurate for precision up to 1,000.
210
242
  *
211
243
  */
212
- set precision(p: number | 'machine');
213
- get numericMode(): NumericMode;
214
- /** {@inheritDoc NumericMode} */
215
- set numericMode(f: NumericMode);
244
+ set precision(p: number | 'machine' | 'auto');
216
245
  /**
217
246
  * The unit used for angles in trigonometric functions.
247
+ *
218
248
  * Default is `"rad"` (radians).
219
249
  */
220
250
  get angularUnit(): AngularUnit;
@@ -231,7 +261,7 @@ export declare class ComputeEngine implements IComputeEngine {
231
261
  * purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
232
262
  * equal to `a`.
233
263
  */
234
- set tolerance(val: number);
264
+ set tolerance(val: number | 'auto');
235
265
  /** Replace a number that is close to 0 with the exact integer 0.
236
266
  *
237
267
  * How close to 0 the number has to be to be considered 0 is determined by {@linkcode tolerance}.
@@ -336,40 +366,13 @@ export declare class ComputeEngine implements IComputeEngine {
336
366
  * - `sign()` (1, 0 or -1)
337
367
  */
338
368
  complex(a: number | Decimal | Complex, b?: number | Decimal): Complex;
339
- isBignum(a: unknown): a is Decimal;
340
- isComplex(a: unknown): a is Complex;
341
369
  /**
342
- * Return a LaTeX dictionary suitable for the specified category, or `"all"`
343
- * for all categories (`"arithmetic"`, `"algebra"`, etc...).
344
370
  *
345
- * A LaTeX dictionary is needed to translate between LaTeX and MathJSON.
371
+ * Create a Numeric Value.
346
372
  *
347
- * Each entry in the dictionary indicate how a LaTeX token (or string of
348
- * tokens) should be parsed into a MathJSON expression.
349
- *
350
- * For example an entry can define that the `\pi` LaTeX token should map to the
351
- * symbol `"Pi"`, or that the token `-` should map to the function
352
- * `["Negate",...]` when in a prefix position and to the function
353
- * `["Subtract", ...]` when in an infix position.
354
- *
355
- * Furthermore, the information in each dictionary entry is used to serialize
356
- * the LaTeX string corresponding to a MathJSON expression.
357
- *
358
- * Use with `ce.latexDictionary` to set the dictionary. You can complement
359
- * it with your own definitions, for example with:
360
- *
361
- * ```ts
362
- * ce.latexDictionary = [
363
- * ...ce.getLatexDictionary("all"),
364
- * {
365
- * kind: "function",
366
- * identifierTrigger: "concat",
367
- * parse: "Concatenate"
368
- * }
369
- * ];
370
- * ```
373
+ * @internal
371
374
  */
372
- static getLatexDictionary(domain?: LibraryCategory | 'all'): readonly Readonly<LatexDictionaryEntry>[];
375
+ _numericValue(value: number | bigint | Complex | OneOf<[BigNum | NumericValueData | ExactNumericValueData]>): NumericValue;
373
376
  /**
374
377
  * The cost function is used to determine the "cost" of an expression. For example, when simplifying an expression, the simplification that results in the lowest cost is chosen.
375
378
  */
@@ -382,7 +385,7 @@ export declare class ComputeEngine implements IComputeEngine {
382
385
  */
383
386
  lookupSymbol(symbol: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
384
387
  /**
385
- * Return the definition for a function matching this head.
388
+ * Return the definition for a function with this operator name.
386
389
  *
387
390
  * Start looking in the current context, than up the scope chain.
388
391
  *
@@ -390,7 +393,7 @@ export declare class ComputeEngine implements IComputeEngine {
390
393
  * of the argument or the codomain. However, it is useful during parsing
391
394
  * to differentiate between symbols that might represent a function application, e.g. `f` vs `x`.
392
395
  */
393
- lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
396
+ lookupFunction(name: MathJsonIdentifier, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
394
397
  /**
395
398
  * Associate a new definition to a symbol in the current context.
396
399
  *
@@ -404,7 +407,7 @@ export declare class ComputeEngine implements IComputeEngine {
404
407
  defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
405
408
  _defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
406
409
  /**
407
- * Associate a new delookupSymbolfinition to a function in the current context.
410
+ * Associate a new FunctionDefinition to a function in the current context.
408
411
  *
409
412
  * If a definition existed previously, it is replaced.
410
413
  *
@@ -418,43 +421,45 @@ export declare class ComputeEngine implements IComputeEngine {
418
421
  *
419
422
  * Create a new scope and add it to the top of the scope stack
420
423
  *
421
- * The `scope` argument can be used to specify custom precision,
422
- * etc... for this scope
423
- *
424
- *
425
424
  */
426
- pushScope(scope?: Partial<Scope>): ComputeEngine;
425
+ pushScope(scope?: Partial<Scope>): IComputeEngine;
427
426
  /** Remove the most recent scope from the scope stack, and set its
428
- * parent scope as current. */
429
- popScope(): ComputeEngine;
427
+ * parent scope as the current scope. */
428
+ popScope(): IComputeEngine;
430
429
  /** Set the current scope, return the previous scope. */
431
430
  swapScope(scope: RuntimeScope | null): RuntimeScope | null;
432
- /**
433
- * Reset the value of any identifiers that have been assigned a value
434
- * in the current scope.
435
- * @internal */
436
- resetContext(): void;
437
431
  /** @internal */
438
432
  _printScope(options?: {
439
433
  details?: boolean;
440
434
  maxDepth?: number;
441
435
  }, scope?: RuntimeScope | null, depth?: number): RuntimeScope | null;
442
436
  /**
443
- * Declare an identifier: specify their domain, and other attributes,
437
+ * Reset the value of any identifiers that have been assigned a value
438
+ * in the current scope.
439
+ * @internal */
440
+ resetContext(): void;
441
+ /**
442
+ * Declare an identifier: specify their type and other attributes,
444
443
  * including optionally a value.
445
444
  *
446
- * Once the domain of an identifier has been declared, it cannot be changed.
447
- * The domain information is used to calculate the canonical form of
448
- * expressions and ensure they are valid. If the domain could be changed
445
+ * Once the type of an identifier has been declared, it cannot be changed.
446
+ * The type information is used to calculate the canonical form of
447
+ * expressions and ensure they are valid. If the type could be changed
449
448
  * after the fact, previously valid expressions could become invalid.
450
449
  *
451
- * Use the `Anyting` domain for a very generic domain.
450
+ * Set the type to `any` type for a very generic type, or use `unknown`
451
+ * if the type is not known yet. If `unknown`, the type will be inferred
452
+ * based on usage.
453
+ *
454
+ * An identifier can be redeclared with a different type, but only if
455
+ * the type of the identifier was inferred. If the domain was explicitly
456
+ * set, the identifier cannot be redeclared.
452
457
  *
453
458
  */
454
- declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): ComputeEngine;
459
+ declare(id: string, def: TypeString | OneOf<[Type, SymbolDefinition, FunctionDefinition]>): IComputeEngine;
455
460
  declare(identifiers: {
456
- [id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
457
- }): ComputeEngine;
461
+ [id: string]: Type | TypeString | OneOf<[SymbolDefinition, FunctionDefinition]>;
462
+ }): IComputeEngine;
458
463
  /** Assign a value to an identifier in the current scope.
459
464
  * Use `undefined` to reset the identifier to no value.
460
465
  *
@@ -464,16 +469,17 @@ export declare class ComputeEngine implements IComputeEngine {
464
469
  * The identifier can take the form "f(x, y") to create a function
465
470
  * with two parameters, "x" and "y".
466
471
  *
467
- * If the id was not previously declared, an automatic declaration
468
- * is done. The domain of the identifier is inferred from the value.
469
- * To more precisely define the domain of the identifier, use `ce.declare()`
470
- * instead, which allows you to specify the domain, value and other
472
+ * If the id was not previously declared, assigning a value will declare it.
473
+ * Its type is inferred from the value.
474
+ *
475
+ * To more precisely define the type of the identifier, use `ce.declare()`
476
+ * instead, which allows you to specify the type, value and other
471
477
  * attributes of the identifier.
472
478
  */
473
- assign(id: string, value: AssignValue): ComputeEngine;
479
+ assign(id: string, value: AssignValue): IComputeEngine;
474
480
  assign(ids: {
475
481
  [id: string]: AssignValue;
476
- }): ComputeEngine;
482
+ }): IComputeEngine;
477
483
  /**
478
484
  * Same as assign(), but for internal use:
479
485
  * - skips validity checks
@@ -482,8 +488,9 @@ export declare class ComputeEngine implements IComputeEngine {
482
488
  *
483
489
  * @internal
484
490
  */
485
- _assign(id: string, value: AssignValue): ComputeEngine;
486
- get assumptions(): ExpressionMapInterface<boolean>;
491
+ _assign(id: string, value: BoxedExpression | ((ops: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
492
+ engine: IComputeEngine;
493
+ }) => BoxedExpression | undefined)): void;
487
494
  /**
488
495
  * Return false if the execution should stop.
489
496
  *
@@ -497,16 +504,18 @@ export declare class ComputeEngine implements IComputeEngine {
497
504
  /** @internal */
498
505
  checkContinueExecution(): void;
499
506
  /** @internal */
500
- cache<T>(cacheName: string, build: () => T, purge?: (T: any) => T | undefined): T;
507
+ cache<T>(cacheName: string, build: () => T, purge?: (t: T) => T | undefined): T;
501
508
  /** Return a boxed expression from a number, string or semiboxed expression.
502
509
  * Calls `ce.function()`, `ce.number()` or `ce.symbol()` as appropriate.
503
510
  */
504
- box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
511
+ box(expr: NumericValue | SemiBoxedExpression, options?: {
505
512
  canonical?: CanonicalOptions;
513
+ structural?: boolean;
506
514
  }): BoxedExpression;
507
- function(head: string, ops: SemiBoxedExpression[], options?: {
515
+ function(name: string, ops: ReadonlyArray<BoxedExpression> | ReadonlyArray<Expression>, options?: {
508
516
  metadata?: Metadata;
509
- canonical?: CanonicalOptions;
517
+ canonical: CanonicalOptions;
518
+ structural: boolean;
510
519
  }): BoxedExpression;
511
520
  /**
512
521
  *
@@ -514,94 +523,51 @@ export declare class ComputeEngine implements IComputeEngine {
514
523
  *
515
524
  * The result is canonical.
516
525
  */
517
- error(message: MathJsonIdentifier | [MathJsonIdentifier, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
518
- domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
526
+ error(message: string | string[], where?: string): BoxedExpression;
527
+ typeError(expected: Type, actual: undefined | Type, where?: string): BoxedExpression;
519
528
  /**
520
529
  * Add a`["Hold"]` wrapper to `expr.
521
530
  */
522
- hold(expr: SemiBoxedExpression): BoxedExpression;
523
- /**
524
- * Shortcut for `this.box(["Add", ...]).evaluate()`.
525
- *
526
- */
527
- add(...ops: BoxedExpression[]): BoxedExpression;
528
- /**
529
- *
530
- * Shortcut for `this.box(["Negate", expr]).evaluate()`
531
- *
532
- */
533
- neg(expr: BoxedExpression): BoxedExpression;
534
- /**
535
- *
536
- * Shortcut for `this.box(["Multiply", ...]).evaluate()`
537
- *
538
- */
539
- mul(...ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
540
- /**
541
- *
542
- * Shortcut for `this.box(["Divide", num, denom]).evaluate()`
543
- *
544
- * The result is canonical.
545
- */
546
- div(num: BoxedExpression, denom: BoxedExpression): BoxedExpression;
547
- /**
548
- *
549
- * Shortcut for `this.box(["Sqrt", base]).evaluate()`
550
- *
551
- */
552
- sqrt(base: BoxedExpression): BoxedExpression;
553
- /**
554
- *
555
- * Shortcut for `this.box(["Power", base, exponent]).evaluate()`
556
- *
557
- */
558
- pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression): BoxedExpression;
559
- /**
560
- *
561
- * Shortcut for `this.box(["Divide", 1, expr]).evaluate()`
562
- *
563
- */
564
- inv(expr: BoxedExpression): BoxedExpression;
565
- /** Shortcut for `this.box(["Pair", ...])`
566
- *
567
- * The result is canonical.
568
- */
569
- pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
531
+ hold(expr: BoxedExpression): BoxedExpression;
570
532
  /** Shortcut for `this.box(["Tuple", ...])`
571
533
  *
572
534
  * The result is canonical.
573
535
  */
574
- tuple(elements: number[], metadata?: Metadata): BoxedExpression;
575
- tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
576
- array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
536
+ tuple(...elements: ReadonlyArray<number>): BoxedExpression;
537
+ tuple(...elements: ReadonlyArray<BoxedExpression>): BoxedExpression;
577
538
  string(s: string, metadata?: Metadata): BoxedExpression;
578
539
  /** Return a boxed symbol */
579
540
  symbol(name: string, options?: {
580
541
  metadata?: Metadata;
581
542
  canonical?: CanonicalOptions;
582
543
  }): BoxedExpression;
583
- /** Return a canonical boxed domain.
584
- *
585
- * If the domain is invalid, may return an `["Error"]` expression
586
- *
587
- */
588
- domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
589
544
  /**
590
545
  * This function tries to avoid creating a boxed number if `num` corresponds
591
546
  * to a common value for which we have a shared instance (-1, 0, NaN, etc...)
592
547
  */
593
- number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
594
- metadata?: Metadata;
595
- canonical?: CanonicalOptions;
548
+ number(value: number | bigint | string | NumericValue | MathJsonNumber | Decimal | Complex | Rational, options?: {
549
+ metadata: Metadata;
550
+ canonical: CanonicalOptions;
596
551
  }): BoxedExpression;
597
- rules(rules: Rule[]): BoxedRuleSet;
552
+ rules(rules: Rule | ReadonlyArray<Rule | BoxedRule> | BoxedRuleSet | undefined | null, options?: {
553
+ canonical?: boolean;
554
+ }): BoxedRuleSet;
598
555
  getRuleSet(id?: string): BoxedRuleSet | undefined;
599
556
  /**
600
557
  * Return a function expression, but the caller is responsible for making
601
558
  * sure that the arguments are canonical.
602
559
  *
560
+ * Unlike ce.function(), the operator of the result is the name argument.
561
+ * Calling this function directly is potentially unsafe, as it bypasses
562
+ * the canonicalization of the arguments.
563
+ *
564
+ * For example:
565
+ *
566
+ * - `ce._fn('Multiply', [1, 'x'])` returns `['Multiply', 1, 'x']` as a canonical expression, even though it doesn't follow the canonical form
567
+ * - `ce.function('Multiply', [1, 'x']` returns `'x'` which is the correct canonical form
568
+ *
603
569
  * @internal */
604
- _fn(head: string | BoxedExpression, ops: BoxedExpression[], options?: Metadata & {
570
+ _fn(name: MathJsonIdentifier, ops: ReadonlyArray<BoxedExpression>, options?: Metadata & {
605
571
  canonical?: boolean;
606
572
  }): BoxedExpression;
607
573
  /**
@@ -616,6 +582,7 @@ export declare class ComputeEngine implements IComputeEngine {
616
582
  parse(latex: LatexString, options?: Partial<ParseLatexOptions> & {
617
583
  canonical?: CanonicalOptions;
618
584
  }): BoxedExpression;
585
+ get assumptions(): ExpressionMapInterface<boolean>;
619
586
  /**
620
587
  * Return a list of all the assumptions that match a pattern.
621
588
  *
@@ -625,12 +592,12 @@ export declare class ComputeEngine implements IComputeEngine {
625
592
  * // -> [{'val': 0}]
626
593
  * ```
627
594
  */
628
- ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
595
+ ask(pattern: BoxedExpression): BoxedSubstitution[];
629
596
  /**
630
597
  * Answer a query based on the current assumptions.
631
598
  *
632
599
  */
633
- verify(_query: SemiBoxedExpression): boolean;
600
+ verify(_query: BoxedExpression): boolean;
634
601
  /**
635
602
  * Add an assumption.
636
603
  *
@@ -644,7 +611,7 @@ export declare class ComputeEngine implements IComputeEngine {
644
611
  *
645
612
  *
646
613
  */
647
- assume(predicate: SemiBoxedExpression): AssumeResult;
614
+ assume(predicate: BoxedExpression): AssumeResult;
648
615
  /** Remove all assumptions about one or more symbols */
649
616
  forget(symbol: undefined | string | string[]): void;
650
617
  }
@@ -1,3 +1,13 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
+ /**
3
+ * The default cost function, used to determine if a new expression is simpler
4
+ * than the old one.
5
+ *
6
+ * To change the cost function used by the engine, set the
7
+ * `ce.costFunction` property of the engine or pass a custom cost function
8
+ * to the `simplify` function.
9
+ *
10
+ */
2
11
  export declare function costFunction(expr: BoxedExpression): number;
12
+ export declare function leafCount(expr: BoxedExpression): number;
3
13
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  /***
3
3
  * ### THEORY OF OPERATIONS
4
4
  *
@@ -18,7 +18,7 @@
18
18
  * #### DURING BOXING (in makeLambda())
19
19
  *
20
20
  * During the boxing/canonicalization phase of a function
21
- * (`["Function"]` expression or head expression):
21
+ * (`["Function"]` expression or operator of expression):
22
22
  *
23
23
  * 1/ If not a `["Function"]` expression, the expression is rewritten
24
24
  * to a `["Function"]` expression with anonymous parameters
@@ -50,7 +50,6 @@ export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: B
50
50
  /**
51
51
  * Given an expression, rewrite it to a canonical Function form.
52
52
  *
53
- *
54
53
  * - explicit parameters (no change)
55
54
  * ["Function", ["Add, "x", 1], "x"]
56
55
  * -> ["Function", ["Add, "x", 1], "x"]
@@ -63,8 +62,9 @@ export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: B
63
62
  * ["Add", "_1", "_2"]
64
63
  * -> ["Function", ["Add", "_1", "_2"], "_1", "_2"]
65
64
  *
65
+ *
66
66
  */
67
- export declare function canonicalFunctionExpression(expr: BoxedExpression): BoxedExpression | undefined;
67
+ export declare function canonicalFunctionExpression(body: BoxedExpression, args?: BoxedExpression[]): [body: BoxedExpression, ...params: string[]];
68
68
  /**
69
69
  * Apply arguments to an expression which is either
70
70
  * - a '["Function"]' expression
@@ -87,7 +87,7 @@ export declare function makeLambdaN1(expr: BoxedExpression): ((arg: number) => n
87
87
  *
88
88
  * return a JS function that can be called with arguments.
89
89
  */
90
- export declare function applicable(fn: BoxedExpression): (args: BoxedExpression[]) => BoxedExpression | undefined;
90
+ export declare function applicable(fn: BoxedExpression): (xs: ReadonlyArray<BoxedExpression>) => BoxedExpression | undefined;
91
91
  /**
92
92
  * Use applicableN when the function is known to be a function of a single
93
93
  * variable and the argument is a number.
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
3
3
  export declare const DELIMITERS_SHORTHAND: {
4
4
  '(': string;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionaryEntry[];
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;