@cortex-js/compute-engine 0.23.1 → 0.24.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.
- package/README.md +2 -2
- package/dist/compute-engine.esm.js +13003 -12756
- package/dist/compute-engine.js +12985 -12738
- package/dist/compute-engine.min.esm.js +10 -10
- package/dist/compute-engine.min.js +10 -10
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +12 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -4
- package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +8 -4
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +6 -3
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +8 -4
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +5 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +17 -22
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +7 -4
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +7 -3
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +2 -9
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +39 -23
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +4 -4
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +5 -3
- package/dist/types/compute-engine/latex-syntax/public.d.ts +154 -18
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numerics/factor.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/terms.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +156 -54
- package/dist/types/compute-engine/rules.d.ts +2 -2
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/tensors.d.ts +4 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +10 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +8 -3
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
* The most important classes are {@link ComputeEngine} and
|
|
3
|
-
* {@link BoxedExpression}.
|
|
1
|
+
/* 0.24.0 */
|
|
4
2
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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**: `
|
|
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**: `
|
|
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
|
|
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
|
|
111
|
-
* of one or more expressions, and bind the sequence to the
|
|
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
|
-
*
|
|
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,7 +552,8 @@ export interface BoxedExpression {
|
|
|
492
552
|
}): BoxedExpression;
|
|
493
553
|
/**
|
|
494
554
|
* Transform the expression by applying the rules:
|
|
495
|
-
* if the `
|
|
555
|
+
* if an expression matches the `match` pattern, replace it with
|
|
556
|
+
* the `replace` pattern.
|
|
496
557
|
*
|
|
497
558
|
* If no rules apply, return `null`.
|
|
498
559
|
*
|
|
@@ -502,7 +563,7 @@ export interface BoxedExpression {
|
|
|
502
563
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
503
564
|
*
|
|
504
565
|
*/
|
|
505
|
-
replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
|
|
566
|
+
replace(rules: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): null | BoxedExpression;
|
|
506
567
|
/**
|
|
507
568
|
* True if the expression includes a symbol `v` or a function head `v`.
|
|
508
569
|
*
|
|
@@ -518,23 +579,21 @@ export interface BoxedExpression {
|
|
|
518
579
|
* @category Relational Operator
|
|
519
580
|
*/
|
|
520
581
|
isSame(rhs: BoxedExpression): boolean;
|
|
521
|
-
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
* Otherwise return an object literal.
|
|
582
|
+
/**
|
|
583
|
+
* If this expression matches `pattern`, return a substitution that makes
|
|
584
|
+
* `pattern` equal to `this`. Otherwise return `null`.
|
|
526
585
|
*
|
|
527
|
-
* If
|
|
528
|
-
* with `_`), the
|
|
586
|
+
* If `pattern` includes wildcards (identifiers that starts
|
|
587
|
+
* with `_`), the substitution will include a prop for each matching named
|
|
529
588
|
* wildcard.
|
|
530
589
|
*
|
|
531
|
-
* If
|
|
532
|
-
* the empty
|
|
590
|
+
* If this expression matches `pattern` but there are no named wildcards,
|
|
591
|
+
* return the empty substitution, `{}`.
|
|
533
592
|
*
|
|
534
593
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
535
594
|
*
|
|
536
595
|
*/
|
|
537
|
-
match(
|
|
596
|
+
match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
538
597
|
/**
|
|
539
598
|
* "Not a Number".
|
|
540
599
|
*
|
|
@@ -677,7 +736,7 @@ export interface BoxedExpression {
|
|
|
677
736
|
* @category Expression Properties
|
|
678
737
|
*/
|
|
679
738
|
readonly isNegative: boolean | undefined;
|
|
680
|
-
/** The numeric value of this expression is
|
|
739
|
+
/** The numeric value of this expression is <= 0, same as `isLessEqual(0)`
|
|
681
740
|
*
|
|
682
741
|
* @category Expression Properties
|
|
683
742
|
*/
|
|
@@ -992,11 +1051,13 @@ export interface BoxedExpression {
|
|
|
992
1051
|
*/
|
|
993
1052
|
isEqual(rhs: BoxedExpression): boolean;
|
|
994
1053
|
}
|
|
995
|
-
/** A semi boxed expression is
|
|
1054
|
+
/** A semi boxed expression is a MathJSON expression which can include some
|
|
996
1055
|
* boxed terms.
|
|
997
1056
|
*
|
|
998
1057
|
* This is convenient when creating new expressions from portions
|
|
999
1058
|
* of an existing `BoxedExpression` while avoiding unboxing and reboxing.
|
|
1059
|
+
*
|
|
1060
|
+
* @category Boxed Expression
|
|
1000
1061
|
*/
|
|
1001
1062
|
export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
|
|
1002
1063
|
/**
|
|
@@ -1006,6 +1067,9 @@ export type SemiBoxedExpression = number | string | Decimal | Complex | MathJson
|
|
|
1006
1067
|
* - `recursive`: if true, match recursively, otherwise match only the top level.
|
|
1007
1068
|
* - `numericTolerance`: if present, the tolerance for numeric comparison.
|
|
1008
1069
|
* - `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.
|
|
1070
|
+
*
|
|
1071
|
+
* @category Pattern Matching
|
|
1072
|
+
*
|
|
1009
1073
|
*/
|
|
1010
1074
|
export type PatternMatchOptions = {
|
|
1011
1075
|
substitution?: BoxedSubstitution;
|
|
@@ -1013,12 +1077,13 @@ export type PatternMatchOptions = {
|
|
|
1013
1077
|
numericTolerance?: number;
|
|
1014
1078
|
exact?: boolean;
|
|
1015
1079
|
};
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1080
|
+
/**
|
|
1081
|
+
* @noInheritDoc
|
|
1082
|
+
*
|
|
1083
|
+
* @category Pattern Matching
|
|
1084
|
+
*/
|
|
1085
|
+
export type Pattern = BoxedExpression;
|
|
1086
|
+
/** @category Assumptions */
|
|
1022
1087
|
export interface ExpressionMapInterface<U> {
|
|
1023
1088
|
has(expr: BoxedExpression): boolean;
|
|
1024
1089
|
get(expr: BoxedExpression): U | undefined;
|
|
@@ -1039,9 +1104,14 @@ export interface ExpressionMapInterface<U> {
|
|
|
1039
1104
|
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1040
1105
|
*
|
|
1041
1106
|
* If a semi boxed expression
|
|
1107
|
+
* @category Definitions
|
|
1042
1108
|
*
|
|
1043
1109
|
*/
|
|
1044
1110
|
export type IdentifierDefinition = SymbolDefinition | FunctionDefinition | SemiBoxedExpression;
|
|
1111
|
+
/**
|
|
1112
|
+
* @category Definitions
|
|
1113
|
+
*
|
|
1114
|
+
*/
|
|
1045
1115
|
export type IdentifierDefinitions = Readonly<{
|
|
1046
1116
|
[id: string]: IdentifierDefinition;
|
|
1047
1117
|
}>;
|
|
@@ -1050,6 +1120,8 @@ export type IdentifierDefinitions = Readonly<{
|
|
|
1050
1120
|
*
|
|
1051
1121
|
* When a new scope is created with `pushScope()` or when creating a new
|
|
1052
1122
|
* engine instance, new instances of this type are created as needed.
|
|
1123
|
+
*
|
|
1124
|
+
* @category Definitions
|
|
1053
1125
|
*/
|
|
1054
1126
|
export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
|
|
1055
1127
|
/**
|
|
@@ -1066,6 +1138,7 @@ export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | B
|
|
|
1066
1138
|
* Scopes are lexical (also called a static scope): they are defined based on
|
|
1067
1139
|
* where they are in an expression, they are not determined at runtime.
|
|
1068
1140
|
*
|
|
1141
|
+
* @category Compute Engine
|
|
1069
1142
|
*/
|
|
1070
1143
|
export type Scope = {
|
|
1071
1144
|
/** Signal `timeout` when the execution time for this scope is exceeded.
|
|
@@ -1095,11 +1168,16 @@ export type Scope = {
|
|
|
1095
1168
|
*/
|
|
1096
1169
|
iterationLimit: number;
|
|
1097
1170
|
};
|
|
1171
|
+
/** @category Compute Engine */
|
|
1098
1172
|
export type RuntimeScope = Scope & {
|
|
1099
1173
|
parentScope?: RuntimeScope;
|
|
1100
1174
|
ids?: RuntimeIdentifierDefinitions;
|
|
1101
1175
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
1102
1176
|
};
|
|
1177
|
+
/**
|
|
1178
|
+
* @category Definitions
|
|
1179
|
+
*
|
|
1180
|
+
*/
|
|
1103
1181
|
export type BaseDefinition = {
|
|
1104
1182
|
/** A short (about 1 line) description. May contain Markdown. */
|
|
1105
1183
|
description?: string | string[];
|
|
@@ -1113,6 +1191,10 @@ export type BaseDefinition = {
|
|
|
1113
1191
|
*/
|
|
1114
1192
|
wikidata?: string;
|
|
1115
1193
|
};
|
|
1194
|
+
/**
|
|
1195
|
+
* @category Definitions
|
|
1196
|
+
*
|
|
1197
|
+
*/
|
|
1116
1198
|
export interface BoxedBaseDefinition {
|
|
1117
1199
|
name: string;
|
|
1118
1200
|
wikidata?: string;
|
|
@@ -1132,6 +1214,7 @@ export interface BoxedBaseDefinition {
|
|
|
1132
1214
|
/**
|
|
1133
1215
|
* A function definition can have some flags to indicate specific
|
|
1134
1216
|
* properties of the function.
|
|
1217
|
+
* @category Definitions
|
|
1135
1218
|
*/
|
|
1136
1219
|
export type FunctionDefinitionFlags = {
|
|
1137
1220
|
/** If `true`, the function is applied element by element to lists, matrices
|
|
@@ -1218,6 +1301,7 @@ export type FunctionDefinitionFlags = {
|
|
|
1218
1301
|
numeric: boolean;
|
|
1219
1302
|
};
|
|
1220
1303
|
/**
|
|
1304
|
+
* @category Definitions
|
|
1221
1305
|
*
|
|
1222
1306
|
*/
|
|
1223
1307
|
export type FunctionSignature = {
|
|
@@ -1379,6 +1463,10 @@ export type FunctionSignature = {
|
|
|
1379
1463
|
/** Return a compiled (optimized) expression. */
|
|
1380
1464
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1381
1465
|
};
|
|
1466
|
+
/**
|
|
1467
|
+
* @category Definitions
|
|
1468
|
+
*
|
|
1469
|
+
*/
|
|
1382
1470
|
export type BoxedFunctionSignature = {
|
|
1383
1471
|
inferredSignature: boolean;
|
|
1384
1472
|
params: BoxedDomain[];
|
|
@@ -1404,20 +1492,23 @@ export type BoxedFunctionSignature = {
|
|
|
1404
1492
|
* The `size()` handler of infinite collections returns `Infinity`
|
|
1405
1493
|
* Infinite collections are not indexable, they have no `at()` handler.
|
|
1406
1494
|
*
|
|
1495
|
+
* @category Definitions
|
|
1407
1496
|
*/
|
|
1408
1497
|
export type CollectionHandlers = {
|
|
1409
1498
|
/** Return an iterator
|
|
1410
1499
|
* - start is optional and is a 1-based index.
|
|
1411
1500
|
* - if start is not specified, start from index 1
|
|
1412
1501
|
* - 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
|
|
1502
|
+
* - if count is not specified or negative, return all the elements from start to the endna
|
|
1414
1503
|
*
|
|
1415
1504
|
* If there is a `keys()` handler, there is no `iterator()` handler.
|
|
1505
|
+
*
|
|
1506
|
+
* @category Definitions
|
|
1416
1507
|
*/
|
|
1417
1508
|
iterator: (expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>;
|
|
1418
1509
|
/** Return the element at the specified index.
|
|
1419
1510
|
* The first element is `at(1)`, the last element is `at(-1)`.
|
|
1420
|
-
* If the index is
|
|
1511
|
+
* If the index is <0, return the element at index `size() + index + 1`.
|
|
1421
1512
|
* The index can also be a string for example for dictionaries.
|
|
1422
1513
|
* If the index is invalid, return `undefined`.
|
|
1423
1514
|
*/
|
|
@@ -1446,6 +1537,7 @@ export type CollectionHandlers = {
|
|
|
1446
1537
|
};
|
|
1447
1538
|
/**
|
|
1448
1539
|
* Definition record for a function.
|
|
1540
|
+
* @category Definitions
|
|
1449
1541
|
*
|
|
1450
1542
|
*/
|
|
1451
1543
|
export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> & Partial<FunctionDefinitionFlags> & {
|
|
@@ -1483,6 +1575,10 @@ export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> &
|
|
|
1483
1575
|
hold?: Hold;
|
|
1484
1576
|
signature: FunctionSignature;
|
|
1485
1577
|
};
|
|
1578
|
+
/**
|
|
1579
|
+
* @category Definitions
|
|
1580
|
+
*
|
|
1581
|
+
*/
|
|
1486
1582
|
export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHandlers> & FunctionDefinitionFlags & {
|
|
1487
1583
|
complexity: number;
|
|
1488
1584
|
hold: Hold;
|
|
@@ -1496,6 +1592,8 @@ export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHa
|
|
|
1496
1592
|
*
|
|
1497
1593
|
* For example, it might be useful to override `algebraic = false`
|
|
1498
1594
|
* for a transcendental number.
|
|
1595
|
+
*
|
|
1596
|
+
* @category Definitions
|
|
1499
1597
|
*/
|
|
1500
1598
|
export type NumericFlags = {
|
|
1501
1599
|
number: boolean | undefined;
|
|
@@ -1523,6 +1621,10 @@ export type NumericFlags = {
|
|
|
1523
1621
|
prime: boolean | undefined;
|
|
1524
1622
|
composite: boolean | undefined;
|
|
1525
1623
|
};
|
|
1624
|
+
/**
|
|
1625
|
+
* @category Definitions
|
|
1626
|
+
*
|
|
1627
|
+
*/
|
|
1526
1628
|
export type SymbolAttributes = {
|
|
1527
1629
|
/**
|
|
1528
1630
|
* If `true` the value of the symbol is constant. The value or domain of
|
|
@@ -1537,7 +1639,7 @@ export type SymbolAttributes = {
|
|
|
1537
1639
|
* If the symbol has a value, it is held as indicated in the table below.
|
|
1538
1640
|
* A green checkmark indicate that the symbol is substituted.
|
|
1539
1641
|
|
|
1540
|
-
<div
|
|
1642
|
+
<div className="symbols-table">
|
|
1541
1643
|
|
|
1542
1644
|
| Operation | `"never"` | `"simplify"` | `"evaluate"` | `"N"` |
|
|
1543
1645
|
| :--- | :----- |
|
|
@@ -1561,6 +1663,7 @@ export type SymbolAttributes = {
|
|
|
1561
1663
|
/**
|
|
1562
1664
|
* A bound symbol (i.e. one with an associated definition) has either a domain
|
|
1563
1665
|
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumbers)
|
|
1666
|
+
* @category Definitions
|
|
1564
1667
|
*/
|
|
1565
1668
|
export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
|
|
1566
1669
|
domain?: DomainLiteral | BoxedDomain;
|
|
@@ -1575,24 +1678,33 @@ export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
|
|
|
1575
1678
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1576
1679
|
flags?: Partial<NumericFlags>;
|
|
1577
1680
|
};
|
|
1681
|
+
/**
|
|
1682
|
+
* @noInheritDoc
|
|
1683
|
+
* @category Definitions
|
|
1684
|
+
*/
|
|
1578
1685
|
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<NumericFlags> {
|
|
1579
1686
|
get value(): BoxedExpression | undefined;
|
|
1580
1687
|
set value(val: SemiBoxedExpression | number | undefined);
|
|
1581
1688
|
domain: BoxedDomain | undefined;
|
|
1582
1689
|
inferredDomain: boolean;
|
|
1583
1690
|
}
|
|
1691
|
+
/** @category Assumptions */
|
|
1584
1692
|
export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
|
|
1693
|
+
/** @category Compiling */
|
|
1585
1694
|
export type CompiledExpression = {
|
|
1586
1695
|
evaluate?: (scope: {
|
|
1587
1696
|
[symbol: string]: BoxedExpression;
|
|
1588
1697
|
}) => number | BoxedExpression;
|
|
1589
1698
|
};
|
|
1699
|
+
/** @internal */
|
|
1590
1700
|
export interface ComputeEngineStats {
|
|
1591
1701
|
symbols: Set<BoxedExpression>;
|
|
1592
1702
|
expressions: null | Set<BoxedExpression>;
|
|
1593
1703
|
highwaterMark: number;
|
|
1594
1704
|
}
|
|
1595
|
-
|
|
1705
|
+
/** @category Compute Engine */
|
|
1706
|
+
export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: IComputeEngine, args: any) => BoxedExpression) | undefined;
|
|
1707
|
+
/** @category Compute Engine */
|
|
1596
1708
|
export type ArrayValue = boolean | number | string | Decimal | Complex | BoxedExpression | undefined;
|
|
1597
1709
|
/** @internal */
|
|
1598
1710
|
export interface IComputeEngine {
|
|
@@ -1636,13 +1748,12 @@ export interface IComputeEngine {
|
|
|
1636
1748
|
* @internal
|
|
1637
1749
|
*/
|
|
1638
1750
|
deadline?: number;
|
|
1639
|
-
/** @
|
|
1751
|
+
/** @hidden */
|
|
1640
1752
|
readonly timeLimit: number;
|
|
1641
|
-
/** @
|
|
1753
|
+
/** @hidden */
|
|
1642
1754
|
readonly iterationLimit: number;
|
|
1643
|
-
/** @
|
|
1755
|
+
/** @hidden */
|
|
1644
1756
|
readonly recursionLimit: number;
|
|
1645
|
-
/** {@inheritDoc NumericMode} */
|
|
1646
1757
|
numericMode: NumericMode;
|
|
1647
1758
|
tolerance: number;
|
|
1648
1759
|
chop(n: number): number;
|
|
@@ -1656,16 +1767,8 @@ export interface IComputeEngine {
|
|
|
1656
1767
|
set precision(p: number | 'machine');
|
|
1657
1768
|
get precision(): number;
|
|
1658
1769
|
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
1770
|
strict: boolean;
|
|
1664
|
-
/** Return a canonical version of an array of semi-boxed-expressions. */
|
|
1665
1771
|
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
1772
|
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
|
|
1670
1773
|
canonical?: boolean | CanonicalForm | CanonicalForm[];
|
|
1671
1774
|
}): BoxedExpression;
|
|
@@ -1698,7 +1801,6 @@ export interface IComputeEngine {
|
|
|
1698
1801
|
tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1699
1802
|
array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
|
|
1700
1803
|
rules(rules: Rule[]): BoxedRuleSet;
|
|
1701
|
-
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
1702
1804
|
/**
|
|
1703
1805
|
* This is a primitive to create a boxed function.
|
|
1704
1806
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.24.0 */
|
|
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.
|
|
1
|
+
/* 0.24.0 */
|
|
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,3 +1,3 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare const version = "0.
|
|
1
|
+
/* 0.24.0 */
|
|
2
|
+
export declare const version = "0.24.0";
|
|
3
3
|
export { ComputeEngine } from './compute-engine/compute-engine';
|