@cortex-js/compute-engine 0.4.3 → 0.6.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 -3
- package/dist/compute-engine.esm.js +18900 -18332
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +44 -6141
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.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 +8 -7
- package/dist/types/compute-engine/boxed-expression/box.d.ts +3 -5
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +32 -6
- 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 +7 -3
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -6
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +3 -3
- package/dist/types/compute-engine/compute-engine.d.ts +101 -50
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +2 -2
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/core.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- 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-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.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-sets.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 -2
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -13
- package/dist/types/compute-engine/latex-syntax/public.d.ts +69 -44
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +3 -5
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +551 -228
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.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/sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +3 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +3 -4
- package/dist/types/math-json.d.ts +3 -4
- package/package.json +17 -18
- package/dist/compute-engine.js +0 -23523
- package/dist/math-json.js +0 -6339
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
|
+
* The most important classes are {@link ComputeEngine} and
|
|
3
|
+
* {@link BoxedExpression}.
|
|
4
|
+
*
|
|
5
|
+
* With `ComputeEngine` you create `BoxedExpression` objects. With
|
|
6
|
+
* `BoxedExpression` you simplify, evaluate and serialize expressions.
|
|
7
|
+
*
|
|
8
|
+
* @module ComputeEngine
|
|
9
|
+
*/
|
|
10
|
+
import type { Decimal } from 'decimal.js';
|
|
2
11
|
import type { Complex } from 'complex.js';
|
|
3
|
-
import { SignalMessage, WarningSignal, WarningSignalHandler } from '../common/signals';
|
|
4
|
-
import { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
5
|
-
import { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from '
|
|
6
|
-
export
|
|
7
|
-
export declare const DEBUG = true;
|
|
12
|
+
import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../common/signals';
|
|
13
|
+
import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
14
|
+
import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
15
|
+
export * from './latex-syntax/public';
|
|
8
16
|
/**
|
|
9
|
-
* Metadata that can be associated with a BoxedExpression
|
|
17
|
+
* Metadata that can be associated with a `BoxedExpression`
|
|
10
18
|
*/
|
|
11
19
|
export declare type Metadata = {
|
|
12
20
|
latex?: string;
|
|
@@ -15,32 +23,45 @@ export declare type Metadata = {
|
|
|
15
23
|
/**
|
|
16
24
|
* The numeric evaluation mode:
|
|
17
25
|
*
|
|
18
|
-
* - `machine`: 64-bit float, **IEEE 754-2008**, 52-bit, about 15 digits of precision
|
|
19
|
-
* - `decimal`: arbitrary precision floating point numbers
|
|
20
|
-
* - `complex`: complex number represented by two machine numbers, a real and
|
|
21
|
-
* an imaginary part
|
|
22
26
|
* - `auto`: use machine number if precision is 15 or less, allow complex numbers.
|
|
27
|
+
* - `machine`: 64-bit float, **IEEE 754-2008**, 64-bit float, 52-bit mantissa,
|
|
28
|
+
* about 15 digits of precision
|
|
29
|
+
* - `decimal`: arbitrary precision floating point numbers, as provided by the
|
|
30
|
+
* "decimal.js" library
|
|
31
|
+
* - `complex`: complex number represented by two machine numbers, a real and
|
|
32
|
+
* an imaginary part, as provided by the "complex.js" library
|
|
23
33
|
*/
|
|
24
34
|
export declare type NumericMode = 'auto' | 'machine' | 'decimal' | 'complex';
|
|
25
|
-
/** Options for `
|
|
35
|
+
/** Options for `BoxedExpression.simplify()`
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
26
38
|
export declare type SimplifyOptions = EvaluateOptions & {
|
|
27
39
|
recursive?: boolean;
|
|
28
40
|
rules?: BoxedRuleSet;
|
|
29
41
|
};
|
|
30
|
-
/** Options for `
|
|
42
|
+
/** Options for `BoxedExpression.evaluate()`
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
31
46
|
export declare type EvaluateOptions = {};
|
|
32
|
-
/** Options for `
|
|
47
|
+
/** Options for `BoxedExpression.N()`
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
33
50
|
export declare type NOptions = {};
|
|
34
51
|
export declare type ReplaceOptions = {
|
|
35
52
|
/** If true, apply replacement rules to all sub-expressions.
|
|
36
53
|
* If false, only consider the top-level expression.
|
|
37
54
|
*
|
|
38
|
-
* **Default**: true
|
|
55
|
+
* **Default**: `true`
|
|
56
|
+
*/
|
|
39
57
|
recursive?: boolean;
|
|
40
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* If true, stop after the first rule that matches.
|
|
60
|
+
*
|
|
41
61
|
* If false, apply all the remaining rules even after the first match.
|
|
42
62
|
*
|
|
43
|
-
* **Default**: true
|
|
63
|
+
* **Default**: `true`
|
|
64
|
+
*/
|
|
44
65
|
once?: boolean;
|
|
45
66
|
/**
|
|
46
67
|
* If `iterationLimit` > 1, the rules will be repeatedly applied
|
|
@@ -48,7 +69,7 @@ export declare type ReplaceOptions = {
|
|
|
48
69
|
*
|
|
49
70
|
* Note that if `once` is true, `maxIterations` has no effect.
|
|
50
71
|
*
|
|
51
|
-
* **Default**: 1
|
|
72
|
+
* **Default**: `1`
|
|
52
73
|
*/
|
|
53
74
|
iterationLimit?: number;
|
|
54
75
|
};
|
|
@@ -70,8 +91,8 @@ export declare type LatexString = string;
|
|
|
70
91
|
* A rule describes how to modify an expressions that matches a `lhs` pattern
|
|
71
92
|
* into a new expressions matching `rhs`.
|
|
72
93
|
*
|
|
73
|
-
* `x-1`
|
|
74
|
-
* `(x+1)(x-1)`
|
|
94
|
+
* `x-1` \( \to \) `1-x`
|
|
95
|
+
* `(x+1)(x-1)` \( \to \) `x^2-1
|
|
75
96
|
*
|
|
76
97
|
* The `lhs` can be expressed as a LaTeX string or a MathJSON expression.
|
|
77
98
|
*
|
|
@@ -101,13 +122,62 @@ export declare type BoxedRule = [
|
|
|
101
122
|
condition: undefined | ((wildcards: Substitution) => boolean)
|
|
102
123
|
];
|
|
103
124
|
export declare type BoxedRuleSet = Set<BoxedRule>;
|
|
125
|
+
export declare type ParametricDomainFunction = 'Function' | 'Union' | 'List' | 'Record' | 'Tuple' | 'Intersection' | 'Range' | 'Interval' | 'Optional' | 'Some' | 'Head' | 'Symbol' | 'Literal';
|
|
126
|
+
export declare type ParametricDomain = [
|
|
127
|
+
ParametricDomainFunction,
|
|
128
|
+
...DomainExpression[]
|
|
129
|
+
];
|
|
130
|
+
export declare type DomainExpression = string | ParametricDomain;
|
|
104
131
|
/**
|
|
105
132
|
* Domains can be defined as a union or intersection of domains:
|
|
106
133
|
* - `["Union", "Number", "Boolean"]` A number or a boolean.
|
|
107
134
|
* - `["SetMinus", "Number", 1]` Any number except "1".
|
|
108
135
|
*
|
|
109
136
|
*/
|
|
110
|
-
export
|
|
137
|
+
export interface Domain extends BoxedExpression {
|
|
138
|
+
isSubdomainOf(dom: Domain | string): boolean;
|
|
139
|
+
isMemberOf(expr: BoxedExpression): boolean;
|
|
140
|
+
readonly domainExpression: DomainExpression;
|
|
141
|
+
codomain: Domain | null;
|
|
142
|
+
readonly isNothing: boolean;
|
|
143
|
+
is(s: BoxedExpression): boolean;
|
|
144
|
+
readonly isBoolean: boolean;
|
|
145
|
+
readonly isNumeric: boolean;
|
|
146
|
+
readonly isFunction: boolean;
|
|
147
|
+
readonly isPredicate: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* If true, when all the arguments are numeric, the result of the
|
|
150
|
+
* evaluation is numeric. Numeric is any value with a domain of `Number`.
|
|
151
|
+
*
|
|
152
|
+
* Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
|
|
153
|
+
*
|
|
154
|
+
* Default: false
|
|
155
|
+
*/
|
|
156
|
+
readonly isNumericFunction: boolean;
|
|
157
|
+
readonly isRealFunction: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* If true, when all the arguments are boolean, the result of the
|
|
160
|
+
* evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
|
|
161
|
+
*
|
|
162
|
+
* Example of logic functions: `And`, `Or`, `Not`, `Implies`
|
|
163
|
+
*
|
|
164
|
+
* **Default:** false
|
|
165
|
+
*/
|
|
166
|
+
readonly isLogicOperator: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* The function represent a relation between the first argument and
|
|
169
|
+
* the second argument, and evaluates to a boolean indicating if the relation
|
|
170
|
+
* is satisfied.
|
|
171
|
+
*
|
|
172
|
+
* For example, `Equal`, `Less`, `Approx`, etc...
|
|
173
|
+
*
|
|
174
|
+
* **Default:** false
|
|
175
|
+
*/
|
|
176
|
+
readonly isRelationalOperator: boolean;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Options to control the serialization to MathJSON when using `BoxedExpression.json`.
|
|
180
|
+
*/
|
|
111
181
|
export declare type JsonSerializationOptions = {
|
|
112
182
|
/** A list of space separated function names that should be excluded from
|
|
113
183
|
* the JSON output.
|
|
@@ -131,13 +201,13 @@ export declare type JsonSerializationOptions = {
|
|
|
131
201
|
* included in the MathJSON. If metadata is included, shorthand notation
|
|
132
202
|
* is not used.
|
|
133
203
|
*
|
|
134
|
-
* **Default**: `[]`
|
|
204
|
+
* **Default**: `[]` (none)
|
|
135
205
|
*/
|
|
136
206
|
metadata: ('all' | 'wikidata' | 'latex')[];
|
|
137
207
|
/** If true, repeating decimals are detected and serialized accordingly
|
|
138
208
|
* For example:
|
|
139
|
-
* - `1.3333333333333333`
|
|
140
|
-
* - `0.142857142857142857142857142857142857142857142857142`
|
|
209
|
+
* - `1.3333333333333333` \( \to \) `1.(3)`
|
|
210
|
+
* - `0.142857142857142857142857142857142857142857142857142` \( \to \) `0.(1428571)`
|
|
141
211
|
*
|
|
142
212
|
* **Default**: `true`
|
|
143
213
|
*/
|
|
@@ -146,12 +216,12 @@ export declare type JsonSerializationOptions = {
|
|
|
146
216
|
/**
|
|
147
217
|
* **Theory of Operations**
|
|
148
218
|
*
|
|
149
|
-
* The `BoxedExpression` interface includes most of the
|
|
150
|
-
* to any kind of expression, for example `get
|
|
151
|
-
* `get
|
|
219
|
+
* The `BoxedExpression` interface includes most of the member functions
|
|
220
|
+
* applicable to any kind of expression, for example `get symbol()` or
|
|
221
|
+
* `get ops()`.
|
|
152
222
|
*
|
|
153
|
-
* When
|
|
154
|
-
* `BoxedNumber`,
|
|
223
|
+
* When a member function is not applicable to this `BoxedExpression`,
|
|
224
|
+
* for example `get symbol()` on a `BoxedNumber`, it returns `null`.
|
|
155
225
|
*
|
|
156
226
|
* This convention makes it convenient to manipulate expressions without
|
|
157
227
|
* having to check what kind of instance they are before manipulating them.
|
|
@@ -163,19 +233,43 @@ export interface BoxedExpression {
|
|
|
163
233
|
* and functions.
|
|
164
234
|
*/
|
|
165
235
|
readonly engine: IComputeEngine;
|
|
166
|
-
/** From Object.valueOf()
|
|
236
|
+
/** From `Object.valueOf()`, return a primitive value for the expression.
|
|
237
|
+
*
|
|
238
|
+
* If the expression is a machine number, or a Decimal that can be
|
|
239
|
+
* converted to a machine number, return a `number`.
|
|
240
|
+
*
|
|
241
|
+
* If the expression is a rational number, return `[number, number]`.
|
|
242
|
+
*
|
|
243
|
+
* If the expression is a symbol, return the name of the symbol as a `string`.
|
|
244
|
+
*
|
|
245
|
+
* Otherwise return a LaTeX representation of the expression.
|
|
246
|
+
*
|
|
247
|
+
* @category Object Methods
|
|
248
|
+
*/
|
|
167
249
|
valueOf(): number | string | [number, number];
|
|
168
|
-
/** From Object.toString()
|
|
250
|
+
/** From `Object.toString()`, return a LaTeX representation of the expression.
|
|
251
|
+
*
|
|
252
|
+
* @category Object Methods
|
|
253
|
+
*/
|
|
169
254
|
toString(): string;
|
|
170
|
-
/** From Object.toJSON()
|
|
255
|
+
/** From `Object.toJSON()`, equivalent to `JSON.stringify(this.json)`
|
|
256
|
+
*
|
|
257
|
+
* @category Object Methods
|
|
258
|
+
*/
|
|
171
259
|
toJSON(): string;
|
|
172
|
-
/** From Object.is()
|
|
173
|
-
|
|
260
|
+
/** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
|
|
261
|
+
*
|
|
262
|
+
* @category Object Methods
|
|
263
|
+
*
|
|
264
|
+
*/
|
|
265
|
+
is(rhs: unknown): boolean;
|
|
266
|
+
/** @internal */
|
|
174
267
|
get hash(): number;
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
268
|
+
/** An optional short description of the symbol or function head.
|
|
269
|
+
*
|
|
270
|
+
* May include markdown. Each string is a paragraph. */
|
|
177
271
|
readonly description: string[];
|
|
178
|
-
/**
|
|
272
|
+
/** An optional URL pointing to more information about the symbol or function head */
|
|
179
273
|
readonly url: string;
|
|
180
274
|
/** All boxed expressions have a head.
|
|
181
275
|
*
|
|
@@ -186,16 +280,16 @@ export interface BoxedExpression {
|
|
|
186
280
|
*/
|
|
187
281
|
get head(): BoxedExpression | string;
|
|
188
282
|
/**
|
|
189
|
-
* If `
|
|
283
|
+
* If `this.isPure` is `true`, this is a synonym for `this.evaluate()`.
|
|
190
284
|
* Otherwise, it returns `undefined`.
|
|
191
285
|
*/
|
|
192
286
|
get value(): BoxedExpression | undefined;
|
|
193
287
|
/** Only the value of variables can be changed (symbols that are not constants) */
|
|
194
|
-
set value(value: BoxedExpression | undefined);
|
|
288
|
+
set value(value: BoxedExpression | number | undefined);
|
|
195
289
|
/** Return an approximation of the value of this expression. Floating-point
|
|
196
290
|
* operations may be performed.
|
|
197
291
|
*
|
|
198
|
-
* Just like `
|
|
292
|
+
* Just like `this.value`, it returns `undefined` for impure expressions.
|
|
199
293
|
*/
|
|
200
294
|
get numericValue(): BoxedExpression | undefined;
|
|
201
295
|
/** If true, the value of the expression never changes and evaluating it has
|
|
@@ -203,8 +297,8 @@ export interface BoxedExpression {
|
|
|
203
297
|
* If false, the value of the expression may change, if the
|
|
204
298
|
* value of other expression changes or for other reasons.
|
|
205
299
|
*
|
|
206
|
-
* If `
|
|
207
|
-
* `
|
|
300
|
+
* If `this.isPure` is `false`, `this.value` is undefined. Call
|
|
301
|
+
* `this.evaluate()` to determine the value of the expression instead.
|
|
208
302
|
*
|
|
209
303
|
* As an example, the `Random` function is not pure.
|
|
210
304
|
*/
|
|
@@ -218,25 +312,76 @@ export interface BoxedExpression {
|
|
|
218
312
|
get isLiteral(): boolean;
|
|
219
313
|
/** If `true`, this expression is in a canonical form */
|
|
220
314
|
get isCanonical(): boolean;
|
|
221
|
-
/** For internal use only, set when a canonical expression is created.
|
|
315
|
+
/** For internal use only, set when a canonical expression is created.
|
|
316
|
+
* @internal
|
|
317
|
+
*/
|
|
222
318
|
set isCanonical(val: boolean);
|
|
223
|
-
/** `ops` is the list of arguments of the function, its "tail"
|
|
319
|
+
/** `ops` is the list of arguments of the function, its "tail"
|
|
320
|
+
*
|
|
321
|
+
* @category Function Expression
|
|
322
|
+
*
|
|
323
|
+
*/
|
|
224
324
|
get ops(): null | BoxedExpression[];
|
|
225
|
-
/** If a function, the number of operands, otherwise 0.
|
|
325
|
+
/** If this expression is a function, the number of operands, otherwise 0.
|
|
226
326
|
*
|
|
227
327
|
* Note that a function can have 0 operands, so to check if this expression
|
|
228
|
-
* is a function, check if `
|
|
328
|
+
* is a function, check if `this.ops !== null` instead.
|
|
329
|
+
*
|
|
330
|
+
* @category Function Expression
|
|
331
|
+
*
|
|
332
|
+
*/
|
|
229
333
|
get nops(): number;
|
|
230
|
-
/** First operand, i.e
|
|
334
|
+
/** First operand, i.e.`this.ops[0]`
|
|
335
|
+
*
|
|
336
|
+
*
|
|
337
|
+
* @category Function Expression
|
|
338
|
+
*
|
|
339
|
+
*
|
|
340
|
+
*/
|
|
231
341
|
get op1(): BoxedExpression;
|
|
232
|
-
/** Second operand, i.e
|
|
342
|
+
/** Second operand, i.e.`this.ops[0]`
|
|
343
|
+
*
|
|
344
|
+
*
|
|
345
|
+
* @category Function Expression
|
|
346
|
+
*
|
|
347
|
+
*
|
|
348
|
+
*/
|
|
233
349
|
get op2(): BoxedExpression;
|
|
234
|
-
/** Third operand, i.e.
|
|
350
|
+
/** Third operand, i.e. `this.ops[2]`
|
|
351
|
+
*
|
|
352
|
+
*
|
|
353
|
+
* @category Function Expression
|
|
354
|
+
*
|
|
355
|
+
*
|
|
356
|
+
*/
|
|
235
357
|
get op3(): BoxedExpression;
|
|
236
|
-
/** The keys of the dictionary.
|
|
358
|
+
/** The keys of the dictionary.
|
|
359
|
+
*
|
|
360
|
+
* If this expression not a dictionary, return `null`
|
|
361
|
+
*
|
|
362
|
+
* @category Dictionary Expression
|
|
363
|
+
*
|
|
364
|
+
*/
|
|
237
365
|
get keys(): IterableIterator<string> | null;
|
|
366
|
+
/**
|
|
367
|
+
*
|
|
368
|
+
* @category Dictionary Expression
|
|
369
|
+
*/
|
|
238
370
|
get keysCount(): number;
|
|
371
|
+
/**
|
|
372
|
+
* If this expression is a dictionary, return the value of the `key` entry.
|
|
373
|
+
*
|
|
374
|
+
* @category Dictionary Expression
|
|
375
|
+
*
|
|
376
|
+
*/
|
|
239
377
|
getKey(key: string): BoxedExpression | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* If this expression is a dictionary, return true if the dictionary has a
|
|
380
|
+
* `key` entry.
|
|
381
|
+
*
|
|
382
|
+
* @category Dictionary Expression
|
|
383
|
+
*
|
|
384
|
+
*/
|
|
240
385
|
hasKey(key: string): boolean;
|
|
241
386
|
/**
|
|
242
387
|
* Return the value of this number or symbol, if stored as a machine number.
|
|
@@ -247,6 +392,8 @@ export interface BoxedExpression {
|
|
|
247
392
|
* If `machineValue` is not `null`, then `decimalValue`, `rationalValue`
|
|
248
393
|
* and `complexValue` are `null.
|
|
249
394
|
*
|
|
395
|
+
* @category Numeric Expression
|
|
396
|
+
*
|
|
250
397
|
*/
|
|
251
398
|
get machineValue(): number | null;
|
|
252
399
|
/** If the value of this expression is a rational number, return it.
|
|
@@ -254,6 +401,9 @@ export interface BoxedExpression {
|
|
|
254
401
|
*
|
|
255
402
|
* If `rationalValue` is not `[null, null]`, then `machineValue`, `decimalValue`
|
|
256
403
|
* and `complexValue` are `null.
|
|
404
|
+
*
|
|
405
|
+
* @category Numeric Expression
|
|
406
|
+
*
|
|
257
407
|
*/
|
|
258
408
|
get rationalValue(): [numer: number, denom: number] | [null, null];
|
|
259
409
|
/** If the value of this expression is a `Decimal` number, return it.
|
|
@@ -263,6 +413,9 @@ export interface BoxedExpression {
|
|
|
263
413
|
*
|
|
264
414
|
* If `decimalValue` is not `null`, then `machineValue`
|
|
265
415
|
* and `complexValue` are `null` and `rationalValue` is `[null, null]`.
|
|
416
|
+
*
|
|
417
|
+
* @category Numeric Expression
|
|
418
|
+
*
|
|
266
419
|
*/
|
|
267
420
|
get decimalValue(): Decimal | null;
|
|
268
421
|
/** If the value of this expression is a `Complex` number, return it.
|
|
@@ -271,6 +424,9 @@ export interface BoxedExpression {
|
|
|
271
424
|
* If `complexValue` is not `null`, then `machineValue`, `rationalValue`
|
|
272
425
|
* and `decimalValue` are `null.
|
|
273
426
|
*
|
|
427
|
+
* @category Numeric Expression
|
|
428
|
+
*
|
|
429
|
+
*
|
|
274
430
|
*/
|
|
275
431
|
get complexValue(): Complex | null;
|
|
276
432
|
/** Return an approximation of the numeric value of this expression as
|
|
@@ -289,6 +445,9 @@ export interface BoxedExpression {
|
|
|
289
445
|
* If the value of this expression cannot be represented by a float,
|
|
290
446
|
* return `null`.
|
|
291
447
|
*
|
|
448
|
+
* @category Numeric Expression
|
|
449
|
+
*
|
|
450
|
+
*
|
|
292
451
|
*/
|
|
293
452
|
get asFloat(): number | null;
|
|
294
453
|
/**
|
|
@@ -300,57 +459,85 @@ export interface BoxedExpression {
|
|
|
300
459
|
* to check for this, whether the value is a Decimal or a number.
|
|
301
460
|
*
|
|
302
461
|
* By default, "small" is less than 10,000.
|
|
462
|
+
*
|
|
463
|
+
* @category Numeric Expression
|
|
464
|
+
*
|
|
303
465
|
*/
|
|
304
466
|
get asSmallInteger(): number | null;
|
|
305
467
|
/**
|
|
306
468
|
* If the value of this an expression is a small integer or a rational,
|
|
307
469
|
* return this value. Otherwise, return `[null, null`].
|
|
470
|
+
*
|
|
471
|
+
* @category Numeric Expression
|
|
472
|
+
*
|
|
308
473
|
*/
|
|
309
474
|
get asRational(): [number, number] | [null, null];
|
|
310
475
|
/**
|
|
311
476
|
* Return the following, depending on the value of this expression:
|
|
312
477
|
*
|
|
313
|
-
* * `-1
|
|
314
|
-
* * `0
|
|
315
|
-
* * `+1
|
|
316
|
-
* * `undefined
|
|
478
|
+
* * `-1` if it is < 0
|
|
479
|
+
* * `0` if it is = 0
|
|
480
|
+
* * `+1` if it is > 0
|
|
481
|
+
* * `undefined` this value may be positive, negative or zero. We don't know
|
|
317
482
|
* right now (a symbol with an Integer domain, but no currently assigned
|
|
318
483
|
* value, for example)
|
|
319
|
-
* * `null
|
|
484
|
+
* * `null` this value will never be positive, negative or zero (`NaN`,
|
|
320
485
|
* a string or a complex number for example)
|
|
321
486
|
*
|
|
322
487
|
* Note that complex numbers have no natural ordering,
|
|
323
488
|
* so if the value is a complex number, `sgn` is either 0, or `null`
|
|
324
489
|
*
|
|
325
|
-
* If a symbol, this does take assumptions into account, that is `
|
|
490
|
+
* If a symbol, this does take assumptions into account, that is `this.sgn` will return
|
|
326
491
|
* `1` if `isPositive` is `true`, even if this expression has no value
|
|
492
|
+
*
|
|
493
|
+
* @category Numeric Expression
|
|
494
|
+
*
|
|
327
495
|
*/
|
|
328
496
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
329
497
|
/** If this expression is a symbol, return the name of the symbol as a string.
|
|
330
|
-
* Otherwise, return `null`.
|
|
498
|
+
* Otherwise, return `null`.
|
|
499
|
+
*
|
|
500
|
+
* @category Symbol Expression
|
|
501
|
+
*
|
|
502
|
+
*/
|
|
331
503
|
get symbol(): string | null;
|
|
332
|
-
/** Shortcut for `this.symbol ===
|
|
504
|
+
/** Shortcut for `this.symbol === "Missing"`
|
|
505
|
+
*
|
|
506
|
+
* @category Symbol Expression
|
|
507
|
+
*
|
|
508
|
+
*/
|
|
333
509
|
get isMissing(): boolean;
|
|
334
510
|
/** If this expression is a string, return the value of the string.
|
|
335
511
|
* Otherwise, return `null`.
|
|
512
|
+
*
|
|
513
|
+
* @category String Expression
|
|
514
|
+
*
|
|
336
515
|
*/
|
|
337
516
|
get string(): string | null;
|
|
338
|
-
/** True if this domain is a subset of domain d */
|
|
339
|
-
isSubsetOf(d: BoxedExpression | string): undefined | boolean;
|
|
340
517
|
/** True if the value of this expression is a number.
|
|
341
518
|
*
|
|
342
519
|
* `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
|
|
343
520
|
*
|
|
344
521
|
* Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
|
|
345
522
|
* is a number.
|
|
523
|
+
*
|
|
524
|
+
* @category Expression Properties
|
|
346
525
|
*/
|
|
347
526
|
get isNumber(): boolean | undefined;
|
|
348
|
-
/** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
|
|
527
|
+
/** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
|
|
528
|
+
*
|
|
529
|
+
*
|
|
530
|
+
* @category Expression Properties
|
|
531
|
+
*
|
|
532
|
+
*/
|
|
349
533
|
get isInteger(): boolean | undefined;
|
|
350
534
|
/** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
|
|
351
535
|
*
|
|
352
536
|
* Note that every integer is also a rational.
|
|
353
537
|
*
|
|
538
|
+
*
|
|
539
|
+
* @category Expression Properties
|
|
540
|
+
*
|
|
354
541
|
*/
|
|
355
542
|
get isRational(): boolean | undefined;
|
|
356
543
|
/**
|
|
@@ -361,17 +548,26 @@ export interface BoxedExpression {
|
|
|
361
548
|
*
|
|
362
549
|
* Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
|
|
363
550
|
*
|
|
551
|
+
*
|
|
552
|
+
* @category Expression Properties
|
|
553
|
+
*
|
|
364
554
|
*/
|
|
365
555
|
get isAlgebraic(): boolean | undefined;
|
|
366
556
|
/**
|
|
367
557
|
* The value of this expression is real number: finite and not imaginary.
|
|
368
558
|
*
|
|
369
559
|
* `isFinite && !isImaginary`
|
|
560
|
+
*
|
|
561
|
+
*
|
|
562
|
+
* @category Expression Properties
|
|
370
563
|
*/
|
|
371
564
|
get isReal(): boolean | undefined;
|
|
372
565
|
/** Real or ±Infinity
|
|
373
566
|
*
|
|
374
567
|
* `isReal || isInfinity`
|
|
568
|
+
*
|
|
569
|
+
*
|
|
570
|
+
* @category Expression Properties
|
|
375
571
|
*/
|
|
376
572
|
get isExtendedReal(): boolean | undefined;
|
|
377
573
|
/**
|
|
@@ -379,50 +575,100 @@ export interface BoxedExpression {
|
|
|
379
575
|
*
|
|
380
576
|
* `isReal || isImaginary`
|
|
381
577
|
*
|
|
578
|
+
*
|
|
579
|
+
* @category Expression Properties
|
|
580
|
+
*
|
|
382
581
|
*/
|
|
383
582
|
get isComplex(): boolean | undefined;
|
|
384
|
-
/** `isReal || isImaginary || isInfinity`
|
|
583
|
+
/** `isReal || isImaginary || isInfinity`
|
|
584
|
+
*
|
|
585
|
+
*
|
|
586
|
+
* @category Expression Properties
|
|
587
|
+
*/
|
|
385
588
|
get isExtendedComplex(): boolean | undefined;
|
|
386
|
-
/** The value of this expression is a number with a imaginary part
|
|
589
|
+
/** The value of this expression is a number with a imaginary part
|
|
590
|
+
*
|
|
591
|
+
*
|
|
592
|
+
* @category Expression Properties
|
|
593
|
+
*/
|
|
387
594
|
get isImaginary(): boolean | undefined;
|
|
595
|
+
/**
|
|
596
|
+
* @category Expression Properties
|
|
597
|
+
*/
|
|
388
598
|
get isZero(): boolean | undefined;
|
|
599
|
+
/**
|
|
600
|
+
* @category Expression Properties
|
|
601
|
+
*/
|
|
389
602
|
get isNotZero(): boolean | undefined;
|
|
603
|
+
/**
|
|
604
|
+
* @category Expression Properties
|
|
605
|
+
*/
|
|
390
606
|
get isOne(): boolean | undefined;
|
|
607
|
+
/**
|
|
608
|
+
* @category Expression Properties
|
|
609
|
+
*/
|
|
391
610
|
get isNegativeOne(): boolean | undefined;
|
|
392
|
-
/** ±Infinity or Complex Infinity
|
|
611
|
+
/** ±Infinity or Complex Infinity
|
|
612
|
+
*
|
|
613
|
+
* @category Expression Properties
|
|
614
|
+
*/
|
|
393
615
|
get isInfinity(): boolean | undefined;
|
|
394
616
|
/**
|
|
395
617
|
* "Not a Number".
|
|
396
618
|
*
|
|
397
619
|
* A value representing undefined result of computations, such as `0/0`,
|
|
398
|
-
* as per the
|
|
620
|
+
* as per the floating point format standard IEEE-754.
|
|
621
|
+
*
|
|
622
|
+
* Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
|
|
623
|
+
* number).
|
|
399
624
|
*
|
|
400
|
-
*
|
|
625
|
+
* @category Expression Properties
|
|
401
626
|
*
|
|
402
627
|
*/
|
|
403
628
|
get isNaN(): boolean | undefined;
|
|
404
|
-
/** Not ±Infinity and not NaN
|
|
629
|
+
/** Not ±Infinity and not `NaN`
|
|
630
|
+
*
|
|
631
|
+
* @category Expression Properties
|
|
632
|
+
*/
|
|
405
633
|
get isFinite(): boolean | undefined;
|
|
634
|
+
/**
|
|
635
|
+
* @category Expression Properties
|
|
636
|
+
*/
|
|
406
637
|
get isEven(): boolean | undefined;
|
|
638
|
+
/**
|
|
639
|
+
* @category Expression Properties
|
|
640
|
+
*/
|
|
407
641
|
get isOdd(): boolean | undefined;
|
|
642
|
+
/**
|
|
643
|
+
* @category Expression Properties
|
|
644
|
+
*/
|
|
408
645
|
get isPrime(): boolean | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* @category Expression Properties
|
|
648
|
+
*/
|
|
409
649
|
get isComposite(): boolean | undefined;
|
|
410
650
|
/** Structural/symbolic equality (weak equality).
|
|
411
651
|
*
|
|
412
|
-
* `ce.parse('1+x').isSame(ce.parse('x+1'))` is `
|
|
652
|
+
* `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
|
|
413
653
|
*
|
|
654
|
+
* @category Relational Operator
|
|
414
655
|
*/
|
|
415
656
|
isSame(rhs: BoxedExpression): boolean;
|
|
416
657
|
/**
|
|
417
|
-
* True if the expression includes a symbol `v
|
|
658
|
+
* True if the expression includes a symbol `v` or a function head `v`.
|
|
418
659
|
*/
|
|
419
660
|
has(v: string | string[]): boolean;
|
|
420
|
-
/** Attempt to match this
|
|
661
|
+
/** Attempt to match this expression to the `rhs` expression.
|
|
421
662
|
*
|
|
422
663
|
* If `rhs` does not match, return `null`.
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
664
|
+
*
|
|
665
|
+
* Otherwise return an object literal.
|
|
666
|
+
*
|
|
667
|
+
* If this expression includes wildcards (symbols with a name that starts
|
|
668
|
+
* with `_`), the object literal will include a prop for each matching named
|
|
669
|
+
* wildcard.
|
|
670
|
+
*
|
|
671
|
+
* If `rhs` matches this pattern but there are no named wildcards, return
|
|
426
672
|
* the empty object literal, `{}`.
|
|
427
673
|
*/
|
|
428
674
|
match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
|
|
@@ -432,22 +678,48 @@ export interface BoxedExpression {
|
|
|
432
678
|
* Both expressions are numerically evaluated.
|
|
433
679
|
*
|
|
434
680
|
* Numbers whose difference is less than `engine.tolerance` are
|
|
435
|
-
* considered equal. This
|
|
681
|
+
* considered equal. This tolerance is set when the `engine.precision` is
|
|
436
682
|
* changed to be such that the last two digits are ignored.
|
|
683
|
+
*
|
|
684
|
+
* @category Relational Operator
|
|
437
685
|
*/
|
|
438
686
|
isEqual(rhs: BoxedExpression): boolean;
|
|
439
|
-
/** If the expressions cannot be compared, `undefined` is returned
|
|
687
|
+
/** If the expressions cannot be compared, `undefined` is returned
|
|
688
|
+
*
|
|
689
|
+
* @category Relational Operator
|
|
690
|
+
*/
|
|
440
691
|
isLess(rhs: BoxedExpression): boolean | undefined;
|
|
692
|
+
/**
|
|
693
|
+
* @category Relational Operator
|
|
694
|
+
*/
|
|
441
695
|
isLessEqual(rhs: BoxedExpression): boolean | undefined;
|
|
696
|
+
/**
|
|
697
|
+
* @category Relational Operator
|
|
698
|
+
*/
|
|
442
699
|
isGreater(rhs: BoxedExpression): boolean | undefined;
|
|
700
|
+
/**
|
|
701
|
+
* @category Relational Operator
|
|
702
|
+
*/
|
|
443
703
|
isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
|
|
444
|
-
/** The value of this expression is > 0, same as `isGreater(0)`
|
|
704
|
+
/** The value of this expression is > 0, same as `isGreater(0)`
|
|
705
|
+
*
|
|
706
|
+
* @category Expression Properties
|
|
707
|
+
*/
|
|
445
708
|
get isPositive(): boolean | undefined;
|
|
446
|
-
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
709
|
+
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
710
|
+
*
|
|
711
|
+
* @category Expression Properties
|
|
712
|
+
*/
|
|
447
713
|
get isNonNegative(): boolean | undefined;
|
|
448
|
-
/** The value of this expression is < 0, same as `isLess(0)`
|
|
714
|
+
/** The value of this expression is < 0, same as `isLess(0)`
|
|
715
|
+
*
|
|
716
|
+
* @category Expression Properties
|
|
717
|
+
*/
|
|
449
718
|
get isNegative(): boolean | undefined;
|
|
450
|
-
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
719
|
+
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
720
|
+
*
|
|
721
|
+
* @category Expression Properties
|
|
722
|
+
*/
|
|
451
723
|
get isNonPositive(): boolean | undefined;
|
|
452
724
|
/** Wikidata identifier */
|
|
453
725
|
get wikidata(): string;
|
|
@@ -461,11 +733,17 @@ export interface BoxedExpression {
|
|
|
461
733
|
* first in commutative functions
|
|
462
734
|
*/
|
|
463
735
|
get complexity(): number;
|
|
464
|
-
/** The domain of this expression
|
|
465
|
-
|
|
466
|
-
get domain(): BoxedExpression;
|
|
736
|
+
/** The domain of this expression. */
|
|
737
|
+
get domain(): Domain;
|
|
467
738
|
/** Symbols that represent a variable, can have their domain modified */
|
|
468
|
-
set domain(domain:
|
|
739
|
+
set domain(domain: Domain | string);
|
|
740
|
+
/** The domain of the value of this expression, using the value of the expression,
|
|
741
|
+
* definitions associated with this expression and assumptions if necessary.
|
|
742
|
+
*
|
|
743
|
+
* For symbols, the `domain` and `valueDomain` are the same. For functions,
|
|
744
|
+
* the `valueDomain` is the codomain of the function.
|
|
745
|
+
*/
|
|
746
|
+
get valueDomain(): Domain;
|
|
469
747
|
/** For symbols and functions, a possible definition associated with the expression */
|
|
470
748
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
471
749
|
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
@@ -519,22 +797,22 @@ export interface BoxedExpression {
|
|
|
519
797
|
* The expression is first converted to canonical form.
|
|
520
798
|
*
|
|
521
799
|
* A pure expression always return the same value and has no side effects.
|
|
522
|
-
* If `
|
|
523
|
-
* For an impure expression, `
|
|
800
|
+
* If `this.isPure` is `true`, `this.value` and `this.evaluate()` are synonyms.
|
|
801
|
+
* For an impure expression, `this.value` is undefined.
|
|
524
802
|
*
|
|
525
803
|
* Evaluating an impure expression may have some side effects, for
|
|
526
804
|
* example modifying the `ComputeEngine` environment, such as its set of assumptions.
|
|
527
805
|
*
|
|
528
806
|
* Only exact calculations are performed, no floating point calculations.
|
|
529
|
-
* To perform approximate floating point calculations, use `N()` instead.
|
|
807
|
+
* To perform approximate floating point calculations, use `this.N()` instead.
|
|
530
808
|
*
|
|
531
|
-
* The result of `
|
|
809
|
+
* The result of `this.evaluate()` may be the same as `this.simplify()`.
|
|
532
810
|
*
|
|
533
811
|
* The result is in canonical form.
|
|
534
812
|
*
|
|
535
813
|
*/
|
|
536
814
|
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
537
|
-
/** Return a
|
|
815
|
+
/** Return a numeric approximation of this expression.
|
|
538
816
|
*
|
|
539
817
|
* The expression is first converted to canonical form.
|
|
540
818
|
*
|
|
@@ -542,7 +820,10 @@ export interface BoxedExpression {
|
|
|
542
820
|
* are performed. The calculations are performed according
|
|
543
821
|
* to the `numericMode` and `precision` properties of the `ComputeEngine`.
|
|
544
822
|
*
|
|
545
|
-
*
|
|
823
|
+
* To only perform exact calculations, use `this.evaluate()` instead.
|
|
824
|
+
*
|
|
825
|
+
* If the function is not numeric, the result of `this.N()` is the same as
|
|
826
|
+
* `this.evaluate()`.
|
|
546
827
|
*
|
|
547
828
|
* The result is in canonical form.
|
|
548
829
|
*/
|
|
@@ -564,13 +845,15 @@ export interface BoxedExpression {
|
|
|
564
845
|
* the matching `lhs` of a rule is replaced by its `rhs`.
|
|
565
846
|
*
|
|
566
847
|
* If no rules apply, return `null`.
|
|
848
|
+
*
|
|
849
|
+
* See also `subs` for a simple substitution.
|
|
567
850
|
*/
|
|
568
851
|
replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
|
|
569
852
|
/**
|
|
570
853
|
* Replace all the symbols in the expression as indicated.
|
|
571
854
|
*
|
|
572
|
-
* Note the same effect can be achieved with `
|
|
573
|
-
* this is more efficient, and simpler.
|
|
855
|
+
* Note the same effect can be achieved with `this.replace()`, but
|
|
856
|
+
* using `this.subs()` is more efficient, and simpler.
|
|
574
857
|
*
|
|
575
858
|
*/
|
|
576
859
|
subs(sub: Substitution): BoxedExpression;
|
|
@@ -578,10 +861,13 @@ export interface BoxedExpression {
|
|
|
578
861
|
* Update the definition associated with this expression, taking
|
|
579
862
|
* into account the current context.
|
|
580
863
|
*
|
|
581
|
-
*
|
|
864
|
+
* @internal
|
|
582
865
|
*/
|
|
583
866
|
_repairDefinition(): void;
|
|
584
|
-
/** Purge any cached values
|
|
867
|
+
/** Purge any cached values.
|
|
868
|
+
*
|
|
869
|
+
* @internal
|
|
870
|
+
*/
|
|
585
871
|
_purge(): undefined;
|
|
586
872
|
}
|
|
587
873
|
/** A semi boxed expression is an MathJSON expression which can include some
|
|
@@ -601,6 +887,7 @@ export declare type PatternMatchOption = {
|
|
|
601
887
|
export interface Pattern extends BoxedExpression {
|
|
602
888
|
/**
|
|
603
889
|
* If `expr` does not match the pattern, return `null`.
|
|
890
|
+
*
|
|
604
891
|
* Otherwise, return a substitution describing the values that the named
|
|
605
892
|
* wildcard in the pattern should be changed to in order for the pattern to be
|
|
606
893
|
* equal to the expression. If there are no named wildcards and the expression
|
|
@@ -664,17 +951,27 @@ export declare type Scope = {
|
|
|
664
951
|
warn?: WarningSignalHandler;
|
|
665
952
|
/** Signal `timeout` when the execution time for this scope is exceeded.
|
|
666
953
|
* Time in seconds, default 2s.
|
|
954
|
+
*
|
|
955
|
+
* @experimental
|
|
667
956
|
*/
|
|
668
957
|
timeLimit?: number;
|
|
669
958
|
/** Signal `out-of-memory` when the memory usage for this scope is exceeded.
|
|
670
959
|
* Memory in Megabytes, default: 1Mb.
|
|
960
|
+
*
|
|
961
|
+
* @experimental
|
|
671
962
|
*/
|
|
672
963
|
memoryLimit?: number;
|
|
673
964
|
/** Signal `recursion-depth-exceeded` when the recursion depth for this
|
|
674
|
-
* scope is exceeded.
|
|
965
|
+
* scope is exceeded.
|
|
966
|
+
*
|
|
967
|
+
* @experimental
|
|
968
|
+
*/
|
|
675
969
|
recursionLimit?: number;
|
|
676
970
|
/** Signal `iteration-limit-exceeded` when the iteration limit for this
|
|
677
|
-
* scope is exceeded. Default: no limits
|
|
971
|
+
* scope is exceeded. Default: no limits.
|
|
972
|
+
*
|
|
973
|
+
* @experimental
|
|
974
|
+
*/
|
|
678
975
|
iterationLimit?: number;
|
|
679
976
|
};
|
|
680
977
|
export declare type RuntimeScope = Scope & {
|
|
@@ -717,12 +1014,21 @@ export declare type BaseDefinition = {
|
|
|
717
1014
|
wikidata?: string;
|
|
718
1015
|
/**
|
|
719
1016
|
* The domain of this item.
|
|
720
|
-
*
|
|
721
|
-
* For
|
|
1017
|
+
*
|
|
1018
|
+
* For dictionaries, this is the domain of all the items in the dictionary.
|
|
1019
|
+
*
|
|
1020
|
+
* For strings, it's always 'String'.
|
|
1021
|
+
*
|
|
722
1022
|
* For symbols, this is the domain of their value.
|
|
723
|
-
*
|
|
1023
|
+
*
|
|
1024
|
+
* For functions, this is the signature of the function
|
|
1025
|
+
*
|
|
1026
|
+
* When `domain` is a handler, calculate the domain (or signature) based on
|
|
1027
|
+
* the arguments (for expressions others than functions, `args` is an empty
|
|
1028
|
+
* array). If the function cannot be applied to the arguments, return
|
|
1029
|
+
* `null`.
|
|
724
1030
|
*/
|
|
725
|
-
domain?: BoxedExpression |
|
|
1031
|
+
domain?: Domain | DomainExpression | string | ((ce: IComputeEngine, args: BoxedExpression[]) => Domain | DomainExpression);
|
|
726
1032
|
};
|
|
727
1033
|
export declare type BoxedBaseDefinition = {
|
|
728
1034
|
name: string;
|
|
@@ -735,7 +1041,7 @@ export declare type BoxedBaseDefinition = {
|
|
|
735
1041
|
* This field is usually undefined, but its value is set by `getDefinition()`
|
|
736
1042
|
*/
|
|
737
1043
|
scope: RuntimeScope | undefined;
|
|
738
|
-
domain?: BoxedExpression;
|
|
1044
|
+
domain?: Domain | ((ce: IComputeEngine, args: BoxedExpression[]) => Domain | DomainExpression);
|
|
739
1045
|
_purge(): undefined;
|
|
740
1046
|
};
|
|
741
1047
|
/**
|
|
@@ -746,86 +1052,58 @@ export declare type FunctionDefinitionFlags = {
|
|
|
746
1052
|
/** If true, the function is applied element by element to lists, matrices
|
|
747
1053
|
* and equations.
|
|
748
1054
|
*
|
|
749
|
-
* Default
|
|
1055
|
+
* **Default**: `false`
|
|
750
1056
|
*/
|
|
751
1057
|
threadable: boolean;
|
|
752
|
-
/** If true, [f, [f, a], b] simplifies to [f, a, b]
|
|
1058
|
+
/** If true, `["f", ["f", a], b]` simplifies to `["f", a, b]`
|
|
753
1059
|
*
|
|
754
|
-
* Default
|
|
1060
|
+
* **Default**: `false`
|
|
755
1061
|
*/
|
|
756
1062
|
associative: boolean;
|
|
757
|
-
/** If true, `[f, a, b]` equals `[f, b, a]`. The canonical
|
|
1063
|
+
/** If true, `["f", a, b]` equals `["f", b, a]`. The canonical
|
|
758
1064
|
* version of the function will order the arguments.
|
|
759
1065
|
*
|
|
760
|
-
* Default
|
|
1066
|
+
* **Default**: `false`
|
|
761
1067
|
*/
|
|
762
1068
|
commutative: boolean;
|
|
763
|
-
/** If true, when the function is univariate, `[f, ["Add", x, c]]` where `c`
|
|
764
|
-
* is constant, is simplified to `["Add", [f, x], c]`.
|
|
1069
|
+
/** If true, when the function is univariate, `["f", ["Add", x, c]]` where `c`
|
|
1070
|
+
* is constant, is simplified to `["Add", ["f", x], c]`.
|
|
765
1071
|
*
|
|
766
1072
|
* When the function is multivariate, additivity is considered only on the
|
|
767
|
-
* first argument: `[f, ["Add", x, c], y]` simplifies to `["Add", [f, x, y], c]`.
|
|
1073
|
+
* first argument: `["f", ["Add", x, c], y]` simplifies to `["Add", ["f", x, y], c]`.
|
|
768
1074
|
*
|
|
769
|
-
* For example, `
|
|
1075
|
+
* For example, `Log` is additive.
|
|
770
1076
|
*
|
|
771
|
-
* Default
|
|
1077
|
+
* **Default**: `false`
|
|
772
1078
|
*/
|
|
773
|
-
/** If true, when the function is univariate, `[f, ["Multiply", x, y]]`
|
|
774
|
-
* simplifies to `["Multiply", [f, x], [f, y]]`.
|
|
1079
|
+
/** If true, when the function is univariate, `["f", ["Multiply", x, y]]`
|
|
1080
|
+
* simplifies to `["Multiply", ["f", x], ["f", y]]`.
|
|
775
1081
|
*
|
|
776
1082
|
* When the function is multivariate, multiplicativity is considered only on the
|
|
777
|
-
* first argument: `[f, ["Multiply", x, y], z]` simplifies to
|
|
778
|
-
* `["Multiply", [f, x, z], [f, y, z]]`
|
|
1083
|
+
* first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1084
|
+
* `["Multiply", ["f", x, z], ["f", y, z]]`
|
|
779
1085
|
*
|
|
780
|
-
* Default
|
|
1086
|
+
* **Default**: `false`
|
|
781
1087
|
*/
|
|
782
|
-
/** If true, when the function is univariate, `[f, ["Multiply", x, c]]`
|
|
783
|
-
* simplifies to `["Multiply", [f, x], c]` where `c` is constant
|
|
1088
|
+
/** If true, when the function is univariate, `["f", ["Multiply", x, c]]`
|
|
1089
|
+
* simplifies to `["Multiply", ["f", x], c]` where `c` is constant
|
|
784
1090
|
*
|
|
785
1091
|
* When the function is multivariate, multiplicativity is considered only on the
|
|
786
|
-
* first argument: `[f, ["Multiply", x, y], z]` simplifies to
|
|
787
|
-
* `["Multiply", [f, x, z], [f, y, z]]`
|
|
1092
|
+
* first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1093
|
+
* `["Multiply", ["f", x, z], ["f", y, z]]`
|
|
788
1094
|
*
|
|
789
|
-
* Default: false
|
|
1095
|
+
* Default: `false`
|
|
790
1096
|
*/
|
|
791
|
-
/** If true, `[f, [f, x]]` simplifies to `[f, x]`.
|
|
1097
|
+
/** If true, `["f", ["f", x]]` simplifies to `["f", x]`.
|
|
792
1098
|
*
|
|
793
|
-
* Default
|
|
1099
|
+
* **Default**: `false`
|
|
794
1100
|
*/
|
|
795
1101
|
idempotent: boolean;
|
|
796
|
-
/** If true, `[f, [f, x]]` simplifies to `x`.
|
|
1102
|
+
/** If true, `["f", ["f", x]]` simplifies to `x`.
|
|
797
1103
|
*
|
|
798
|
-
* Default
|
|
1104
|
+
* **Default**: `false`
|
|
799
1105
|
*/
|
|
800
1106
|
involution: boolean;
|
|
801
|
-
/**
|
|
802
|
-
* If true, when all the arguments are numeric, the result of the
|
|
803
|
-
* evaluation is numeric. Numeric is any value with a domain of `Number`.
|
|
804
|
-
*
|
|
805
|
-
* Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
|
|
806
|
-
*
|
|
807
|
-
* Default: false
|
|
808
|
-
*/
|
|
809
|
-
numeric: boolean;
|
|
810
|
-
/**
|
|
811
|
-
* If true, when all the arguments are boolean, the result of the
|
|
812
|
-
* evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
|
|
813
|
-
*
|
|
814
|
-
* Example of logic functions: `And`, `Or`, `Not`, `Implies`
|
|
815
|
-
*
|
|
816
|
-
* **Default:** false
|
|
817
|
-
*/
|
|
818
|
-
logic: boolean;
|
|
819
|
-
/**
|
|
820
|
-
* The function represent a relation between the first argument and
|
|
821
|
-
* the second argument, and evaluates to a boolean indicating if the relation
|
|
822
|
-
* is satisfied.
|
|
823
|
-
*
|
|
824
|
-
* For example, `Equal`, `Less`, `Approx`, etc...
|
|
825
|
-
*
|
|
826
|
-
* **Default:** false
|
|
827
|
-
*/
|
|
828
|
-
relationalOperator: boolean;
|
|
829
1107
|
/** If true, the value of this function is always the same for a given
|
|
830
1108
|
* set of arguments and it has no side effects.
|
|
831
1109
|
*
|
|
@@ -849,35 +1127,35 @@ export declare type FunctionDefinitionFlags = {
|
|
|
849
1127
|
inert: boolean;
|
|
850
1128
|
};
|
|
851
1129
|
/**
|
|
852
|
-
*
|
|
1130
|
+
* Definition record for a function.
|
|
853
1131
|
*
|
|
854
1132
|
*/
|
|
855
1133
|
export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
856
1134
|
/**
|
|
857
|
-
* A number used to order
|
|
858
|
-
* complexity are placed after
|
|
859
|
-
* ordered canonically.
|
|
860
|
-
*
|
|
861
|
-
* Additive functions: 1000-1999
|
|
862
|
-
* Multiplicative functions: 2000-2999
|
|
863
|
-
* Root and power functions: 3000-3999
|
|
864
|
-
* Log functions: 4000-4999
|
|
865
|
-
* Trigonometric functions: 5000-5999
|
|
866
|
-
* Hypertrigonometric functions: 6000-6999
|
|
867
|
-
* Special functions (factorial, Gamma, ...): 7000-7999
|
|
868
|
-
* Collections: 8000-8999
|
|
869
|
-
* Inert and styling: 9000-9999
|
|
870
|
-
* Logic: 10000-10999
|
|
871
|
-
* Relational: 11000-11999
|
|
872
|
-
*
|
|
873
|
-
* **Default**: 100,000
|
|
1135
|
+
* A number used to order arguments. Argument with higher
|
|
1136
|
+
* complexity are placed after arguments with lower complexity when
|
|
1137
|
+
* ordered canonically in commutative functions.
|
|
1138
|
+
*
|
|
1139
|
+
* - Additive functions: 1000-1999
|
|
1140
|
+
* - Multiplicative functions: 2000-2999
|
|
1141
|
+
* - Root and power functions: 3000-3999
|
|
1142
|
+
* - Log functions: 4000-4999
|
|
1143
|
+
* - Trigonometric functions: 5000-5999
|
|
1144
|
+
* - Hypertrigonometric functions: 6000-6999
|
|
1145
|
+
* - Special functions (factorial, Gamma, ...): 7000-7999
|
|
1146
|
+
* - Collections: 8000-8999
|
|
1147
|
+
* - Inert and styling: 9000-9999
|
|
1148
|
+
* - Logic: 10000-10999
|
|
1149
|
+
* - Relational: 11000-11999
|
|
1150
|
+
*
|
|
1151
|
+
* **Default**: 100,000
|
|
874
1152
|
*/
|
|
875
1153
|
complexity?: number;
|
|
876
1154
|
/**
|
|
877
|
-
* - `none
|
|
878
|
-
* - `all
|
|
879
|
-
* - `first
|
|
880
|
-
* - `rest
|
|
1155
|
+
* - `none` Each of the arguments is evaluated (default)
|
|
1156
|
+
* - `all` None of the arguments are evaluated and they are passed as is
|
|
1157
|
+
* - `first` The first argument is not evaluated, the others are
|
|
1158
|
+
* - `rest` The first argument is evaluated, the others aren't
|
|
881
1159
|
*/
|
|
882
1160
|
hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
883
1161
|
/**
|
|
@@ -926,12 +1204,12 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
926
1204
|
* `arg.isPositive`.
|
|
927
1205
|
*
|
|
928
1206
|
* Even though a symbol may not have a value, there may be some information
|
|
929
|
-
* about it reflected for example in `
|
|
1207
|
+
* about it reflected for example in `this.isZero` or `this.isPrime`.
|
|
930
1208
|
*
|
|
931
1209
|
* The handler should not perform approximate numeric calculations, such
|
|
932
1210
|
* as calculations involving floating point numbers. Making exact
|
|
933
1211
|
* calculations on integers or rationals is OK. It is recommended, but not
|
|
934
|
-
* required, that the calculations be limited to `
|
|
1212
|
+
* required, that the calculations be limited to `this.smallIntegerValue`
|
|
935
1213
|
* (i.e. numeric representations of the expression as an integer of small
|
|
936
1214
|
* magnitude).
|
|
937
1215
|
*
|
|
@@ -959,12 +1237,12 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
959
1237
|
*/
|
|
960
1238
|
evaluate?: LambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
961
1239
|
/**
|
|
962
|
-
* Evaluate numerically
|
|
1240
|
+
* Evaluate numerically an expression.
|
|
963
1241
|
*
|
|
964
|
-
* The arguments
|
|
1242
|
+
* The arguments `args` have been simplified and evaluated, numerically
|
|
965
1243
|
* if possible, except the arguments to which a `hold` apply.
|
|
966
1244
|
*
|
|
967
|
-
* The arguments
|
|
1245
|
+
* The arguments may be a combination of numbers, symbolic
|
|
968
1246
|
* expressions and other expressions.
|
|
969
1247
|
*
|
|
970
1248
|
* Perform as many calculations as possible, and return the result.
|
|
@@ -982,13 +1260,13 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
982
1260
|
* number, but complex numbers are not allowed (the `engine.numericMode`
|
|
983
1261
|
* is not `complex` or `auto`).
|
|
984
1262
|
*
|
|
985
|
-
* If the `
|
|
1263
|
+
* If the `ce.numericMode` is `auto` or `complex`, you may return
|
|
986
1264
|
* a Complex number as a result. Otherwise, if the result is a complex
|
|
987
1265
|
* value, return `NaN`. If Complex are not allowed, none of the arguments
|
|
988
1266
|
* will be complex literals.
|
|
989
1267
|
*
|
|
990
|
-
* If the `
|
|
991
|
-
* `
|
|
1268
|
+
* If the `ce.numericMode` is `decimal` or `auto` and
|
|
1269
|
+
* `this.engine.precision` is > 15, you may return a Decimal number.
|
|
992
1270
|
* Otherwise, return a `machine` number approximation. If Decimal are
|
|
993
1271
|
* not allowed, none of the arguments will be Decimal literal.
|
|
994
1272
|
*
|
|
@@ -997,32 +1275,9 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
997
1275
|
*
|
|
998
1276
|
*/
|
|
999
1277
|
N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1000
|
-
/**
|
|
1001
|
-
*
|
|
1002
|
-
* Calculate the domain of the result, based on the value of the arguments.
|
|
1003
|
-
*
|
|
1004
|
-
* If the domain of the result is always the same, use the `domain` property
|
|
1005
|
-
* instead.
|
|
1006
|
-
*
|
|
1007
|
-
* The argument `args` represent the arguments of the function.
|
|
1008
|
-
*
|
|
1009
|
-
* The return value is `null` if the input arguments cannot be handled by
|
|
1010
|
-
* this definition.
|
|
1011
|
-
*
|
|
1012
|
-
* Otherwise, the return value is the domain of the result.
|
|
1013
|
-
*
|
|
1014
|
-
* Return `Nothing` if the arguments are acceptable, but the evaluation
|
|
1015
|
-
* will fail, for example in some cases if there are missing arguments.
|
|
1016
|
-
*
|
|
1017
|
-
* This function is used to select the correct definition when there are
|
|
1018
|
-
* multiple definitions for the same function name.
|
|
1019
|
-
*
|
|
1020
|
-
* For example it allows to distinguish between a `Add` function that
|
|
1021
|
-
* applies to numbers and an `Add` function that applies to tensors.
|
|
1022
|
-
*
|
|
1278
|
+
/** Dimensional analysis
|
|
1279
|
+
* @experimental
|
|
1023
1280
|
*/
|
|
1024
|
-
evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
|
|
1025
|
-
/** Dimensional analysis */
|
|
1026
1281
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1027
1282
|
/** Return the sign of the function given a list of arguments. */
|
|
1028
1283
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
@@ -1038,13 +1293,13 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
|
|
|
1038
1293
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1039
1294
|
evaluate?: BoxedLambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
1040
1295
|
N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1041
|
-
evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
|
|
1042
1296
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1043
1297
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
1044
1298
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1045
1299
|
};
|
|
1046
1300
|
/**
|
|
1047
1301
|
* When used in a `SymbolDefinition`, these flags are optional.
|
|
1302
|
+
*
|
|
1048
1303
|
* If provided, they will override the value derived from
|
|
1049
1304
|
* the symbol's value.
|
|
1050
1305
|
*
|
|
@@ -1103,7 +1358,7 @@ export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & P
|
|
|
1103
1358
|
* `Pi`, the actual value depends on the `precision` setting of the
|
|
1104
1359
|
* `ComputeEngine` */
|
|
1105
1360
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1106
|
-
domain?: string |
|
|
1361
|
+
domain?: string | Domain;
|
|
1107
1362
|
};
|
|
1108
1363
|
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
|
|
1109
1364
|
get value(): BoxedExpression | undefined;
|
|
@@ -1121,38 +1376,65 @@ export interface ComputeEngineStats {
|
|
|
1121
1376
|
expressions: null | Set<BoxedExpression>;
|
|
1122
1377
|
highwaterMark: number;
|
|
1123
1378
|
}
|
|
1379
|
+
/** @internal */
|
|
1124
1380
|
export interface IComputeEngine {
|
|
1381
|
+
/** @internal */
|
|
1125
1382
|
readonly ZERO: BoxedExpression;
|
|
1383
|
+
/** @internal */
|
|
1126
1384
|
readonly ONE: BoxedExpression;
|
|
1385
|
+
/** @internal */
|
|
1127
1386
|
readonly TWO: BoxedExpression;
|
|
1387
|
+
/** @internal */
|
|
1128
1388
|
readonly HALF: BoxedExpression;
|
|
1389
|
+
/** @internal */
|
|
1129
1390
|
readonly NEGATIVE_ONE: BoxedExpression;
|
|
1391
|
+
/** @internal */
|
|
1130
1392
|
readonly I: BoxedExpression;
|
|
1393
|
+
/** @internal */
|
|
1131
1394
|
readonly NAN: BoxedExpression;
|
|
1395
|
+
/** @internal */
|
|
1132
1396
|
readonly POSITIVE_INFINITY: BoxedExpression;
|
|
1397
|
+
/** @internal */
|
|
1133
1398
|
readonly NEGATIVE_INFINITY: BoxedExpression;
|
|
1399
|
+
/** @internal */
|
|
1134
1400
|
readonly COMPLEX_INFINITY: BoxedExpression;
|
|
1401
|
+
/** @internal */
|
|
1135
1402
|
readonly DECIMAL_NAN: Decimal;
|
|
1403
|
+
/** @internal */
|
|
1136
1404
|
readonly DECIMAL_ZERO: Decimal;
|
|
1405
|
+
/** @internal */
|
|
1137
1406
|
readonly DECIMAL_ONE: Decimal;
|
|
1407
|
+
/** @internal */
|
|
1138
1408
|
readonly DECIMAL_TWO: Decimal;
|
|
1409
|
+
/** @internal */
|
|
1139
1410
|
readonly DECIMAL_HALF: Decimal;
|
|
1411
|
+
/** @internal */
|
|
1140
1412
|
readonly DECIMAL_PI: Decimal;
|
|
1413
|
+
/** @internal */
|
|
1141
1414
|
readonly DECIMAL_NEGATIVE_ONE: Decimal;
|
|
1415
|
+
/** The current scope */
|
|
1142
1416
|
context: RuntimeScope;
|
|
1143
|
-
/** Absolute time beyond which evaluation should not proceed
|
|
1417
|
+
/** Absolute time beyond which evaluation should not proceed
|
|
1418
|
+
* @internal
|
|
1419
|
+
*/
|
|
1144
1420
|
deadline?: number;
|
|
1421
|
+
/** @experimental */
|
|
1145
1422
|
readonly timeLimit: number;
|
|
1423
|
+
/** @experimental */
|
|
1146
1424
|
readonly iterationLimit: number;
|
|
1425
|
+
/** @experimental */
|
|
1147
1426
|
readonly recursionLimit: number;
|
|
1148
|
-
|
|
1427
|
+
defaultDomain: null | Domain;
|
|
1428
|
+
/** {@inheritDoc NumericMode} */
|
|
1149
1429
|
numericMode: NumericMode;
|
|
1150
1430
|
tolerance: number;
|
|
1151
1431
|
chop(n: number): number;
|
|
1152
1432
|
chop(n: Decimal): Decimal | 0;
|
|
1153
1433
|
chop(n: Complex): Complex | 0;
|
|
1154
1434
|
chop(n: number | Decimal | Complex): number | Decimal | Complex;
|
|
1435
|
+
/** @internal */
|
|
1155
1436
|
decimal: (a: Decimal.Value) => Decimal;
|
|
1437
|
+
/** @internal */
|
|
1156
1438
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
1157
1439
|
set precision(p: number | 'machine');
|
|
1158
1440
|
get precision(): number;
|
|
@@ -1167,7 +1449,7 @@ export interface IComputeEngine {
|
|
|
1167
1449
|
/**
|
|
1168
1450
|
* Return `undefined` if no definition exist for this `head.
|
|
1169
1451
|
*/
|
|
1170
|
-
getFunctionDefinition(head: string,
|
|
1452
|
+
getFunctionDefinition(head: string, args?: BoxedExpression[]): undefined | BoxedFunctionDefinition;
|
|
1171
1453
|
/**
|
|
1172
1454
|
* Returned a boxed expression from the input.
|
|
1173
1455
|
*
|
|
@@ -1181,13 +1463,13 @@ export interface IComputeEngine {
|
|
|
1181
1463
|
/** Return a canonical boxed string */
|
|
1182
1464
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
1183
1465
|
/** Return a canonical boxed domain */
|
|
1184
|
-
domain(domain:
|
|
1466
|
+
domain(domain: SemiBoxedExpression | Domain | string, metadata?: Metadata): Domain;
|
|
1185
1467
|
/** Return a canonical expression.
|
|
1186
1468
|
*
|
|
1187
1469
|
* Note that the result may not be a function, or may have a different
|
|
1188
1470
|
* `head` than the one specified.
|
|
1189
1471
|
*
|
|
1190
|
-
* For example `ce.fn(
|
|
1472
|
+
* For example `ce.fn("Add", [ce.number(2), ce.number(3)]))` \( \to \) 5
|
|
1191
1473
|
*
|
|
1192
1474
|
*/
|
|
1193
1475
|
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
@@ -1202,47 +1484,47 @@ export interface IComputeEngine {
|
|
|
1202
1484
|
* ops canonical, etc..) so that the result is actually canonical.
|
|
1203
1485
|
*/
|
|
1204
1486
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1205
|
-
/** Shortcut for `fn(
|
|
1487
|
+
/** Shortcut for `this.fn("Error"...)`.
|
|
1206
1488
|
*
|
|
1207
1489
|
* The result is canonical.
|
|
1208
1490
|
*/
|
|
1209
1491
|
error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): any;
|
|
1210
|
-
/** Shortcut for `fn(
|
|
1492
|
+
/** Shortcut for `this.fn("Add"...)`.
|
|
1211
1493
|
*
|
|
1212
1494
|
* The result is canonical.
|
|
1213
1495
|
*/
|
|
1214
1496
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1215
|
-
/** Shortcut for `fn(
|
|
1497
|
+
/** Shortcut for `this.fn("Multiply"...)`
|
|
1216
1498
|
*
|
|
1217
1499
|
* The result is canonical.
|
|
1218
1500
|
*/
|
|
1219
1501
|
mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1220
|
-
/** Shortcut for `fn(
|
|
1502
|
+
/** Shortcut for `this.fn("Power"...)`
|
|
1221
1503
|
*
|
|
1222
1504
|
* The result is canonical.
|
|
1223
1505
|
*/
|
|
1224
1506
|
power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1225
|
-
/** Shortcut for `fn(
|
|
1507
|
+
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
1226
1508
|
*
|
|
1227
1509
|
* The result is canonical.
|
|
1228
1510
|
*/
|
|
1229
1511
|
inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1230
|
-
/** Shortcut for `fn(
|
|
1512
|
+
/** Shortcut for `this.fn("Negate", [expr])`
|
|
1231
1513
|
*
|
|
1232
1514
|
* The result is canonical.
|
|
1233
1515
|
*/
|
|
1234
1516
|
negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1235
|
-
/** Shortcut for `fn(
|
|
1517
|
+
/** Shortcut for `this.fn("Divide", [num, denom])`
|
|
1236
1518
|
*
|
|
1237
1519
|
* The result is canonical.
|
|
1238
1520
|
*/
|
|
1239
1521
|
divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1240
|
-
/** Shortcut for `fn(
|
|
1522
|
+
/** Shortcut for `this.fn("Pair"...)`
|
|
1241
1523
|
*
|
|
1242
1524
|
* The result is canonical.
|
|
1243
1525
|
*/
|
|
1244
1526
|
pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1245
|
-
/** Shortcut for `fn(
|
|
1527
|
+
/** Shortcut for `this.fn("Tuple"...)`
|
|
1246
1528
|
*
|
|
1247
1529
|
* The result is canonical.
|
|
1248
1530
|
*/
|
|
@@ -1255,18 +1537,47 @@ export interface IComputeEngine {
|
|
|
1255
1537
|
* The result may not be canonical.
|
|
1256
1538
|
*
|
|
1257
1539
|
*/
|
|
1258
|
-
parse(s:
|
|
1540
|
+
parse(s: LatexString | string): BoxedExpression;
|
|
1541
|
+
parse(s: null): null;
|
|
1542
|
+
parse(s: LatexString | string | null): null | BoxedExpression;
|
|
1259
1543
|
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
1260
1544
|
* a LaTeX string
|
|
1261
1545
|
*/
|
|
1262
1546
|
serialize(expr: SemiBoxedExpression): LatexString;
|
|
1263
|
-
|
|
1264
|
-
|
|
1547
|
+
/**
|
|
1548
|
+
* Options to control the serailization of MathJSON expression to LaTeX
|
|
1549
|
+
* when using `this.latex` or `this.engine.serialize()`.
|
|
1550
|
+
*
|
|
1551
|
+
*
|
|
1552
|
+
* {@inheritDoc NumberFormattingOptions}
|
|
1553
|
+
* {@inheritDoc ParseLatexOptions}
|
|
1554
|
+
* {@inheritDoc SerializeLatexOptions}
|
|
1555
|
+
*
|
|
1556
|
+
*/
|
|
1557
|
+
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
1558
|
+
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
1559
|
+
/** {@inheritDoc JsonSerializationOptions} */
|
|
1265
1560
|
get jsonSerializationOptions(): JsonSerializationOptions;
|
|
1266
1561
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1267
|
-
|
|
1562
|
+
/**
|
|
1563
|
+
* Add an assumption.
|
|
1564
|
+
*
|
|
1565
|
+
* Note that the assumption is put into canonical form before being added.
|
|
1566
|
+
*
|
|
1567
|
+
* @param symbol - The symbol to make an assumption about
|
|
1568
|
+
*
|
|
1569
|
+
* Returns:
|
|
1570
|
+
* - `contradiction` if the new assumption is incompatible with previous
|
|
1571
|
+
* ones.
|
|
1572
|
+
* - `tautology` if the new assumption is redundant with previous ones.
|
|
1573
|
+
* - `ok` if the assumption was successfully added to the assumption set.
|
|
1574
|
+
*
|
|
1575
|
+
*
|
|
1576
|
+
*/
|
|
1577
|
+
assume(symbol: LatexString | SemiBoxedExpression, domain: Domain): AssumeResult;
|
|
1268
1578
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
1269
1579
|
assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
|
|
1580
|
+
/** Remove all assumptions about one or more symbols */
|
|
1270
1581
|
forget(symbol?: string | string[]): void;
|
|
1271
1582
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1272
1583
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
@@ -1276,15 +1587,27 @@ export interface IComputeEngine {
|
|
|
1276
1587
|
scope?: Partial<Scope>;
|
|
1277
1588
|
}): void;
|
|
1278
1589
|
popScope(): void;
|
|
1590
|
+
/**
|
|
1591
|
+
* When `condition` is false, signal.
|
|
1592
|
+
*
|
|
1593
|
+
* - `condition` - If `true`, do nothing. If `false`, signal.
|
|
1594
|
+
*
|
|
1595
|
+
* @experimental
|
|
1596
|
+
*/
|
|
1279
1597
|
assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): any;
|
|
1280
1598
|
signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
1281
1599
|
signal(sig: WarningSignal): void;
|
|
1600
|
+
/** @internal */
|
|
1282
1601
|
shouldContinueExecution(): boolean;
|
|
1602
|
+
/** @internal */
|
|
1283
1603
|
checkContinueExecution(): void;
|
|
1604
|
+
/** @internal */
|
|
1284
1605
|
cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
|
|
1285
1606
|
readonly stats: ComputeEngineStats;
|
|
1607
|
+
/** @internal */
|
|
1286
1608
|
purge(): void;
|
|
1609
|
+
/** @internal */
|
|
1287
1610
|
_register(expr: BoxedExpression): void;
|
|
1611
|
+
/** @internal */
|
|
1288
1612
|
_unregister(expr: BoxedExpression): void;
|
|
1289
1613
|
}
|
|
1290
|
-
export declare function getVars(expr: BoxedExpression): string[];
|