@cortex-js/compute-engine 0.23.1 → 0.24.1

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 (108) hide show
  1. package/README.md +2 -2
  2. package/dist/compute-engine.esm.js +13789 -13539
  3. package/dist/compute-engine.js +13790 -13540
  4. package/dist/compute-engine.min.esm.js +10 -10
  5. package/dist/compute-engine.min.js +10 -10
  6. package/dist/math-json.esm.js +2 -2
  7. package/dist/math-json.js +2 -2
  8. package/dist/math-json.min.esm.js +2 -2
  9. package/dist/math-json.min.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +1 -1
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/signals.d.ts +12 -1
  13. package/dist/types/common/utils.d.ts +1 -1
  14. package/dist/types/compute-engine/assume.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -4
  16. package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -2
  17. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +8 -4
  18. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +6 -3
  19. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +8 -4
  21. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +5 -3
  22. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +17 -22
  23. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -3
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +2 -2
  25. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +7 -4
  26. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +7 -3
  27. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/utils.d.ts +2 -9
  32. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  33. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  34. package/dist/types/compute-engine/compile.d.ts +1 -1
  35. package/dist/types/compute-engine/compute-engine.d.ts +39 -23
  36. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  37. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  38. package/dist/types/compute-engine/function-utils.d.ts +4 -4
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/parse.d.ts +5 -3
  56. package/dist/types/compute-engine/latex-syntax/public.d.ts +154 -18
  57. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
  59. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  60. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  62. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  63. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  64. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  65. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  66. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  67. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  68. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  69. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  70. package/dist/types/compute-engine/library/core.d.ts +1 -1
  71. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  72. package/dist/types/compute-engine/library/library.d.ts +1 -1
  73. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  74. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  75. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  77. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -1
  78. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  79. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  80. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  81. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  82. package/dist/types/compute-engine/numerics/factor.d.ts +1 -1
  83. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +2 -2
  84. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  85. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  86. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  87. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  88. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  89. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  90. package/dist/types/compute-engine/numerics/terms.d.ts +1 -1
  91. package/dist/types/compute-engine/public.d.ts +159 -55
  92. package/dist/types/compute-engine/rules.d.ts +2 -2
  93. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  94. package/dist/types/compute-engine/solve.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  96. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  97. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  98. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  99. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  100. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  101. package/dist/types/compute-engine/symbolic/tensor-fields.d.ts +1 -1
  102. package/dist/types/compute-engine/symbolic/tensors.d.ts +4 -1
  103. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  104. package/dist/types/compute-engine.d.ts +2 -2
  105. package/dist/types/math-json/math-json-format.d.ts +10 -1
  106. package/dist/types/math-json/utils.d.ts +1 -1
  107. package/dist/types/math-json.d.ts +2 -2
  108. package/package.json +8 -3
@@ -1,20 +1,31 @@
1
- /* 0.23.1 */
2
- * The most important classes are {@link ComputeEngine} and
3
- * {@link BoxedExpression}.
1
+ /* 0.24.1 */
4
2
  *
5
- * With `ComputeEngine` you create `BoxedExpression` objects. With
6
- * `BoxedExpression` you simplify, evaluate and serialize expressions.
3
+ * The Compute Engine is a symbolic computation engine that can be used to
4
+ * manipulate and evaluate mathematical expressions.
5
+ *
6
+ * Use an instance of {@linkcode ComputeEngine} to create boxed expressions
7
+ * with {@linkcode ComputeEngine.parse} and {@linkcode ComputeEngine.box}.
8
+ *
9
+ * Use a {@linkcode BoxedExpression} object to manipulate and evaluate
10
+ * mathematical expressions.
11
+ *
12
+ * @module "compute-engine"
7
13
  *
8
- * @module ComputeEngine
9
14
  */
10
15
  import type { Complex } from 'complex.js';
11
16
  import type { Decimal } from 'decimal.js';
12
17
  import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
