@cortex-js/compute-engine 0.4.4 → 0.5.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/dist/compute-engine.esm.js +7057 -7037
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +3 -6142
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
- 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 +3 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.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 +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +87 -43
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +1 -1
- 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 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +46 -20
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -4
- 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 +432 -138
- 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 +2 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +3 -4
- package/package.json +16 -16
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.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
12
|
import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../common/signals';
|
|
4
13
|
import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
5
14
|
import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
6
|
-
export
|
|
15
|
+
export * from './latex-syntax/public';
|
|
7
16
|
/**
|
|
8
|
-
* Metadata that can be associated with a BoxedExpression
|
|
17
|
+
* Metadata that can be associated with a `BoxedExpression`
|
|
9
18
|
*/
|
|
10
19
|
export declare type Metadata = {
|
|
11
20
|
latex?: string;
|
|
@@ -14,32 +23,45 @@ export declare type Metadata = {
|
|
|
14
23
|
/**
|
|
15
24
|
* The numeric evaluation mode:
|
|
16
25
|
*
|
|
17
|
-
* - `machine`: 64-bit float, **IEEE 754-2008**, 52-bit, about 15 digits of precision
|
|
18
|
-
* - `decimal`: arbitrary precision floating point numbers
|
|
19
|
-
* - `complex`: complex number represented by two machine numbers, a real and
|
|
20
|
-
* an imaginary part
|
|
21
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
|
|
22
33
|
*/
|
|
23
34
|
export declare type NumericMode = 'auto' | 'machine' | 'decimal' | 'complex';
|
|
24
|
-
/** Options for `
|
|
35
|
+
/** Options for `BoxedExpression.simplify()`
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
25
38
|
export declare type SimplifyOptions = EvaluateOptions & {
|
|
26
39
|
recursive?: boolean;
|
|
27
40
|
rules?: BoxedRuleSet;
|
|
28
41
|
};
|
|
29
|
-
/** Options for `
|
|
42
|
+
/** Options for `BoxedExpression.evaluate()`
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
30
46
|
export declare type EvaluateOptions = {};
|
|
31
|
-
/** Options for `
|
|
47
|
+
/** Options for `BoxedExpression.N()`
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
32
50
|
export declare type NOptions = {};
|
|
33
51
|
export declare type ReplaceOptions = {
|
|
34
52
|
/** If true, apply replacement rules to all sub-expressions.
|
|
35
53
|
* If false, only consider the top-level expression.
|
|
36
54
|
*
|
|
37
|
-
* **Default**: true
|
|
55
|
+
* **Default**: `true`
|
|
56
|
+
*/
|
|
38
57
|
recursive?: boolean;
|
|
39
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* If true, stop after the first rule that matches.
|
|
60
|
+
*
|
|
40
61
|
* If false, apply all the remaining rules even after the first match.
|
|
41
62
|
*
|
|
42
|
-
* **Default**: true
|
|
63
|
+
* **Default**: `true`
|
|
64
|
+
*/
|
|
43
65
|
once?: boolean;
|
|
44
66
|
/**
|
|
45
67
|
* If `iterationLimit` > 1, the rules will be repeatedly applied
|
|
@@ -47,7 +69,7 @@ export declare type ReplaceOptions = {
|
|
|
47
69
|
*
|
|
48
70
|
* Note that if `once` is true, `maxIterations` has no effect.
|
|
49
71
|
*
|
|
50
|
-
* **Default**: 1
|
|
72
|
+
* **Default**: `1`
|
|
51
73
|
*/
|
|
52
74
|
iterationLimit?: number;
|
|
53
75
|
};
|
|
@@ -69,8 +91,8 @@ export declare type LatexString = string;
|
|
|
69
91
|
* A rule describes how to modify an expressions that matches a `lhs` pattern
|
|
70
92
|
* into a new expressions matching `rhs`.
|
|
71
93
|
*
|
|
72
|
-
* `x-1`
|
|
73
|
-
* `(x+1)(x-1)`
|
|
94
|
+
* `x-1` \( \to \) `1-x`
|
|
95
|
+
* `(x+1)(x-1)` \( \to \) `x^2-1
|
|
74
96
|
*
|
|
75
97
|
* The `lhs` can be expressed as a LaTeX string or a MathJSON expression.
|
|
76
98
|
*
|
|
@@ -107,6 +129,9 @@ export declare type BoxedRuleSet = Set<BoxedRule>;
|
|
|
107
129
|
*
|
|
108
130
|
*/
|
|
109
131
|
export declare type DomainExpression = BoxedExpression;
|
|
132
|
+
/**
|
|
133
|
+
* Options to control the serialization to MathJSON when using `BoxedExpression.json`.
|
|
134
|
+
*/
|
|
110
135
|
export declare type JsonSerializationOptions = {
|
|
111
136
|
/** A list of space separated function names that should be excluded from
|
|
112
137
|
* the JSON output.
|
|
@@ -130,13 +155,13 @@ export declare type JsonSerializationOptions = {
|
|
|
130
155
|
* included in the MathJSON. If metadata is included, shorthand notation
|
|
131
156
|
* is not used.
|
|
132
157
|
*
|
|
133
|
-
* **Default**: `[]`
|
|
158
|
+
* **Default**: `[]` (none)
|
|
134
159
|
*/
|
|
135
160
|
metadata: ('all' | 'wikidata' | 'latex')[];
|
|
136
161
|
/** If true, repeating decimals are detected and serialized accordingly
|
|
137
162
|
* For example:
|
|
138
|
-
* - `1.3333333333333333`
|
|
139
|
-
* - `0.142857142857142857142857142857142857142857142857142`
|
|
163
|
+
* - `1.3333333333333333` \( \to \) `1.(3)`
|
|
164
|
+
* - `0.142857142857142857142857142857142857142857142857142` \( \to \) `0.(1428571)`
|
|
140
165
|
*
|
|
141
166
|
* **Default**: `true`
|
|
142
167
|
*/
|
|
@@ -173,14 +198,26 @@ export interface BoxedExpression {
|
|
|
173
198
|
*
|
|
174
199
|
* Otherwise return a LaTeX representation of the expression.
|
|
175
200
|
*
|
|
201
|
+
* @category Object Methods
|
|
176
202
|
*/
|
|
177
203
|
valueOf(): number | string | [number, number];
|
|
178
|
-
/** From `Object.toString()`, return a LaTeX representation of the expression.
|
|
204
|
+
/** From `Object.toString()`, return a LaTeX representation of the expression.
|
|
205
|
+
*
|
|
206
|
+
* @category Object Methods
|
|
207
|
+
*/
|
|
179
208
|
toString(): string;
|
|
180
|
-
/** From `Object.toJSON()`, equivalent to `JSON.stringify(this.json)`
|
|
209
|
+
/** From `Object.toJSON()`, equivalent to `JSON.stringify(this.json)`
|
|
210
|
+
*
|
|
211
|
+
* @category Object Methods
|
|
212
|
+
*/
|
|
181
213
|
toJSON(): string;
|
|
182
|
-
/** From `Object.is()`. Equivalent to `
|
|
214
|
+
/** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
|
|
215
|
+
*
|
|
216
|
+
* @category Object Methods
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
183
219
|
is(rhs: any): boolean;
|
|
220
|
+
/** @internal */
|
|
184
221
|
get hash(): number;
|
|
185
222
|
/** An optional short description of the symbol or function head.
|
|
186
223
|
*
|
|
@@ -197,7 +234,7 @@ export interface BoxedExpression {
|
|
|
197
234
|
*/
|
|
198
235
|
get head(): BoxedExpression | string;
|
|
199
236
|
/**
|
|
200
|
-
* If `
|
|
237
|
+
* If `this.isPure` is `true`, this is a synonym for `this.evaluate()`.
|
|
201
238
|
* Otherwise, it returns `undefined`.
|
|
202
239
|
*/
|
|
203
240
|
get value(): BoxedExpression | undefined;
|
|
@@ -206,7 +243,7 @@ export interface BoxedExpression {
|
|
|
206
243
|
/** Return an approximation of the value of this expression. Floating-point
|
|
207
244
|
* operations may be performed.
|
|
208
245
|
*
|
|
209
|
-
* Just like `
|
|
246
|
+
* Just like `this.value`, it returns `undefined` for impure expressions.
|
|
210
247
|
*/
|
|
211
248
|
get numericValue(): BoxedExpression | undefined;
|
|
212
249
|
/** If true, the value of the expression never changes and evaluating it has
|
|
@@ -214,8 +251,8 @@ export interface BoxedExpression {
|
|
|
214
251
|
* If false, the value of the expression may change, if the
|
|
215
252
|
* value of other expression changes or for other reasons.
|
|
216
253
|
*
|
|
217
|
-
* If `
|
|
218
|
-
* `
|
|
254
|
+
* If `this.isPure` is `false`, `this.value` is undefined. Call
|
|
255
|
+
* `this.evaluate()` to determine the value of the expression instead.
|
|
219
256
|
*
|
|
220
257
|
* As an example, the `Random` function is not pure.
|
|
221
258
|
*/
|
|
@@ -229,33 +266,75 @@ export interface BoxedExpression {
|
|
|
229
266
|
get isLiteral(): boolean;
|
|
230
267
|
/** If `true`, this expression is in a canonical form */
|
|
231
268
|
get isCanonical(): boolean;
|
|
232
|
-
/** For internal use only, set when a canonical expression is created.
|
|
269
|
+
/** For internal use only, set when a canonical expression is created.
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
233
272
|
set isCanonical(val: boolean);
|
|
234
|
-
/** `ops` is the list of arguments of the function, its "tail"
|
|
273
|
+
/** `ops` is the list of arguments of the function, its "tail"
|
|
274
|
+
*
|
|
275
|
+
* @category Function Expression
|
|
276
|
+
*
|
|
277
|
+
*/
|
|
235
278
|
get ops(): null | BoxedExpression[];
|
|
236
|
-
/** If a function, the number of operands, otherwise 0.
|
|
279
|
+
/** If this expression is a function, the number of operands, otherwise 0.
|
|
237
280
|
*
|
|
238
281
|
* Note that a function can have 0 operands, so to check if this expression
|
|
239
|
-
* is a function, check if `
|
|
282
|
+
* is a function, check if `this.ops !== null` instead.
|
|
283
|
+
*
|
|
284
|
+
* @category Function Expression
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
240
287
|
get nops(): number;
|
|
241
|
-
/** First operand, i.e
|
|
288
|
+
/** First operand, i.e.`this.ops[0]`
|
|
289
|
+
*
|
|
290
|
+
*
|
|
291
|
+
* @category Function Expression
|
|
292
|
+
*
|
|
293
|
+
*
|
|
294
|
+
*/
|
|
242
295
|
get op1(): BoxedExpression;
|
|
243
|
-
/** Second operand, i.e
|
|
296
|
+
/** Second operand, i.e.`this.ops[0]`
|
|
297
|
+
*
|
|
298
|
+
*
|
|
299
|
+
* @category Function Expression
|
|
300
|
+
*
|
|
301
|
+
*
|
|
302
|
+
*/
|
|
244
303
|
get op2(): BoxedExpression;
|
|
245
|
-
/** Third operand, i.e.
|
|
304
|
+
/** Third operand, i.e. `this.ops[2]`
|
|
305
|
+
*
|
|
306
|
+
*
|
|
307
|
+
* @category Function Expression
|
|
308
|
+
*
|
|
309
|
+
*
|
|
310
|
+
*/
|
|
246
311
|
get op3(): BoxedExpression;
|
|
247
312
|
/** The keys of the dictionary.
|
|
248
313
|
*
|
|
249
|
-
* If this expression not a dictionary, return `null`
|
|
314
|
+
* If this expression not a dictionary, return `null`
|
|
315
|
+
*
|
|
316
|
+
* @category Dictionary Expression
|
|
317
|
+
*
|
|
318
|
+
*/
|
|
250
319
|
get keys(): IterableIterator<string> | null;
|
|
320
|
+
/**
|
|
321
|
+
*
|
|
322
|
+
* @category Dictionary Expression
|
|
323
|
+
*/
|
|
251
324
|
get keysCount(): number;
|
|
252
325
|
/**
|
|
253
326
|
* If this expression is a dictionary, return the value of the `key` entry.
|
|
327
|
+
*
|
|
328
|
+
* @category Dictionary Expression
|
|
329
|
+
*
|
|
254
330
|
*/
|
|
255
331
|
getKey(key: string): BoxedExpression | undefined;
|
|
256
332
|
/**
|
|
257
333
|
* If this expression is a dictionary, return true if the dictionary has a
|
|
258
334
|
* `key` entry.
|
|
335
|
+
*
|
|
336
|
+
* @category Dictionary Expression
|
|
337
|
+
*
|
|
259
338
|
*/
|
|
260
339
|
hasKey(key: string): boolean;
|
|
261
340
|
/**
|
|
@@ -267,6 +346,8 @@ export interface BoxedExpression {
|
|
|
267
346
|
* If `machineValue` is not `null`, then `decimalValue`, `rationalValue`
|
|
268
347
|
* and `complexValue` are `null.
|
|
269
348
|
*
|
|
349
|
+
* @category Numeric Expression
|
|
350
|
+
*
|
|
270
351
|
*/
|
|
271
352
|
get machineValue(): number | null;
|
|
272
353
|
/** If the value of this expression is a rational number, return it.
|
|
@@ -274,6 +355,9 @@ export interface BoxedExpression {
|
|
|
274
355
|
*
|
|
275
356
|
* If `rationalValue` is not `[null, null]`, then `machineValue`, `decimalValue`
|
|
276
357
|
* and `complexValue` are `null.
|
|
358
|
+
*
|
|
359
|
+
* @category Numeric Expression
|
|
360
|
+
*
|
|
277
361
|
*/
|
|
278
362
|
get rationalValue(): [numer: number, denom: number] | [null, null];
|
|
279
363
|
/** If the value of this expression is a `Decimal` number, return it.
|
|
@@ -283,6 +367,9 @@ export interface BoxedExpression {
|
|
|
283
367
|
*
|
|
284
368
|
* If `decimalValue` is not `null`, then `machineValue`
|
|
285
369
|
* and `complexValue` are `null` and `rationalValue` is `[null, null]`.
|
|
370
|
+
*
|
|
371
|
+
* @category Numeric Expression
|
|
372
|
+
*
|
|
286
373
|
*/
|
|
287
374
|
get decimalValue(): Decimal | null;
|
|
288
375
|
/** If the value of this expression is a `Complex` number, return it.
|
|
@@ -291,6 +378,9 @@ export interface BoxedExpression {
|
|
|
291
378
|
* If `complexValue` is not `null`, then `machineValue`, `rationalValue`
|
|
292
379
|
* and `decimalValue` are `null.
|
|
293
380
|
*
|
|
381
|
+
* @category Numeric Expression
|
|
382
|
+
*
|
|
383
|
+
*
|
|
294
384
|
*/
|
|
295
385
|
get complexValue(): Complex | null;
|
|
296
386
|
/** Return an approximation of the numeric value of this expression as
|
|
@@ -309,6 +399,9 @@ export interface BoxedExpression {
|
|
|
309
399
|
* If the value of this expression cannot be represented by a float,
|
|
310
400
|
* return `null`.
|
|
311
401
|
*
|
|
402
|
+
* @category Numeric Expression
|
|
403
|
+
*
|
|
404
|
+
*
|
|
312
405
|
*/
|
|
313
406
|
get asFloat(): number | null;
|
|
314
407
|
/**
|
|
@@ -320,42 +413,66 @@ export interface BoxedExpression {
|
|
|
320
413
|
* to check for this, whether the value is a Decimal or a number.
|
|
321
414
|
*
|
|
322
415
|
* By default, "small" is less than 10,000.
|
|
416
|
+
*
|
|
417
|
+
* @category Numeric Expression
|
|
418
|
+
*
|
|
323
419
|
*/
|
|
324
420
|
get asSmallInteger(): number | null;
|
|
325
421
|
/**
|
|
326
422
|
* If the value of this an expression is a small integer or a rational,
|
|
327
423
|
* return this value. Otherwise, return `[null, null`].
|
|
424
|
+
*
|
|
425
|
+
* @category Numeric Expression
|
|
426
|
+
*
|
|
328
427
|
*/
|
|
329
428
|
get asRational(): [number, number] | [null, null];
|
|
330
429
|
/**
|
|
331
430
|
* Return the following, depending on the value of this expression:
|
|
332
431
|
*
|
|
333
|
-
* * `-1
|
|
334
|
-
* * `0
|
|
335
|
-
* * `+1
|
|
336
|
-
* * `undefined
|
|
432
|
+
* * `-1` if it is < 0
|
|
433
|
+
* * `0` if it is = 0
|
|
434
|
+
* * `+1` if it is > 0
|
|
435
|
+
* * `undefined` this value may be positive, negative or zero. We don't know
|
|
337
436
|
* right now (a symbol with an Integer domain, but no currently assigned
|
|
338
437
|
* value, for example)
|
|
339
|
-
* * `null
|
|
438
|
+
* * `null` this value will never be positive, negative or zero (`NaN`,
|
|
340
439
|
* a string or a complex number for example)
|
|
341
440
|
*
|
|
342
441
|
* Note that complex numbers have no natural ordering,
|
|
343
442
|
* so if the value is a complex number, `sgn` is either 0, or `null`
|
|
344
443
|
*
|
|
345
|
-
* If a symbol, this does take assumptions into account, that is `
|
|
444
|
+
* If a symbol, this does take assumptions into account, that is `this.sgn` will return
|
|
346
445
|
* `1` if `isPositive` is `true`, even if this expression has no value
|
|
446
|
+
*
|
|
447
|
+
* @category Numeric Expression
|
|
448
|
+
*
|
|
347
449
|
*/
|
|
348
450
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
349
451
|
/** If this expression is a symbol, return the name of the symbol as a string.
|
|
350
|
-
* Otherwise, return `null`.
|
|
452
|
+
* Otherwise, return `null`.
|
|
453
|
+
*
|
|
454
|
+
* @category Symbol Expression
|
|
455
|
+
*
|
|
456
|
+
*/
|
|
351
457
|
get symbol(): string | null;
|
|
352
|
-
/** Shortcut for `this.symbol ===
|
|
458
|
+
/** Shortcut for `this.symbol === "Missing"`
|
|
459
|
+
*
|
|
460
|
+
* @category Symbol Expression
|
|
461
|
+
*
|
|
462
|
+
*/
|
|
353
463
|
get isMissing(): boolean;
|
|
354
464
|
/** If this expression is a string, return the value of the string.
|
|
355
465
|
* Otherwise, return `null`.
|
|
466
|
+
*
|
|
467
|
+
* @category String Expression
|
|
468
|
+
*
|
|
356
469
|
*/
|
|
357
470
|
get string(): string | null;
|
|
358
|
-
/** True if this domain is a subset of domain `d`
|
|
471
|
+
/** True if this domain is a subset of domain `d`
|
|
472
|
+
*
|
|
473
|
+
* @category Expression Properties
|
|
474
|
+
*
|
|
475
|
+
*/
|
|
359
476
|
isSubsetOf(d: BoxedExpression | string): undefined | boolean;
|
|
360
477
|
/** True if the value of this expression is a number.
|
|
361
478
|
*
|
|
@@ -363,14 +480,24 @@ export interface BoxedExpression {
|
|
|
363
480
|
*
|
|
364
481
|
* Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
|
|
365
482
|
* is a number.
|
|
483
|
+
*
|
|
484
|
+
* @category Expression Properties
|
|
366
485
|
*/
|
|
367
486
|
get isNumber(): boolean | undefined;
|
|
368
|
-
/** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
|
|
487
|
+
/** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
|
|
488
|
+
*
|
|
489
|
+
*
|
|
490
|
+
* @category Expression Properties
|
|
491
|
+
*
|
|
492
|
+
*/
|
|
369
493
|
get isInteger(): boolean | undefined;
|
|
370
494
|
/** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
|
|
371
495
|
*
|
|
372
496
|
* Note that every integer is also a rational.
|
|
373
497
|
*
|
|
498
|
+
*
|
|
499
|
+
* @category Expression Properties
|
|
500
|
+
*
|
|
374
501
|
*/
|
|
375
502
|
get isRational(): boolean | undefined;
|
|
376
503
|
/**
|
|
@@ -381,17 +508,26 @@ export interface BoxedExpression {
|
|
|
381
508
|
*
|
|
382
509
|
* Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
|
|
383
510
|
*
|
|
511
|
+
*
|
|
512
|
+
* @category Expression Properties
|
|
513
|
+
*
|
|
384
514
|
*/
|
|
385
515
|
get isAlgebraic(): boolean | undefined;
|
|
386
516
|
/**
|
|
387
517
|
* The value of this expression is real number: finite and not imaginary.
|
|
388
518
|
*
|
|
389
519
|
* `isFinite && !isImaginary`
|
|
520
|
+
*
|
|
521
|
+
*
|
|
522
|
+
* @category Expression Properties
|
|
390
523
|
*/
|
|
391
524
|
get isReal(): boolean | undefined;
|
|
392
525
|
/** Real or ±Infinity
|
|
393
526
|
*
|
|
394
527
|
* `isReal || isInfinity`
|
|
528
|
+
*
|
|
529
|
+
*
|
|
530
|
+
* @category Expression Properties
|
|
395
531
|
*/
|
|
396
532
|
get isExtendedReal(): boolean | undefined;
|
|
397
533
|
/**
|
|
@@ -399,38 +535,83 @@ export interface BoxedExpression {
|
|
|
399
535
|
*
|
|
400
536
|
* `isReal || isImaginary`
|
|
401
537
|
*
|
|
538
|
+
*
|
|
539
|
+
* @category Expression Properties
|
|
540
|
+
*
|
|
402
541
|
*/
|
|
403
542
|
get isComplex(): boolean | undefined;
|
|
404
|
-
/** `isReal || isImaginary || isInfinity`
|
|
543
|
+
/** `isReal || isImaginary || isInfinity`
|
|
544
|
+
*
|
|
545
|
+
*
|
|
546
|
+
* @category Expression Properties
|
|
547
|
+
*/
|
|
405
548
|
get isExtendedComplex(): boolean | undefined;
|
|
406
|
-
/** The value of this expression is a number with a imaginary part
|
|
549
|
+
/** The value of this expression is a number with a imaginary part
|
|
550
|
+
*
|
|
551
|
+
*
|
|
552
|
+
* @category Expression Properties
|
|
553
|
+
*/
|
|
407
554
|
get isImaginary(): boolean | undefined;
|
|
555
|
+
/**
|
|
556
|
+
* @category Expression Properties
|
|
557
|
+
*/
|
|
408
558
|
get isZero(): boolean | undefined;
|
|
559
|
+
/**
|
|
560
|
+
* @category Expression Properties
|
|
561
|
+
*/
|
|
409
562
|
get isNotZero(): boolean | undefined;
|
|
563
|
+
/**
|
|
564
|
+
* @category Expression Properties
|
|
565
|
+
*/
|
|
410
566
|
get isOne(): boolean | undefined;
|
|
567
|
+
/**
|
|
568
|
+
* @category Expression Properties
|
|
569
|
+
*/
|
|
411
570
|
get isNegativeOne(): boolean | undefined;
|
|
412
|
-
/** ±Infinity or Complex Infinity
|
|
571
|
+
/** ±Infinity or Complex Infinity
|
|
572
|
+
*
|
|
573
|
+
* @category Expression Properties
|
|
574
|
+
*/
|
|
413
575
|
get isInfinity(): boolean | undefined;
|
|
414
576
|
/**
|
|
415
577
|
* "Not a Number".
|
|
416
578
|
*
|
|
417
579
|
* A value representing undefined result of computations, such as `0/0`,
|
|
418
|
-
* as per the
|
|
580
|
+
* as per the floating point format standard IEEE-754.
|
|
581
|
+
*
|
|
582
|
+
* Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
|
|
583
|
+
* number).
|
|
419
584
|
*
|
|
420
|
-
*
|
|
585
|
+
* @category Expression Properties
|
|
421
586
|
*
|
|
422
587
|
*/
|
|
423
588
|
get isNaN(): boolean | undefined;
|
|
424
|
-
/** Not ±Infinity and not NaN
|
|
589
|
+
/** Not ±Infinity and not `NaN`
|
|
590
|
+
*
|
|
591
|
+
* @category Expression Properties
|
|
592
|
+
*/
|
|
425
593
|
get isFinite(): boolean | undefined;
|
|
594
|
+
/**
|
|
595
|
+
* @category Expression Properties
|
|
596
|
+
*/
|
|
426
597
|
get isEven(): boolean | undefined;
|
|
598
|
+
/**
|
|
599
|
+
* @category Expression Properties
|
|
600
|
+
*/
|
|
427
601
|
get isOdd(): boolean | undefined;
|
|
602
|
+
/**
|
|
603
|
+
* @category Expression Properties
|
|
604
|
+
*/
|
|
428
605
|
get isPrime(): boolean | undefined;
|
|
606
|
+
/**
|
|
607
|
+
* @category Expression Properties
|
|
608
|
+
*/
|
|
429
609
|
get isComposite(): boolean | undefined;
|
|
430
610
|
/** Structural/symbolic equality (weak equality).
|
|
431
611
|
*
|
|
432
612
|
* `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
|
|
433
613
|
*
|
|
614
|
+
* @category Relational Operator
|
|
434
615
|
*/
|
|
435
616
|
isSame(rhs: BoxedExpression): boolean;
|
|
436
617
|
/**
|
|
@@ -459,20 +640,46 @@ export interface BoxedExpression {
|
|
|
459
640
|
* Numbers whose difference is less than `engine.tolerance` are
|
|
460
641
|
* considered equal. This tolerance is set when the `engine.precision` is
|
|
461
642
|
* changed to be such that the last two digits are ignored.
|
|
643
|
+
*
|
|
644
|
+
* @category Relational Operator
|
|
462
645
|
*/
|
|
463
646
|
isEqual(rhs: BoxedExpression): boolean;
|
|
464
|
-
/** If the expressions cannot be compared, `undefined` is returned
|
|
647
|
+
/** If the expressions cannot be compared, `undefined` is returned
|
|
648
|
+
*
|
|
649
|
+
* @category Relational Operator
|
|
650
|
+
*/
|
|
465
651
|
isLess(rhs: BoxedExpression): boolean | undefined;
|
|
652
|
+
/**
|
|
653
|
+
* @category Relational Operator
|
|
654
|
+
*/
|
|
466
655
|
isLessEqual(rhs: BoxedExpression): boolean | undefined;
|
|
656
|
+
/**
|
|
657
|
+
* @category Relational Operator
|
|
658
|
+
*/
|
|
467
659
|
isGreater(rhs: BoxedExpression): boolean | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* @category Relational Operator
|
|
662
|
+
*/
|
|
468
663
|
isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
|
|
469
|
-
/** The value of this expression is > 0, same as `isGreater(0)`
|
|
664
|
+
/** The value of this expression is > 0, same as `isGreater(0)`
|
|
665
|
+
*
|
|
666
|
+
* @category Expression Properties
|
|
667
|
+
*/
|
|
470
668
|
get isPositive(): boolean | undefined;
|
|
471
|
-
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
669
|
+
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
670
|
+
*
|
|
671
|
+
* @category Expression Properties
|
|
672
|
+
*/
|
|
472
673
|
get isNonNegative(): boolean | undefined;
|
|
473
|
-
/** The value of this expression is < 0, same as `isLess(0)`
|
|
674
|
+
/** The value of this expression is < 0, same as `isLess(0)`
|
|
675
|
+
*
|
|
676
|
+
* @category Expression Properties
|
|
677
|
+
*/
|
|
474
678
|
get isNegative(): boolean | undefined;
|
|
475
|
-
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
679
|
+
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
680
|
+
*
|
|
681
|
+
* @category Expression Properties
|
|
682
|
+
*/
|
|
476
683
|
get isNonPositive(): boolean | undefined;
|
|
477
684
|
/** Wikidata identifier */
|
|
478
685
|
get wikidata(): string;
|
|
@@ -544,22 +751,22 @@ export interface BoxedExpression {
|
|
|
544
751
|
* The expression is first converted to canonical form.
|
|
545
752
|
*
|
|
546
753
|
* A pure expression always return the same value and has no side effects.
|
|
547
|
-
* If `
|
|
548
|
-
* For an impure expression, `
|
|
754
|
+
* If `this.isPure` is `true`, `this.value` and `this.evaluate()` are synonyms.
|
|
755
|
+
* For an impure expression, `this.value` is undefined.
|
|
549
756
|
*
|
|
550
757
|
* Evaluating an impure expression may have some side effects, for
|
|
551
758
|
* example modifying the `ComputeEngine` environment, such as its set of assumptions.
|
|
552
759
|
*
|
|
553
760
|
* Only exact calculations are performed, no floating point calculations.
|
|
554
|
-
* To perform approximate floating point calculations, use `
|
|
761
|
+
* To perform approximate floating point calculations, use `this.N()` instead.
|
|
555
762
|
*
|
|
556
|
-
* The result of `
|
|
763
|
+
* The result of `this.evaluate()` may be the same as `this.simplify()`.
|
|
557
764
|
*
|
|
558
765
|
* The result is in canonical form.
|
|
559
766
|
*
|
|
560
767
|
*/
|
|
561
768
|
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
562
|
-
/** Return a
|
|
769
|
+
/** Return a numeric approximation of this expression.
|
|
563
770
|
*
|
|
564
771
|
* The expression is first converted to canonical form.
|
|
565
772
|
*
|
|
@@ -567,10 +774,10 @@ export interface BoxedExpression {
|
|
|
567
774
|
* are performed. The calculations are performed according
|
|
568
775
|
* to the `numericMode` and `precision` properties of the `ComputeEngine`.
|
|
569
776
|
*
|
|
570
|
-
* To only perform exact calculations, use `
|
|
777
|
+
* To only perform exact calculations, use `this.evaluate()` instead.
|
|
571
778
|
*
|
|
572
|
-
* If the function is not numeric, the result of `
|
|
573
|
-
* `
|
|
779
|
+
* If the function is not numeric, the result of `this.N()` is the same as
|
|
780
|
+
* `this.evaluate()`.
|
|
574
781
|
*
|
|
575
782
|
* The result is in canonical form.
|
|
576
783
|
*/
|
|
@@ -599,8 +806,8 @@ export interface BoxedExpression {
|
|
|
599
806
|
/**
|
|
600
807
|
* Replace all the symbols in the expression as indicated.
|
|
601
808
|
*
|
|
602
|
-
* Note the same effect can be achieved with `
|
|
603
|
-
* using `
|
|
809
|
+
* Note the same effect can be achieved with `this.replace()`, but
|
|
810
|
+
* using `this.subs()` is more efficient, and simpler.
|
|
604
811
|
*
|
|
605
812
|
*/
|
|
606
813
|
subs(sub: Substitution): BoxedExpression;
|
|
@@ -608,12 +815,12 @@ export interface BoxedExpression {
|
|
|
608
815
|
* Update the definition associated with this expression, taking
|
|
609
816
|
* into account the current context.
|
|
610
817
|
*
|
|
611
|
-
*
|
|
818
|
+
* @internal
|
|
612
819
|
*/
|
|
613
820
|
_repairDefinition(): void;
|
|
614
821
|
/** Purge any cached values.
|
|
615
822
|
*
|
|
616
|
-
*
|
|
823
|
+
* @internal
|
|
617
824
|
*/
|
|
618
825
|
_purge(): undefined;
|
|
619
826
|
}
|
|
@@ -634,6 +841,7 @@ export declare type PatternMatchOption = {
|
|
|
634
841
|
export interface Pattern extends BoxedExpression {
|
|
635
842
|
/**
|
|
636
843
|
* If `expr` does not match the pattern, return `null`.
|
|
844
|
+
*
|
|
637
845
|
* Otherwise, return a substitution describing the values that the named
|
|
638
846
|
* wildcard in the pattern should be changed to in order for the pattern to be
|
|
639
847
|
* equal to the expression. If there are no named wildcards and the expression
|
|
@@ -697,17 +905,27 @@ export declare type Scope = {
|
|
|
697
905
|
warn?: WarningSignalHandler;
|
|
698
906
|
/** Signal `timeout` when the execution time for this scope is exceeded.
|
|
699
907
|
* Time in seconds, default 2s.
|
|
908
|
+
*
|
|
909
|
+
* @experimental
|
|
700
910
|
*/
|
|
701
911
|
timeLimit?: number;
|
|
702
912
|
/** Signal `out-of-memory` when the memory usage for this scope is exceeded.
|
|
703
913
|
* Memory in Megabytes, default: 1Mb.
|
|
914
|
+
*
|
|
915
|
+
* @experimental
|
|
704
916
|
*/
|
|
705
917
|
memoryLimit?: number;
|
|
706
918
|
/** Signal `recursion-depth-exceeded` when the recursion depth for this
|
|
707
|
-
* scope is exceeded.
|
|
919
|
+
* scope is exceeded.
|
|
920
|
+
*
|
|
921
|
+
* @experimental
|
|
922
|
+
*/
|
|
708
923
|
recursionLimit?: number;
|
|
709
924
|
/** Signal `iteration-limit-exceeded` when the iteration limit for this
|
|
710
|
-
* scope is exceeded. Default: no limits
|
|
925
|
+
* scope is exceeded. Default: no limits.
|
|
926
|
+
*
|
|
927
|
+
* @experimental
|
|
928
|
+
*/
|
|
711
929
|
iterationLimit?: number;
|
|
712
930
|
};
|
|
713
931
|
export declare type RuntimeScope = Scope & {
|
|
@@ -750,9 +968,13 @@ export declare type BaseDefinition = {
|
|
|
750
968
|
wikidata?: string;
|
|
751
969
|
/**
|
|
752
970
|
* The domain of this item.
|
|
753
|
-
*
|
|
754
|
-
* For
|
|
971
|
+
*
|
|
972
|
+
* For dictionaries, this is the domain of all the items in the dictionary.
|
|
973
|
+
*
|
|
974
|
+
* For strings, it's always 'String'.
|
|
975
|
+
*
|
|
755
976
|
* For symbols, this is the domain of their value.
|
|
977
|
+
*
|
|
756
978
|
* For functions, this is the domain of their result (aka codomain)
|
|
757
979
|
*/
|
|
758
980
|
domain?: BoxedExpression | string;
|
|
@@ -779,56 +1001,56 @@ export declare type FunctionDefinitionFlags = {
|
|
|
779
1001
|
/** If true, the function is applied element by element to lists, matrices
|
|
780
1002
|
* and equations.
|
|
781
1003
|
*
|
|
782
|
-
* Default
|
|
1004
|
+
* **Default**: `false`
|
|
783
1005
|
*/
|
|
784
1006
|
threadable: boolean;
|
|
785
|
-
/** If true, [f, [f, a], b] simplifies to [f, a, b]
|
|
1007
|
+
/** If true, `["f", ["f", a], b]` simplifies to `["f", a, b]`
|
|
786
1008
|
*
|
|
787
|
-
* Default
|
|
1009
|
+
* **Default**: `false`
|
|
788
1010
|
*/
|
|
789
1011
|
associative: boolean;
|
|
790
|
-
/** If true, `[f, a, b]` equals `[f, b, a]`. The canonical
|
|
1012
|
+
/** If true, `["f", a, b]` equals `["f", b, a]`. The canonical
|
|
791
1013
|
* version of the function will order the arguments.
|
|
792
1014
|
*
|
|
793
|
-
* Default
|
|
1015
|
+
* **Default**: `false`
|
|
794
1016
|
*/
|
|
795
1017
|
commutative: boolean;
|
|
796
|
-
/** If true, when the function is univariate, `[f, ["Add", x, c]]` where `c`
|
|
797
|
-
* is constant, is simplified to `["Add", [f, x], c]`.
|
|
1018
|
+
/** If true, when the function is univariate, `["f", ["Add", x, c]]` where `c`
|
|
1019
|
+
* is constant, is simplified to `["Add", ["f", x], c]`.
|
|
798
1020
|
*
|
|
799
1021
|
* When the function is multivariate, additivity is considered only on the
|
|
800
|
-
* first argument: `[f, ["Add", x, c], y]` simplifies to `["Add", [f, x, y], c]`.
|
|
1022
|
+
* first argument: `["f", ["Add", x, c], y]` simplifies to `["Add", ["f", x, y], c]`.
|
|
801
1023
|
*
|
|
802
|
-
* For example, `
|
|
1024
|
+
* For example, `Log` is additive.
|
|
803
1025
|
*
|
|
804
|
-
* Default
|
|
1026
|
+
* **Default**: `false`
|
|
805
1027
|
*/
|
|
806
|
-
/** If true, when the function is univariate, `[f, ["Multiply", x, y]]`
|
|
807
|
-
* simplifies to `["Multiply", [f, x], [f, y]]`.
|
|
1028
|
+
/** If true, when the function is univariate, `["f", ["Multiply", x, y]]`
|
|
1029
|
+
* simplifies to `["Multiply", ["f", x], ["f", y]]`.
|
|
808
1030
|
*
|
|
809
1031
|
* When the function is multivariate, multiplicativity is considered only on the
|
|
810
|
-
* first argument: `[f, ["Multiply", x, y], z]` simplifies to
|
|
811
|
-
* `["Multiply", [f, x, z], [f, y, z]]`
|
|
1032
|
+
* first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1033
|
+
* `["Multiply", ["f", x, z], ["f", y, z]]`
|
|
812
1034
|
*
|
|
813
|
-
* Default
|
|
1035
|
+
* **Default**: `false`
|
|
814
1036
|
*/
|
|
815
|
-
/** If true, when the function is univariate, `[f, ["Multiply", x, c]]`
|
|
816
|
-
* simplifies to `["Multiply", [f, x], c]` where `c` is constant
|
|
1037
|
+
/** If true, when the function is univariate, `["f", ["Multiply", x, c]]`
|
|
1038
|
+
* simplifies to `["Multiply", ["f", x], c]` where `c` is constant
|
|
817
1039
|
*
|
|
818
1040
|
* When the function is multivariate, multiplicativity is considered only on the
|
|
819
|
-
* first argument: `[f, ["Multiply", x, y], z]` simplifies to
|
|
820
|
-
* `["Multiply", [f, x, z], [f, y, z]]`
|
|
1041
|
+
* first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1042
|
+
* `["Multiply", ["f", x, z], ["f", y, z]]`
|
|
821
1043
|
*
|
|
822
|
-
* Default: false
|
|
1044
|
+
* Default: `false`
|
|
823
1045
|
*/
|
|
824
|
-
/** If true, `[f, [f, x]]` simplifies to `[f, x]`.
|
|
1046
|
+
/** If true, `["f", ["f", x]]` simplifies to `["f", x]`.
|
|
825
1047
|
*
|
|
826
|
-
* Default
|
|
1048
|
+
* **Default**: `false`
|
|
827
1049
|
*/
|
|
828
1050
|
idempotent: boolean;
|
|
829
|
-
/** If true, `[f, [f, x]]` simplifies to `x`.
|
|
1051
|
+
/** If true, `["f", ["f", x]]` simplifies to `x`.
|
|
830
1052
|
*
|
|
831
|
-
* Default
|
|
1053
|
+
* **Default**: `false`
|
|
832
1054
|
*/
|
|
833
1055
|
involution: boolean;
|
|
834
1056
|
/**
|
|
@@ -882,35 +1104,35 @@ export declare type FunctionDefinitionFlags = {
|
|
|
882
1104
|
inert: boolean;
|
|
883
1105
|
};
|
|
884
1106
|
/**
|
|
885
|
-
*
|
|
1107
|
+
* Definition record for a function.
|
|
886
1108
|
*
|
|
887
1109
|
*/
|
|
888
1110
|
export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
889
1111
|
/**
|
|
890
|
-
* A number used to order
|
|
891
|
-
* complexity are placed after
|
|
892
|
-
* ordered canonically.
|
|
893
|
-
*
|
|
894
|
-
* Additive functions: 1000-1999
|
|
895
|
-
* Multiplicative functions: 2000-2999
|
|
896
|
-
* Root and power functions: 3000-3999
|
|
897
|
-
* Log functions: 4000-4999
|
|
898
|
-
* Trigonometric functions: 5000-5999
|
|
899
|
-
* Hypertrigonometric functions: 6000-6999
|
|
900
|
-
* Special functions (factorial, Gamma, ...): 7000-7999
|
|
901
|
-
* Collections: 8000-8999
|
|
902
|
-
* Inert and styling: 9000-9999
|
|
903
|
-
* Logic: 10000-10999
|
|
904
|
-
* Relational: 11000-11999
|
|
1112
|
+
* A number used to order arguments. Argument with higher
|
|
1113
|
+
* complexity are placed after arguments with lower complexity when
|
|
1114
|
+
* ordered canonically in commutative functions.
|
|
1115
|
+
*
|
|
1116
|
+
* - Additive functions: 1000-1999
|
|
1117
|
+
* - Multiplicative functions: 2000-2999
|
|
1118
|
+
* - Root and power functions: 3000-3999
|
|
1119
|
+
* - Log functions: 4000-4999
|
|
1120
|
+
* - Trigonometric functions: 5000-5999
|
|
1121
|
+
* - Hypertrigonometric functions: 6000-6999
|
|
1122
|
+
* - Special functions (factorial, Gamma, ...): 7000-7999
|
|
1123
|
+
* - Collections: 8000-8999
|
|
1124
|
+
* - Inert and styling: 9000-9999
|
|
1125
|
+
* - Logic: 10000-10999
|
|
1126
|
+
* - Relational: 11000-11999
|
|
905
1127
|
*
|
|
906
1128
|
* **Default**: 100,000
|
|
907
1129
|
*/
|
|
908
1130
|
complexity?: number;
|
|
909
1131
|
/**
|
|
910
|
-
* - `none
|
|
911
|
-
* - `all
|
|
912
|
-
* - `first
|
|
913
|
-
* - `rest
|
|
1132
|
+
* - `none` Each of the arguments is evaluated (default)
|
|
1133
|
+
* - `all` None of the arguments are evaluated and they are passed as is
|
|
1134
|
+
* - `first` The first argument is not evaluated, the others are
|
|
1135
|
+
* - `rest` The first argument is evaluated, the others aren't
|
|
914
1136
|
*/
|
|
915
1137
|
hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
916
1138
|
/**
|
|
@@ -959,12 +1181,12 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
959
1181
|
* `arg.isPositive`.
|
|
960
1182
|
*
|
|
961
1183
|
* Even though a symbol may not have a value, there may be some information
|
|
962
|
-
* about it reflected for example in `
|
|
1184
|
+
* about it reflected for example in `this.isZero` or `this.isPrime`.
|
|
963
1185
|
*
|
|
964
1186
|
* The handler should not perform approximate numeric calculations, such
|
|
965
1187
|
* as calculations involving floating point numbers. Making exact
|
|
966
1188
|
* calculations on integers or rationals is OK. It is recommended, but not
|
|
967
|
-
* required, that the calculations be limited to `
|
|
1189
|
+
* required, that the calculations be limited to `this.smallIntegerValue`
|
|
968
1190
|
* (i.e. numeric representations of the expression as an integer of small
|
|
969
1191
|
* magnitude).
|
|
970
1192
|
*
|
|
@@ -992,12 +1214,12 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
992
1214
|
*/
|
|
993
1215
|
evaluate?: LambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
994
1216
|
/**
|
|
995
|
-
* Evaluate numerically
|
|
1217
|
+
* Evaluate numerically an expression.
|
|
996
1218
|
*
|
|
997
|
-
* The arguments
|
|
1219
|
+
* The arguments `args` have been simplified and evaluated, numerically
|
|
998
1220
|
* if possible, except the arguments to which a `hold` apply.
|
|
999
1221
|
*
|
|
1000
|
-
* The arguments
|
|
1222
|
+
* The arguments may be a combination of numbers, symbolic
|
|
1001
1223
|
* expressions and other expressions.
|
|
1002
1224
|
*
|
|
1003
1225
|
* Perform as many calculations as possible, and return the result.
|
|
@@ -1015,13 +1237,13 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
1015
1237
|
* number, but complex numbers are not allowed (the `engine.numericMode`
|
|
1016
1238
|
* is not `complex` or `auto`).
|
|
1017
1239
|
*
|
|
1018
|
-
* If the `
|
|
1240
|
+
* If the `ce.numericMode` is `auto` or `complex`, you may return
|
|
1019
1241
|
* a Complex number as a result. Otherwise, if the result is a complex
|
|
1020
1242
|
* value, return `NaN`. If Complex are not allowed, none of the arguments
|
|
1021
1243
|
* will be complex literals.
|
|
1022
1244
|
*
|
|
1023
|
-
* If the `
|
|
1024
|
-
* `
|
|
1245
|
+
* If the `ce.numericMode` is `decimal` or `auto` and
|
|
1246
|
+
* `this.engine.precision` is > 15, you may return a Decimal number.
|
|
1025
1247
|
* Otherwise, return a `machine` number approximation. If Decimal are
|
|
1026
1248
|
* not allowed, none of the arguments will be Decimal literal.
|
|
1027
1249
|
*
|
|
@@ -1044,7 +1266,7 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
1044
1266
|
*
|
|
1045
1267
|
* Otherwise, the return value is the domain of the result.
|
|
1046
1268
|
*
|
|
1047
|
-
* Return `Nothing` if the arguments are acceptable, but the evaluation
|
|
1269
|
+
* Return `"Nothing"` if the arguments are acceptable, but the evaluation
|
|
1048
1270
|
* will fail, for example in some cases if there are missing arguments.
|
|
1049
1271
|
*
|
|
1050
1272
|
* This function is used to select the correct definition when there are
|
|
@@ -1055,7 +1277,9 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
1055
1277
|
*
|
|
1056
1278
|
*/
|
|
1057
1279
|
evalDomain?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | string | null;
|
|
1058
|
-
/** Dimensional analysis
|
|
1280
|
+
/** Dimensional analysis
|
|
1281
|
+
* @experimental
|
|
1282
|
+
*/
|
|
1059
1283
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1060
1284
|
/** Return the sign of the function given a list of arguments. */
|
|
1061
1285
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
@@ -1078,6 +1302,7 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
|
|
|
1078
1302
|
};
|
|
1079
1303
|
/**
|
|
1080
1304
|
* When used in a `SymbolDefinition`, these flags are optional.
|
|
1305
|
+
*
|
|
1081
1306
|
* If provided, they will override the value derived from
|
|
1082
1307
|
* the symbol's value.
|
|
1083
1308
|
*
|
|
@@ -1154,38 +1379,65 @@ export interface ComputeEngineStats {
|
|
|
1154
1379
|
expressions: null | Set<BoxedExpression>;
|
|
1155
1380
|
highwaterMark: number;
|
|
1156
1381
|
}
|
|
1382
|
+
/** @internal */
|
|
1157
1383
|
export interface IComputeEngine {
|
|
1384
|
+
/** @internal */
|
|
1158
1385
|
readonly ZERO: BoxedExpression;
|
|
1386
|
+
/** @internal */
|
|
1159
1387
|
readonly ONE: BoxedExpression;
|
|
1388
|
+
/** @internal */
|
|
1160
1389
|
readonly TWO: BoxedExpression;
|
|
1390
|
+
/** @internal */
|
|
1161
1391
|
readonly HALF: BoxedExpression;
|
|
1392
|
+
/** @internal */
|
|
1162
1393
|
readonly NEGATIVE_ONE: BoxedExpression;
|
|
1394
|
+
/** @internal */
|
|
1163
1395
|
readonly I: BoxedExpression;
|
|
1396
|
+
/** @internal */
|
|
1164
1397
|
readonly NAN: BoxedExpression;
|
|
1398
|
+
/** @internal */
|
|
1165
1399
|
readonly POSITIVE_INFINITY: BoxedExpression;
|
|
1400
|
+
/** @internal */
|
|
1166
1401
|
readonly NEGATIVE_INFINITY: BoxedExpression;
|
|
1402
|
+
/** @internal */
|
|
1167
1403
|
readonly COMPLEX_INFINITY: BoxedExpression;
|
|
1404
|
+
/** @internal */
|
|
1168
1405
|
readonly DECIMAL_NAN: Decimal;
|
|
1406
|
+
/** @internal */
|
|
1169
1407
|
readonly DECIMAL_ZERO: Decimal;
|
|
1408
|
+
/** @internal */
|
|
1170
1409
|
readonly DECIMAL_ONE: Decimal;
|
|
1410
|
+
/** @internal */
|
|
1171
1411
|
readonly DECIMAL_TWO: Decimal;
|
|
1412
|
+
/** @internal */
|
|
1172
1413
|
readonly DECIMAL_HALF: Decimal;
|
|
1414
|
+
/** @internal */
|
|
1173
1415
|
readonly DECIMAL_PI: Decimal;
|
|
1416
|
+
/** @internal */
|
|
1174
1417
|
readonly DECIMAL_NEGATIVE_ONE: Decimal;
|
|
1418
|
+
/** The current scope */
|
|
1175
1419
|
context: RuntimeScope;
|
|
1176
|
-
/** Absolute time beyond which evaluation should not proceed
|
|
1420
|
+
/** Absolute time beyond which evaluation should not proceed
|
|
1421
|
+
* @internal
|
|
1422
|
+
*/
|
|
1177
1423
|
deadline?: number;
|
|
1424
|
+
/** @experimental */
|
|
1178
1425
|
readonly timeLimit: number;
|
|
1426
|
+
/** @experimental */
|
|
1179
1427
|
readonly iterationLimit: number;
|
|
1428
|
+
/** @experimental */
|
|
1180
1429
|
readonly recursionLimit: number;
|
|
1181
|
-
|
|
1430
|
+
defaultDomain: null | BoxedExpression;
|
|
1431
|
+
/** {@inheritDoc NumericMode} */
|
|
1182
1432
|
numericMode: NumericMode;
|
|
1183
1433
|
tolerance: number;
|
|
1184
1434
|
chop(n: number): number;
|
|
1185
1435
|
chop(n: Decimal): Decimal | 0;
|
|
1186
1436
|
chop(n: Complex): Complex | 0;
|
|
1187
1437
|
chop(n: number | Decimal | Complex): number | Decimal | Complex;
|
|
1438
|
+
/** @internal */
|
|
1188
1439
|
decimal: (a: Decimal.Value) => Decimal;
|
|
1440
|
+
/** @internal */
|
|
1189
1441
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
1190
1442
|
set precision(p: number | 'machine');
|
|
1191
1443
|
get precision(): number;
|
|
@@ -1220,7 +1472,7 @@ export interface IComputeEngine {
|
|
|
1220
1472
|
* Note that the result may not be a function, or may have a different
|
|
1221
1473
|
* `head` than the one specified.
|
|
1222
1474
|
*
|
|
1223
|
-
* For example `ce.fn(
|
|
1475
|
+
* For example `ce.fn("Add", [ce.number(2), ce.number(3)]))` \( \to \) 5
|
|
1224
1476
|
*
|
|
1225
1477
|
*/
|
|
1226
1478
|
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
@@ -1235,47 +1487,47 @@ export interface IComputeEngine {
|
|
|
1235
1487
|
* ops canonical, etc..) so that the result is actually canonical.
|
|
1236
1488
|
*/
|
|
1237
1489
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1238
|
-
/** Shortcut for `fn(
|
|
1490
|
+
/** Shortcut for `this.fn("Error"...)`.
|
|
1239
1491
|
*
|
|
1240
1492
|
* The result is canonical.
|
|
1241
1493
|
*/
|
|
1242
1494
|
error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): any;
|
|
1243
|
-
/** Shortcut for `fn(
|
|
1495
|
+
/** Shortcut for `this.fn("Add"...)`.
|
|
1244
1496
|
*
|
|
1245
1497
|
* The result is canonical.
|
|
1246
1498
|
*/
|
|
1247
1499
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1248
|
-
/** Shortcut for `fn(
|
|
1500
|
+
/** Shortcut for `this.fn("Multiply"...)`
|
|
1249
1501
|
*
|
|
1250
1502
|
* The result is canonical.
|
|
1251
1503
|
*/
|
|
1252
1504
|
mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1253
|
-
/** Shortcut for `fn(
|
|
1505
|
+
/** Shortcut for `this.fn("Power"...)`
|
|
1254
1506
|
*
|
|
1255
1507
|
* The result is canonical.
|
|
1256
1508
|
*/
|
|
1257
1509
|
power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1258
|
-
/** Shortcut for `fn(
|
|
1510
|
+
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
1259
1511
|
*
|
|
1260
1512
|
* The result is canonical.
|
|
1261
1513
|
*/
|
|
1262
1514
|
inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1263
|
-
/** Shortcut for `fn(
|
|
1515
|
+
/** Shortcut for `this.fn("Negate", [expr])`
|
|
1264
1516
|
*
|
|
1265
1517
|
* The result is canonical.
|
|
1266
1518
|
*/
|
|
1267
1519
|
negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1268
|
-
/** Shortcut for `fn(
|
|
1520
|
+
/** Shortcut for `this.fn("Divide", [num, denom])`
|
|
1269
1521
|
*
|
|
1270
1522
|
* The result is canonical.
|
|
1271
1523
|
*/
|
|
1272
1524
|
divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1273
|
-
/** Shortcut for `fn(
|
|
1525
|
+
/** Shortcut for `this.fn("Pair"...)`
|
|
1274
1526
|
*
|
|
1275
1527
|
* The result is canonical.
|
|
1276
1528
|
*/
|
|
1277
1529
|
pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1278
|
-
/** Shortcut for `fn(
|
|
1530
|
+
/** Shortcut for `this.fn("Tuple"...)`
|
|
1279
1531
|
*
|
|
1280
1532
|
* The result is canonical.
|
|
1281
1533
|
*/
|
|
@@ -1288,18 +1540,47 @@ export interface IComputeEngine {
|
|
|
1288
1540
|
* The result may not be canonical.
|
|
1289
1541
|
*
|
|
1290
1542
|
*/
|
|
1291
|
-
parse(s:
|
|
1543
|
+
parse(s: LatexString | string): BoxedExpression;
|
|
1544
|
+
parse(s: null): null;
|
|
1545
|
+
parse(s: LatexString | string | null): null | BoxedExpression;
|
|
1292
1546
|
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
1293
1547
|
* a LaTeX string
|
|
1294
1548
|
*/
|
|
1295
1549
|
serialize(expr: SemiBoxedExpression): LatexString;
|
|
1550
|
+
/**
|
|
1551
|
+
* Options to control the serailization of MathJSON expression to LaTeX
|
|
1552
|
+
* when using `this.latex` or `this.engine.serialize()`.
|
|
1553
|
+
*
|
|
1554
|
+
*
|
|
1555
|
+
* {@inheritDoc NumberFormattingOptions}
|
|
1556
|
+
* {@inheritDoc ParseLatexOptions}
|
|
1557
|
+
* {@inheritDoc SerializeLatexOptions}
|
|
1558
|
+
*
|
|
1559
|
+
*/
|
|
1296
1560
|
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
1297
1561
|
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
1562
|
+
/** {@inheritDoc JsonSerializationOptions} */
|
|
1298
1563
|
get jsonSerializationOptions(): JsonSerializationOptions;
|
|
1299
1564
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1565
|
+
/**
|
|
1566
|
+
* Add an assumption.
|
|
1567
|
+
*
|
|
1568
|
+
* Note that the assumption is put into canonical form before being added.
|
|
1569
|
+
*
|
|
1570
|
+
* @param symbol - The symbol to make an assumption about
|
|
1571
|
+
*
|
|
1572
|
+
* Returns:
|
|
1573
|
+
* - `contradiction` if the new assumption is incompatible with previous
|
|
1574
|
+
* ones.
|
|
1575
|
+
* - `tautology` if the new assumption is redundant with previous ones.
|
|
1576
|
+
* - `ok` if the assumption was successfully added to the assumption set.
|
|
1577
|
+
*
|
|
1578
|
+
*
|
|
1579
|
+
*/
|
|
1300
1580
|
assume(symbol: LatexString | SemiBoxedExpression, domain: BoxedExpression): AssumeResult;
|
|
1301
1581
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
1302
1582
|
assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
|
|
1583
|
+
/** Remove all assumptions about one or more symbols */
|
|
1303
1584
|
forget(symbol?: string | string[]): void;
|
|
1304
1585
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1305
1586
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
@@ -1309,15 +1590,28 @@ export interface IComputeEngine {
|
|
|
1309
1590
|
scope?: Partial<Scope>;
|
|
1310
1591
|
}): void;
|
|
1311
1592
|
popScope(): void;
|
|
1593
|
+
/**
|
|
1594
|
+
* When `condition` is false, signal.
|
|
1595
|
+
*
|
|
1596
|
+
* - `condition` - If `true`, do nothing. If `false`, signal.
|
|
1597
|
+
*
|
|
1598
|
+
* @experimental
|
|
1599
|
+
*/
|
|
1312
1600
|
assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): any;
|
|
1313
1601
|
signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
1314
1602
|
signal(sig: WarningSignal): void;
|
|
1603
|
+
/** @internal */
|
|
1315
1604
|
shouldContinueExecution(): boolean;
|
|
1605
|
+
/** @internal */
|
|
1316
1606
|
checkContinueExecution(): void;
|
|
1607
|
+
/** @internal */
|
|
1317
1608
|
cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
|
|
1318
1609
|
readonly stats: ComputeEngineStats;
|
|
1610
|
+
/** @internal */
|
|
1319
1611
|
purge(): void;
|
|
1612
|
+
/** @internal */
|
|
1320
1613
|
_register(expr: BoxedExpression): void;
|
|
1614
|
+
/** @internal */
|
|
1321
1615
|
_unregister(expr: BoxedExpression): void;
|
|
1322
1616
|
}
|
|
1323
1617
|
export declare function getVars(expr: BoxedExpression): string[];
|