13
18
  import type { LatexDictionaryEntry, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
14
19
  export * from './latex-syntax/public';
20
+ export * from './compute-engine';
21
+ /**
22
+ * @category Boxed Expression
23
+ */
15
24
  export type Rational = [number, number] | [bigint, bigint];
16
25
  /**
17
26
  * Metadata that can be associated with a `BoxedExpression`
27
+ *
28
+ * @category Boxed Expression
18
29
  */
19
30
  export type Metadata = {
20
31
  latex?: string | undefined;
@@ -23,7 +34,7 @@ export type Metadata = {
23
34
  /**
24
35
  * The numeric evaluation mode:
25
36
  *
26
- <div class=symbols-table>
37
+ <div className="symbols-table">
27
38
 
28
39
  | Mode | |
29
40
  | :--- | :----- |
@@ -33,29 +44,41 @@ export type Metadata = {
33
44
  | `"complex"` | Complex number represented by two machine numbers, a real and an imaginary part, as provided by the "complex.js" library |
34
45
 
35
46
  </div>
47
+
48
+ * @category Compute Engine
36
49
  */
37
50
  export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
51
+ /** @category Compute Engine */
38
52
  export type Hold = 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
39
- /** Options for `BoxedExpression.simplify()` */
53
+ /** Options for `BoxedExpression.simplify()`
54
+ *
55
+ * @category Compute Engine
56
+ */
40
57
  export type SimplifyOptions = {
41
58
  recursive?: boolean;
42
59
  rules?: BoxedRuleSet;
43
60
  };
44
61
  /** Options for `BoxedExpression.evaluate()`
45
62
  *
63
+ * @category Boxed Expression
46
64
  */
47
65
  export type EvaluateOptions = {
48
66
  numericMode?: boolean;
49
67
  };
50
68
  /** Options for `BoxedExpression.N()`
51
- * @internal
69
+ *
70
+ * @category Boxed Expression
52
71
  */
53
72
  export type NOptions = {};
73
+ /**
74
+ * @category Boxed Expression
75
+ *
76
+ */
54
77
  export type ReplaceOptions = {
55
78
  /** If `true`, apply replacement rules to all sub-expressions.
56
79
  * If `false`, only consider the top-level expression.
57
80
  *
58
- * **Default**: `true`
81
+ * **Default**: `false`
59
82
  */
60
83
  recursive?: boolean;
61
84
  /**
@@ -63,7 +86,7 @@ export type ReplaceOptions = {
63
86
  *
64
87
  * If `false`, apply all the remaining rules even after the first match.
65
88
  *
66
- * **Default**: `true`
89
+ * **Default**: `false`
67
90
  */
68
91
  once?: boolean;
69
92
  /**
@@ -82,16 +105,26 @@ export type ReplaceOptions = {
82
105
  *
83
106
  * A substitution can also be considered a more constrained version of a
84
107
  * rule whose `lhs` is always a symbol.
108
+
109
+ * @category Boxed Expression
85
110
  */
86
111
  export type Substitution<T = SemiBoxedExpression> = {
87
112
  [symbol: string]: T;
88
113
  };
114
+ /**
115
+ * @category Boxed Expression
116
+ *
117
+ */
89
118
  export type BoxedSubstitution = Substitution<BoxedExpression>;
90
119
  /** A LaTeX string starts and end with `$`, for example
91
120
  * `"$\frac{\pi}{2}$"`.
121
+ *
122
+ * @category Latex Parsing and Serialization
92
123
  */
93
124
  export type LatexString = string;
125
+ /** @category Rules */
94
126
  export type PatternReplaceFunction = (expr: BoxedExpression, wildcards: BoxedSubstitution) => BoxedExpression;
127
+ /** @category Rules */
95
128
  export type PatternConditionFunction = (wildcards: BoxedSubstitution, ce: IComputeEngine) => boolean;
96
129
  /**
97
130
  * A rule describes how to modify an expressions that matches a pattern `match`
@@ -100,15 +133,19 @@ export type PatternConditionFunction = (wildcards: BoxedSubstitution, ce: ICompu
100
133
  * `x-1` \( \to \) `1-x`
101
134
  * `(x+1)(x-1)` \( \to \) `x^2-1
102
135
  *
103
- * The `match` pattern can be expressed as a LaTeX string or a MathJSON expression.
136
+ * The `match` pattern can be expressed as a LaTeX string or a
137
+ * MathJSON expression.
104
138
  *
105
139
  *
106
140
  * Anonymous wildcards (`_`) will match any
107
141
  * expression. Named wildcards (`_x`, `_a`, etc...) will match any expression
108
142
  * and bind the expression to the wildcard name.
109
143
  *
110
- * In addition the sequence wildcard (`__1`, `__a`, etc...) will match a sequence
111
- * of one or more expressions, and bind the sequence to the wildcard name.
144
+ * In addition the sequence wildcard (`__1`, `__a`, etc...) will match
145
+ * a sequence of one or more expressions, and bind the sequence to the
146
+ * wildcard name.
147
+ *
148
+ * @category Rules
112
149
  */
113
150
  export type Rule = {
114
151
  match: LatexString | SemiBoxedExpression | Pattern;
@@ -117,6 +154,7 @@ export type Rule = {
117
154
  priority?: number;
118
155
  id?: string;
119
156
  };
157
+ /** @category Rules */
120
158
  export type BoxedRule = {
121
159
  match: Pattern;
122
160
  replace: BoxedExpression | PatternReplaceFunction;
@@ -124,12 +162,25 @@ export type BoxedRule = {
124
162
  priority: number;
125
163
  id?: string;
126
164
  };
165
+ /** @category Rules */
127
166
  export type BoxedRuleSet = Set<BoxedRule>;
167
+ /** @category Boxed Expression */
128
168
  export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
129
- /** A domain constructor is the head of a domain expression. */
169
+ /** A domain constructor is the head of a domain expression.
170
+ *
171
+ * @category Boxed Expression
172
+ *
173
+ */
130
174
  export type DomainConstructor = 'FunctionOf' | 'ListOf' | 'DictionaryOf' | 'TupleOf' | 'Intersection' | 'Union' | 'OptArg' | 'VarArg' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
175
+ /** @category Boxed Expression */
131
176
  export type DomainLiteral = 'Anything' | 'Values' | 'Domains' | 'Void' | 'NothingDomain' | 'Booleans' | 'Strings' | 'Symbols' | 'Collections' | 'Lists' | 'Dictionaries' | 'Sequences' | 'Tuples' | 'Sets' | 'Functions' | 'Predicates' | 'LogicOperators' | 'RelationalOperators' | 'NumericFunctions' | 'RealFunctions' | 'Numbers' | 'ComplexNumbers' | 'ExtendedRealNumbers' | 'ImaginaryNumbers' | 'Integers' | 'Rationals' | 'PositiveNumbers' | 'PositiveIntegers' | 'NegativeNumbers' | 'NegativeIntegers' | 'NonNegativeNumbers' | 'NonNegativeIntegers' | 'NonPositiveNumbers' | 'NonPositiveIntegers' | 'ExtendedComplexNumbers' | 'TranscendentalNumbers' | 'AlgebraicNumbers' | 'RationalNumbers' | 'RealNumbers';
177
+ /** @category Boxed Expression */
132
178
  export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['ListOf', DomainExpression<T>] | ['DictionaryOf', DomainExpression<T>] | ['TupleOf', ...DomainExpression<T>[]] | ['OptArg', ...DomainExpression<T>[]] | ['VarArg', DomainExpression<T>] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['FunctionOf', ...DomainExpression<T>[]];
179
+ /**
180
+ * @noInheritDoc
181
+ *
182
+ * @category Boxed Expression
183
+ */
133
184
  export interface BoxedDomain extends BoxedExpression {
134
185
  get canonical(): BoxedDomain;
135
186
  get json(): Expression;
@@ -145,6 +196,8 @@ export interface BoxedDomain extends BoxedExpression {
145
196
  }
146
197
  /**
147
198
  * Options to control the serialization to MathJSON when using `BoxedExpression.json`.
199
+ *
200
+ * @category Compute Engine
148
201
  */
149
202
  export type JsonSerializationOptions = {
150
203
  /** A list of space separated function names that should be excluded from
@@ -188,9 +241,12 @@ export type JsonSerializationOptions = {
188
241
  */
189
242
  precision: 'auto' | 'max' | number;
190
243
  };
244
+ /**
245
+ * @category Boxed Expression
246
+ */
191
247
  export type CanonicalForm = 'InvisibleOperator' | 'Number' | 'Multiply' | 'Add' | 'Power' | 'Divide' | 'Flatten' | 'Order';
192
248
  /**
193
- * ## THEORY OF OPERATIONS
249
+ * :::info[THEORY OF OPERATIONS]
194
250
  *
195
251
  * The `BoxedExpression` interface includes most of the member functions
196
252
  * applicable to any kind of expression, for example `get symbol()` or
@@ -201,6 +257,11 @@ export type CanonicalForm = 'InvisibleOperator' | 'Number' | 'Multiply' | 'Add'
201
257
  *
202
258
  * This convention makes it convenient to manipulate expressions without
203
259
  * having to check what kind of instance they are before manipulating them.
260
+ * :::
261
+ *
262
+ * To get a boxed expression, use `ce.box()` or `ce.parse()`.
263
+ *
264
+ * @category Boxed Expression
204
265
  *
205
266
  */
206
267
  export interface BoxedExpression {
@@ -208,7 +269,6 @@ export interface BoxedExpression {
208
269
  * a context in which to interpret it, such as definition of symbols
209
270
  * and functions.
210
271
  *
211
- * {@link ComputeEngine} is the class that implements IComputeEngine.
212
272
  */
213
273
  readonly engine: IComputeEngine;
214
274
  /** From `Object.valueOf()`, return a primitive value for the expression.
@@ -492,17 +552,20 @@ export interface BoxedExpression {
492
552
  }): BoxedExpression;
493
553
  /**
494
554
  * Transform the expression by applying the rules:
495
- * if the `lhs` of a rule matches, it is replaced by its `rhs`.
555
+ *
556
+ * if the expression matches the `match` pattern, replace it with
557
+ * the `replace` pattern.
496
558
  *
497
559
  * If no rules apply, return `null`.
498
560
  *
499
561
  * See also `subs` for a simple substitution.
500
562
  *
501
563
  *
502
- * **Note** applicable to canonical and non-canonical expressions.
564
+ * **Note** applicable to canonical and non-canonical expressions. If the
565
+ * expression is non-canonical, the result is also non-canonical.
503
566
  *
504
567
  */
505
- replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
568
+ replace(rules: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): null | BoxedExpression;
506
569
  /**
507
570
  * True if the expression includes a symbol `v` or a function head `v`.
508
571
  *
@@ -518,23 +581,21 @@ export interface BoxedExpression {
518
581
  * @category Relational Operator
519
582
  */
520
583
  isSame(rhs: BoxedExpression): boolean;
521
- /** Attempt to match this expression to the `rhs` expression.
522
- *
523
- * If `rhs` does not match, return `null`.
524
- *
525
- * Otherwise return an object literal.
584
+ /**
585
+ * If this expression matches `pattern`, return a substitution that makes
586
+ * `pattern` equal to `this`. Otherwise return `null`.
526
587
  *
527
- * If this expression includes wildcards (symbols with a name that starts
528
- * with `_`), the object literal will include a prop for each matching named
588
+ * If `pattern` includes wildcards (identifiers that starts
589
+ * with `_`), the substitution will include a prop for each matching named
529
590
  * wildcard.
530
591
  *
531
- * If `rhs` matches this pattern but there are no named wildcards, return
532
- * the empty object literal, `{}`.
592
+ * If this expression matches `pattern` but there are no named wildcards,
593
+ * return the empty substitution, `{}`.
533
594
  *
534
595
  * **Note** applicable to canonical and non-canonical expressions.
535
596
  *
536
597
  */
537
- match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
598
+ match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
538
599
  /**
539
600
  * "Not a Number".
540
601
  *
@@ -677,7 +738,7 @@ export interface BoxedExpression {
677
738
  * @category Expression Properties
678
739
  */
679
740
  readonly isNegative: boolean | undefined;
680
- /** The numeric value of this expression is <= 0, same as `isLessEqual(0)`
741
+ /** The numeric value of this expression is &lt;= 0, same as `isLessEqual(0)`
681
742
  *
682
743
  * @category Expression Properties
683
744
  */
@@ -992,11 +1053,13 @@ export interface BoxedExpression {
992
1053
  */
993
1054
  isEqual(rhs: BoxedExpression): boolean;
994
1055
  }
995
- /** A semi boxed expression is an MathJSON expression which can include some
1056
+ /** A semi boxed expression is a MathJSON expression which can include some
996
1057
  * boxed terms.
997
1058
  *
998
1059
  * This is convenient when creating new expressions from portions
999
1060
  * of an existing `BoxedExpression` while avoiding unboxing and reboxing.
1061
+ *
1062
+ * @category Boxed Expression
1000
1063
  */
1001
1064
  export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
1002
1065
  /**
@@ -1006,6 +1069,9 @@ export type SemiBoxedExpression = number | string | Decimal | Complex | MathJson
1006
1069
  * - `recursive`: if true, match recursively, otherwise match only the top level.
1007
1070
  * - `numericTolerance`: if present, the tolerance for numeric comparison.
1008
1071
  * - `exact`: if true, only match expressions that are structurally identical. If false, match expressions that are structurally identical or equivalent. For example, when false, `["Add", '_a', 2]` matches `2`, with a value of `_a` of `0`. If true, the expression does not match.
1072
+ *
1073
+ * @category Pattern Matching
1074
+ *
1009
1075
  */
1010
1076
  export type PatternMatchOptions = {
1011
1077
  substitution?: BoxedSubstitution;
@@ -1013,12 +1079,13 @@ export type PatternMatchOptions = {
1013
1079
  numericTolerance?: number;
1014
1080
  exact?: boolean;
1015
1081
  };
1016
- export interface Pattern extends BoxedExpression {
1017
- /** If `expr` matches the pattern, return `true`, otherwise `false` */
1018
- test(expr: BoxedExpression, options?: PatternMatchOptions): boolean;
1019
- /** Return the number of exprs that matched the pattern */
1020
- count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOptions): number;
1021
- }
1082
+ /**
1083
+ * @noInheritDoc
1084
+ *
1085
+ * @category Pattern Matching
1086
+ */
1087
+ export type Pattern = BoxedExpression;
1088
+ /** @category Assumptions */
1022
1089
  export interface ExpressionMapInterface<U> {
1023
1090
  has(expr: BoxedExpression): boolean;
1024
1091
  get(expr: BoxedExpression): U | undefined;
@@ -1039,9 +1106,14 @@ export interface ExpressionMapInterface<U> {
1039
1106
  * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
1040
1107
  *
1041
1108
  * If a semi boxed expression
1109
+ * @category Definitions
1042
1110
  *
1043
1111
  */
1044
1112
  export type IdentifierDefinition = SymbolDefinition | FunctionDefinition | SemiBoxedExpression;
1113
+ /**
1114
+ * @category Definitions
1115
+ *
1116
+ */
1045
1117
  export type IdentifierDefinitions = Readonly<{
1046
1118
  [id: string]: IdentifierDefinition;
1047
1119
  }>;
@@ -1050,6 +1122,8 @@ export type IdentifierDefinitions = Readonly<{
1050
1122
  *
1051
1123
  * When a new scope is created with `pushScope()` or when creating a new
1052
1124
  * engine instance, new instances of this type are created as needed.
1125
+ *
1126
+ * @category Definitions
1053
1127
  */
1054
1128
  export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
1055
1129
  /**
@@ -1066,6 +1140,7 @@ export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | B
1066
1140
  * Scopes are lexical (also called a static scope): they are defined based on
1067
1141
  * where they are in an expression, they are not determined at runtime.
1068
1142
  *
1143
+ * @category Compute Engine
1069
1144
  */
1070
1145
  export type Scope = {
1071
1146
  /** Signal `timeout` when the execution time for this scope is exceeded.
@@ -1095,11 +1170,16 @@ export type Scope = {
1095
1170
  */
1096
1171
  iterationLimit: number;
1097
1172
  };
1173
+ /** @category Compute Engine */
1098
1174
  export type RuntimeScope = Scope & {
1099
1175
  parentScope?: RuntimeScope;
1100
1176
  ids?: RuntimeIdentifierDefinitions;
1101
1177
  assumptions: undefined | ExpressionMapInterface<boolean>;
1102
1178
  };
1179
+ /**
1180
+ * @category Definitions
1181
+ *
1182
+ */
1103
1183
  export type BaseDefinition = {
1104
1184
  /** A short (about 1 line) description. May contain Markdown. */
1105
1185
  description?: string | string[];
@@ -1113,6 +1193,10 @@ export type BaseDefinition = {
1113
1193
  */
1114
1194
  wikidata?: string;
1115
1195
  };
1196
+ /**
1197
+ * @category Definitions
1198
+ *
1199
+ */
1116
1200
  export interface BoxedBaseDefinition {
1117
1201
  name: string;
1118
1202
  wikidata?: string;
@@ -1132,6 +1216,7 @@ export interface BoxedBaseDefinition {
1132
1216
  /**
1133
1217
  * A function definition can have some flags to indicate specific
1134
1218
  * properties of the function.
1219
+ * @category Definitions
1135
1220
  */
1136
1221
  export type FunctionDefinitionFlags = {
1137
1222
  /** If `true`, the function is applied element by element to lists, matrices
@@ -1218,6 +1303,7 @@ export type FunctionDefinitionFlags = {
1218
1303
  numeric: boolean;
1219
1304
  };
1220
1305
  /**
1306
+ * @category Definitions
1221
1307
  *
1222
1308
  */
1223
1309
  export type FunctionSignature = {
@@ -1379,6 +1465,10 @@ export type FunctionSignature = {
1379
1465
  /** Return a compiled (optimized) expression. */
1380
1466
  compile?: (expr: BoxedExpression) => CompiledExpression;
1381
1467
  };
1468
+ /**
1469
+ * @category Definitions
1470
+ *
1471
+ */
1382
1472
  export type BoxedFunctionSignature = {
1383
1473
  inferredSignature: boolean;
1384
1474
  params: BoxedDomain[];
@@ -1404,20 +1494,23 @@ export type BoxedFunctionSignature = {
1404
1494
  * The `size()` handler of infinite collections returns `Infinity`
1405
1495
  * Infinite collections are not indexable, they have no `at()` handler.
1406
1496
  *
1497
+ * @category Definitions
1407
1498
  */
1408
1499
  export type CollectionHandlers = {
1409
1500
  /** Return an iterator
1410
1501
  * - start is optional and is a 1-based index.
1411
1502
  * - if start is not specified, start from index 1
1412
1503
  * - count is optional and is the number of elements to return
1413
- * - if count is not specified or negative, return all the elements from start to the end
1504
+ * - if count is not specified or negative, return all the elements from start to the endna
1414
1505
  *
1415
1506
  * If there is a `keys()` handler, there is no `iterator()` handler.
1507
+ *
1508
+ * @category Definitions
1416
1509
  */
1417
1510
  iterator: (expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>;
1418
1511
  /** Return the element at the specified index.
1419
1512
  * The first element is `at(1)`, the last element is `at(-1)`.
1420
- * If the index is <0, return the element at index `size() + index + 1`.
1513
+ * If the index is &lt;0, return the element at index `size() + index + 1`.
1421
1514
  * The index can also be a string for example for dictionaries.
1422
1515
  * If the index is invalid, return `undefined`.
1423
1516
  */
@@ -1446,6 +1539,7 @@ export type CollectionHandlers = {
1446
1539
  };
1447
1540
  /**
1448
1541
  * Definition record for a function.
1542
+ * @category Definitions
1449
1543
  *
1450
1544
  */
1451
1545
  export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> & Partial<FunctionDefinitionFlags> & {
@@ -1483,6 +1577,10 @@ export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> &
1483
1577
  hold?: Hold;
1484
1578
  signature: FunctionSignature;
1485
1579
  };
1580
+ /**
1581
+ * @category Definitions
1582
+ *
1583
+ */
1486
1584
  export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHandlers> & FunctionDefinitionFlags & {
1487
1585
  complexity: number;
1488
1586
  hold: Hold;
@@ -1496,6 +1594,8 @@ export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHa
1496
1594
  *
1497
1595
  * For example, it might be useful to override `algebraic = false`
1498
1596
  * for a transcendental number.
1597
+ *
1598
+ * @category Definitions
1499
1599
  */
1500
1600
  export type NumericFlags = {
1501
1601
  number: boolean | undefined;
@@ -1523,6 +1623,10 @@ export type NumericFlags = {
1523
1623
  prime: boolean | undefined;
1524
1624
  composite: boolean | undefined;
1525
1625
  };
1626
+ /**
1627
+ * @category Definitions
1628
+ *
1629
+ */
1526
1630
  export type SymbolAttributes = {
1527
1631
  /**
1528
1632
  * If `true` the value of the symbol is constant. The value or domain of
@@ -1537,7 +1641,7 @@ export type SymbolAttributes = {
1537
1641
  * If the symbol has a value, it is held as indicated in the table below.
1538
1642
  * A green checkmark indicate that the symbol is substituted.
1539
1643
 
1540
- <div class=symbols-table>
1644
+ <div className="symbols-table">
1541
1645
 
1542
1646
  | Operation | `"never"` | `"simplify"` | `"evaluate"` | `"N"` |
1543
1647
  | :--- | :----- |
@@ -1561,6 +1665,7 @@ export type SymbolAttributes = {
1561
1665
  /**
1562
1666
  * A bound symbol (i.e. one with an associated definition) has either a domain
1563
1667
  * (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumbers)
1668
+ * @category Definitions
1564
1669
  */
1565
1670
  export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
1566
1671
  domain?: DomainLiteral | BoxedDomain;
@@ -1575,24 +1680,33 @@ export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
1575
1680
  value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
1576
1681
  flags?: Partial<NumericFlags>;
1577
1682
  };
1683
+ /**
1684
+ * @noInheritDoc
1685
+ * @category Definitions
1686
+ */
1578
1687
  export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<NumericFlags> {
1579
1688
  get value(): BoxedExpression | undefined;
1580
1689
  set value(val: SemiBoxedExpression | number | undefined);
1581
1690
  domain: BoxedDomain | undefined;
1582
1691
  inferredDomain: boolean;
1583
1692
  }
1693
+ /** @category Assumptions */
1584
1694
  export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1695
+ /** @category Compiling */
1585
1696
  export type CompiledExpression = {
1586
1697
  evaluate?: (scope: {
1587
1698
  [symbol: string]: BoxedExpression;
1588
1699
  }) => number | BoxedExpression;
1589
1700
  };
1701
+ /** @internal */
1590
1702
  export interface ComputeEngineStats {
1591
1703
  symbols: Set<BoxedExpression>;
1592
1704
  expressions: null | Set<BoxedExpression>;
1593
1705
  highwaterMark: number;
1594
1706
  }
1595
- export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: any, args: any) => BoxedExpression) | undefined;
1707
+ /** @category Compute Engine */
1708
+ export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: IComputeEngine, args: any) => BoxedExpression) | undefined;
1709
+ /** @category Compute Engine */
1596
1710
  export type ArrayValue = boolean | number | string | Decimal | Complex | BoxedExpression | undefined;
1597
1711
  /** @internal */
1598
1712
  export interface IComputeEngine {
@@ -1636,13 +1750,12 @@ export interface IComputeEngine {
1636
1750
  * @internal
1637
1751
  */
1638
1752
  deadline?: number;
1639
- /** @experimental */
1753
+ /** @hidden */
1640
1754
  readonly timeLimit: number;
1641
- /** @experimental */
1755
+ /** @hidden */
1642
1756
  readonly iterationLimit: number;
1643
- /** @experimental */
1757
+ /** @hidden */
1644
1758
  readonly recursionLimit: number;
1645
- /** {@inheritDoc NumericMode} */
1646
1759
  numericMode: NumericMode;
1647
1760
  tolerance: number;
1648
1761
  chop(n: number): number;
@@ -1656,16 +1769,8 @@ export interface IComputeEngine {
1656
1769
  set precision(p: number | 'machine');
1657
1770
  get precision(): number;
1658
1771
  costFunction: (expr: BoxedExpression) => number;
1659
- /** In strict mode the compute engine performs additional checks,
1660
- * for example to ensure the correct number and domain of arguments. These
1661
- * checks may impact performance.
1662
- */
1663
1772
  strict: boolean;
1664
- /** Return a canonical version of an array of semi-boxed-expressions. */
1665
1773
  canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
1666
- /** Return as boxed expression from a number, string or semiboxed expression.
1667
- * Calls `function()`, `number()` or `symbol()` as appropriate.
1668
- */
1669
1774
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
1670
1775
  canonical?: boolean | CanonicalForm | CanonicalForm[];
1671
1776
  }): BoxedExpression;
@@ -1698,7 +1803,6 @@ export interface IComputeEngine {
1698
1803
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1699
1804
  array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
1700
1805
  rules(rules: Rule[]): BoxedRuleSet;
1701
- pattern(expr: LatexString | SemiBoxedExpression): Pattern;
1702
1806
  /**
1703
1807
  * This is a primitive to create a boxed function.
1704
1808
  *
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * For each rules in the rule set that match, return the `replace` of the rule
4
4
  *
@@ -17,4 +17,4 @@ export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedR
17
17
  *
18
18
  * If no rule applied, return `null`.
19
19
  */
20
- export declare function replace(expr: BoxedExpression, ruleSet: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
20
+ export declare function replace(expr: BoxedExpression, ruleSet: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): BoxedExpression | null;
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * @todo: a set to "tidy" an expression. Different from a canonical form, but
4
4
  * inline with the user's expectations.
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  export declare const UNIVARIATE_ROOTS: Rule[];
3
3
  /**
4
4
  * Expression is a function of a single variable (`x`) or an Equality
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  *
4
4
  * @param fn The function to differentiate, a `["Function"]` expression or
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  export declare function distribute(expr: BoxedExpression[]): BoxedExpression;
3
3
  /** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.
4
4
  * The expression must be a power of a sum of terms.
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * Flatten the arguments.
4
4
  */
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
4
  * addition or multiplication or another `Negate`.
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  /**
3
3
  * Group terms in a product by common term.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  import { BoxedExpression, IComputeEngine } from '../public';
3
3
  export type DataTypeMap = {
4
4
  float64: number;
@@ -1,5 +1,8 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  import { DataTypeMap, TensorDataType, TensorField } from './tensor-fields';
3
+ /**
4
+ * @noInheritDoc
5
+ */
3
6
  export interface TensorData<DT extends keyof DataTypeMap = 'float64'> {
4
7
  dtype: DT;
5
8
  shape: number[];
@@ -1,4 +1,4 @@
1
- /* 0.23.1 */
1
+ /* 0.24.1 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression, Hold, Rational } from '../public';
4
4
  /**
@@ -1,3 +1,3 @@
1
- /* 0.23.1 */
2
- export declare const version = "0.23.1";
1
+ /* 0.24.1 */
2
+ export declare const version = "0.24.1";
3
3
  export { ComputeEngine } from './compute-engine/compute-engine';