@cortex-js/compute-engine 0.6.0 → 0.7.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 +15779 -12531
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +62 -43
- 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 +2 -2
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +22 -10
- package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -14
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +4 -4
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +36 -19
- 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 +14 -13
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +5 -5
- 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 +9 -6
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +24 -10
- 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 +23 -6
- package/dist/types/compute-engine/compute-engine.d.ts +74 -50
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/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 -3
- 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 +8 -7
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +87 -62
- package/dist/types/compute-engine/latex-syntax/public.d.ts +65 -46
- 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 +6 -4
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +11 -0
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +15 -0
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +19 -0
- package/dist/types/compute-engine/{dictionary → library}/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +2 -0
- package/dist/types/compute-engine/library/calculus.d.ts +2 -0
- package/dist/types/compute-engine/library/collections.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -0
- package/dist/types/compute-engine/library/domains.d.ts +15 -0
- package/dist/types/compute-engine/library/library.d.ts +17 -0
- package/dist/types/compute-engine/library/logic.d.ts +2 -0
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
- package/dist/types/compute-engine/library/sets.d.ts +2 -0
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +5 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +4 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +237 -187
- 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 +2 -2
- 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 +27 -23
- package/dist/types/math-json/utils.d.ts +22 -16
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +20 -20
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +0 -11
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +0 -9
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +0 -17
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/collections.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/core.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +0 -26
- package/dist/types/compute-engine/dictionary/logic.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/sets.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.7.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -17,18 +17,18 @@ export * from './latex-syntax/public';
|
|
|
17
17
|
* Metadata that can be associated with a `BoxedExpression`
|
|
18
18
|
*/
|
|
19
19
|
export declare type Metadata = {
|
|
20
|
-
latex?: string;
|
|
21
|
-
wikidata?: string;
|
|
20
|
+
latex?: string | undefined;
|
|
21
|
+
wikidata?: string | undefined;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* The numeric evaluation mode:
|
|
25
25
|
*
|
|
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,
|
|
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
28
|
* about 15 digits of precision
|
|
29
|
-
* - `decimal`: arbitrary precision floating point numbers, as provided by the
|
|
29
|
+
* - `"decimal"`: arbitrary precision floating point numbers, as provided by the
|
|
30
30
|
* "decimal.js" library
|
|
31
|
-
* - `complex`: complex number represented by two machine numbers, a real and
|
|
31
|
+
* - `"complex"`: complex number represented by two machine numbers, a real and
|
|
32
32
|
* an imaginary part, as provided by the "complex.js" library
|
|
33
33
|
*/
|
|
34
34
|
export declare type NumericMode = 'auto' | 'machine' | 'decimal' | 'complex';
|
|
@@ -49,16 +49,16 @@ export declare type EvaluateOptions = {};
|
|
|
49
49
|
*/
|
|
50
50
|
export declare type NOptions = {};
|
|
51
51
|
export declare type ReplaceOptions = {
|
|
52
|
-
/** If true
|
|
53
|
-
* If false
|
|
52
|
+
/** If `true`, apply replacement rules to all sub-expressions.
|
|
53
|
+
* If `false`, only consider the top-level expression.
|
|
54
54
|
*
|
|
55
55
|
* **Default**: `true`
|
|
56
56
|
*/
|
|
57
57
|
recursive?: boolean;
|
|
58
58
|
/**
|
|
59
|
-
* If true
|
|
59
|
+
* If `true`, stop after the first rule that matches.
|
|
60
60
|
*
|
|
61
|
-
* If false
|
|
61
|
+
* If `false`, apply all the remaining rules even after the first match.
|
|
62
62
|
*
|
|
63
63
|
* **Default**: `true`
|
|
64
64
|
*/
|
|
@@ -81,6 +81,9 @@ export declare type ReplaceOptions = {
|
|
|
81
81
|
* rule whose `lhs` is always a symbol.
|
|
82
82
|
*/
|
|
83
83
|
export declare type Substitution = {
|
|
84
|
+
[symbol: string]: SemiBoxedExpression;
|
|
85
|
+
};
|
|
86
|
+
export declare type BoxedSubstitution = {
|
|
84
87
|
[symbol: string]: BoxedExpression;
|
|
85
88
|
};
|
|
86
89
|
/** A LaTeX string starts and end with `$`, for example
|
|
@@ -111,7 +114,7 @@ export declare type Rule = [
|
|
|
111
114
|
lhs: LatexString | SemiBoxedExpression | Pattern,
|
|
112
115
|
rhs: LatexString | SemiBoxedExpression,
|
|
113
116
|
options?: {
|
|
114
|
-
condition?: LatexString | ((wildcards:
|
|
117
|
+
condition?: LatexString | ((wildcards: BoxedSubstitution) => boolean);
|
|
115
118
|
priority?: number;
|
|
116
119
|
}
|
|
117
120
|
];
|
|
@@ -119,51 +122,44 @@ export declare type BoxedRule = [
|
|
|
119
122
|
lhs: Pattern,
|
|
120
123
|
rhs: BoxedExpression,
|
|
121
124
|
priority: number,
|
|
122
|
-
condition: undefined | ((wildcards:
|
|
125
|
+
condition: undefined | ((wildcards: BoxedSubstitution) => boolean)
|
|
123
126
|
];
|
|
124
127
|
export declare type BoxedRuleSet = Set<BoxedRule>;
|
|
125
|
-
export declare type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
];
|
|
130
|
-
export
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
codomain: Domain | null;
|
|
128
|
+
export declare type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
129
|
+
/** A domain constructor is the head of a domain expression. */
|
|
130
|
+
export declare type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
|
|
131
|
+
export declare type DomainLiteral = string;
|
|
132
|
+
export declare type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
|
|
133
|
+
export interface BoxedDomain extends BoxedExpression {
|
|
134
|
+
is(s: BoxedDomain): boolean;
|
|
135
|
+
/** True if a valid domain, and compatible with `dom` */
|
|
136
|
+
isCompatible(dom: BoxedDomain | DomainLiteral, kind?: DomainCompatibility): boolean;
|
|
137
|
+
get literal(): string | null;
|
|
138
|
+
get ctor(): DomainConstructor | null;
|
|
139
|
+
get domainArgs(): (DomainExpression<BoxedExpression> | BoxedExpression | string)[] | null;
|
|
140
|
+
get domainArg1(): string | BoxedExpression | DomainExpression<BoxedExpression> | null;
|
|
141
|
+
get codomain(): BoxedDomain | null;
|
|
142
|
+
get canonical(): BoxedDomain;
|
|
143
|
+
get json(): Expression;
|
|
142
144
|
readonly isNothing: boolean;
|
|
143
|
-
is(s: BoxedExpression): boolean;
|
|
144
|
-
readonly isBoolean: boolean;
|
|
145
145
|
readonly isNumeric: boolean;
|
|
146
146
|
readonly isFunction: boolean;
|
|
147
|
-
readonly isPredicate: boolean;
|
|
148
147
|
/**
|
|
149
148
|
* If true, when all the arguments are numeric, the result of the
|
|
150
149
|
* evaluation is numeric. Numeric is any value with a domain of `Number`.
|
|
151
150
|
*
|
|
152
151
|
* Example of numeric functions: `Add`, `Multiply`, `Power`, `Abs`
|
|
153
152
|
*
|
|
154
|
-
* Default: false
|
|
153
|
+
* Default: `false`
|
|
155
154
|
*/
|
|
156
|
-
readonly isNumericFunction: boolean;
|
|
157
|
-
readonly isRealFunction: boolean;
|
|
158
155
|
/**
|
|
159
156
|
* If true, when all the arguments are boolean, the result of the
|
|
160
157
|
* evaluation is a boolean. Boolean is any value with a domain of `MaybeBoolean`.
|
|
161
158
|
*
|
|
162
159
|
* Example of logic functions: `And`, `Or`, `Not`, `Implies`
|
|
163
160
|
*
|
|
164
|
-
* **Default:** false
|
|
161
|
+
* **Default:** `false`
|
|
165
162
|
*/
|
|
166
|
-
readonly isLogicOperator: boolean;
|
|
167
163
|
/**
|
|
168
164
|
* The function represent a relation between the first argument and
|
|
169
165
|
* the second argument, and evaluates to a boolean indicating if the relation
|
|
@@ -171,7 +167,7 @@ export interface Domain extends BoxedExpression {
|
|
|
171
167
|
*
|
|
172
168
|
* For example, `Equal`, `Less`, `Approx`, etc...
|
|
173
169
|
*
|
|
174
|
-
* **Default:** false
|
|
170
|
+
* **Default:** `false`
|
|
175
171
|
*/
|
|
176
172
|
readonly isRelationalOperator: boolean;
|
|
177
173
|
}
|
|
@@ -194,7 +190,7 @@ export declare type JsonSerializationOptions = {
|
|
|
194
190
|
/** A list of space separated keywords indicating which MathJSON expressions
|
|
195
191
|
* can use a shorthand.
|
|
196
192
|
*
|
|
197
|
-
* **Default**: `[
|
|
193
|
+
* **Default**: `["all"]`
|
|
198
194
|
*/
|
|
199
195
|
shorthands: ('all' | 'number' | 'symbol' | 'function' | 'dictionary' | 'string')[];
|
|
200
196
|
/** A list of space separated keywords indicating which metadata should be
|
|
@@ -286,7 +282,7 @@ export interface BoxedExpression {
|
|
|
286
282
|
get value(): BoxedExpression | undefined;
|
|
287
283
|
/** Only the value of variables can be changed (symbols that are not constants) */
|
|
288
284
|
set value(value: BoxedExpression | number | undefined);
|
|
289
|
-
/**
|
|
285
|
+
/** An approximation of the value of this expression. Floating-point
|
|
290
286
|
* operations may be performed.
|
|
291
287
|
*
|
|
292
288
|
* Just like `this.value`, it returns `undefined` for impure expressions.
|
|
@@ -303,6 +299,10 @@ export interface BoxedExpression {
|
|
|
303
299
|
* As an example, the `Random` function is not pure.
|
|
304
300
|
*/
|
|
305
301
|
get isPure(): boolean;
|
|
302
|
+
/** True if the expression is a free variable, that is a symbol with no value */
|
|
303
|
+
get isFree(): boolean;
|
|
304
|
+
/** True if the expression is a constant, that is a symbol with an immutable value */
|
|
305
|
+
get isConstant(): boolean;
|
|
306
306
|
/**
|
|
307
307
|
* If `true`, this expression represents a value that was not calculated
|
|
308
308
|
* or that does not reference another expression.
|
|
@@ -316,6 +316,14 @@ export interface BoxedExpression {
|
|
|
316
316
|
* @internal
|
|
317
317
|
*/
|
|
318
318
|
set isCanonical(val: boolean);
|
|
319
|
+
/** All the subexpressions matching the head */
|
|
320
|
+
getSubexpressions(head: string): BoxedExpression[];
|
|
321
|
+
/** All the subexpressions in this expression, recursively */
|
|
322
|
+
get subexpressions(): BoxedExpression[];
|
|
323
|
+
/** All the symbols in the expression, recursively */
|
|
324
|
+
get symbols(): BoxedExpression[];
|
|
325
|
+
/** All the `["Error"]` subexpressions */
|
|
326
|
+
get errors(): BoxedExpression[];
|
|
319
327
|
/** `ops` is the list of arguments of the function, its "tail"
|
|
320
328
|
*
|
|
321
329
|
* @category Function Expression
|
|
@@ -458,7 +466,7 @@ export interface BoxedExpression {
|
|
|
458
466
|
* performed if they are safe from overflow. This method makes it easy
|
|
459
467
|
* to check for this, whether the value is a Decimal or a number.
|
|
460
468
|
*
|
|
461
|
-
* By default, "small" is less than
|
|
469
|
+
* By default, "small" is less than 1,000,000.
|
|
462
470
|
*
|
|
463
471
|
* @category Numeric Expression
|
|
464
472
|
*
|
|
@@ -487,8 +495,9 @@ export interface BoxedExpression {
|
|
|
487
495
|
* Note that complex numbers have no natural ordering,
|
|
488
496
|
* so if the value is a complex number, `sgn` is either 0, or `null`
|
|
489
497
|
*
|
|
490
|
-
* If a symbol, this does take assumptions into account, that is `this.sgn`
|
|
491
|
-
* `1` if `isPositive` is `true`, even if this expression has
|
|
498
|
+
* If a symbol, this does take assumptions into account, that is `this.sgn`
|
|
499
|
+
* will return `1` if `isPositive` is `true`, even if this expression has
|
|
500
|
+
* no value
|
|
492
501
|
*
|
|
493
502
|
* @category Numeric Expression
|
|
494
503
|
*
|
|
@@ -501,12 +510,17 @@ export interface BoxedExpression {
|
|
|
501
510
|
*
|
|
502
511
|
*/
|
|
503
512
|
get symbol(): string | null;
|
|
504
|
-
/**
|
|
513
|
+
/**
|
|
514
|
+
* If this is the `Nothing`, return `true`.
|
|
515
|
+
*/
|
|
516
|
+
get isNothing(): boolean;
|
|
517
|
+
/** `true` if this expression or any subexpression is an `["Error"]`
|
|
518
|
+
* expression.
|
|
505
519
|
*
|
|
506
520
|
* @category Symbol Expression
|
|
507
521
|
*
|
|
508
522
|
*/
|
|
509
|
-
get
|
|
523
|
+
get isValid(): boolean;
|
|
510
524
|
/** If this expression is a string, return the value of the string.
|
|
511
525
|
* Otherwise, return `null`.
|
|
512
526
|
*
|
|
@@ -514,12 +528,12 @@ export interface BoxedExpression {
|
|
|
514
528
|
*
|
|
515
529
|
*/
|
|
516
530
|
get string(): string | null;
|
|
517
|
-
/**
|
|
531
|
+
/** `true` if the value of this expression is a number.
|
|
518
532
|
*
|
|
519
533
|
* `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
|
|
520
534
|
*
|
|
521
535
|
* Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
|
|
522
|
-
* is a number.
|
|
536
|
+
* **is** a number.
|
|
523
537
|
*
|
|
524
538
|
* @category Expression Properties
|
|
525
539
|
*/
|
|
@@ -626,7 +640,7 @@ export interface BoxedExpression {
|
|
|
626
640
|
*
|
|
627
641
|
*/
|
|
628
642
|
get isNaN(): boolean | undefined;
|
|
629
|
-
/**
|
|
643
|
+
/** This expression is a number, but not ±Infinity and not `NaN`
|
|
630
644
|
*
|
|
631
645
|
* @category Expression Properties
|
|
632
646
|
*/
|
|
@@ -684,7 +698,7 @@ export interface BoxedExpression {
|
|
|
684
698
|
* @category Relational Operator
|
|
685
699
|
*/
|
|
686
700
|
isEqual(rhs: BoxedExpression): boolean;
|
|
687
|
-
/** If the expressions cannot be compared, `undefined`
|
|
701
|
+
/** If the expressions cannot be compared, return `undefined`
|
|
688
702
|
*
|
|
689
703
|
* @category Relational Operator
|
|
690
704
|
*/
|
|
@@ -706,17 +720,17 @@ export interface BoxedExpression {
|
|
|
706
720
|
* @category Expression Properties
|
|
707
721
|
*/
|
|
708
722
|
get isPositive(): boolean | undefined;
|
|
709
|
-
/** The value of this expression is
|
|
723
|
+
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
710
724
|
*
|
|
711
725
|
* @category Expression Properties
|
|
712
726
|
*/
|
|
713
727
|
get isNonNegative(): boolean | undefined;
|
|
714
|
-
/** The value of this expression is
|
|
728
|
+
/** The value of this expression is < 0, same as `isLess(0)`
|
|
715
729
|
*
|
|
716
730
|
* @category Expression Properties
|
|
717
731
|
*/
|
|
718
732
|
get isNegative(): boolean | undefined;
|
|
719
|
-
/** The value of this expression is
|
|
733
|
+
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
720
734
|
*
|
|
721
735
|
* @category Expression Properties
|
|
722
736
|
*/
|
|
@@ -733,18 +747,28 @@ export interface BoxedExpression {
|
|
|
733
747
|
* first in commutative functions
|
|
734
748
|
*/
|
|
735
749
|
get complexity(): number;
|
|
736
|
-
/** The domain of this expression.
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
*
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
750
|
+
/** The domain of this expression. If a function expression, this the domain
|
|
751
|
+
* of the value of the function(the codomain of the function), if a symbol
|
|
752
|
+
* the domain of the value of the symbol.
|
|
753
|
+
*/
|
|
754
|
+
get domain(): BoxedDomain;
|
|
755
|
+
/** Symbols that represent a variable (or a function name), can have their
|
|
756
|
+
* domain modified */
|
|
757
|
+
set domain(domain: BoxedDomain | string);
|
|
758
|
+
/**
|
|
759
|
+
* The domain of this expression, without accounting for any inferred domain
|
|
760
|
+
* or `defaultDomain`. If no domain has been explicitly set via assignment
|
|
761
|
+
* or via an `.assume()` directive, the `expr.explicitDomain` is `null.
|
|
762
|
+
*
|
|
763
|
+
* This is useful to determine if the domain of an expression is inferred.
|
|
764
|
+
*
|
|
765
|
+
* In most cases you'll want to use `.domain` instead.
|
|
766
|
+
*/
|
|
767
|
+
get explicitDomain(): BoxedDomain | null;
|
|
768
|
+
/** For symbols and functions, a possible definition associated with the
|
|
769
|
+
* expression. `basedDefinition` is the base class of symbol and function
|
|
770
|
+
* definition. */
|
|
771
|
+
get basedDefinition(): BoxedBaseDefinition | undefined;
|
|
748
772
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
749
773
|
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
750
774
|
/**
|
|
@@ -831,6 +855,7 @@ export interface BoxedExpression {
|
|
|
831
855
|
solve(vars: Iterable<string>): null | BoxedExpression[];
|
|
832
856
|
/**
|
|
833
857
|
* If this expression is a function, apply the function `fn` to all its operands.
|
|
858
|
+
*
|
|
834
859
|
* Replace the head of this expression with `head`, if defined.
|
|
835
860
|
*
|
|
836
861
|
* If this expression is a dictionary, return a new dictionary with the values
|
|
@@ -859,16 +884,16 @@ export interface BoxedExpression {
|
|
|
859
884
|
subs(sub: Substitution): BoxedExpression;
|
|
860
885
|
/**
|
|
861
886
|
* Update the definition associated with this expression, taking
|
|
862
|
-
* into account the
|
|
887
|
+
* into account the specified scope.
|
|
863
888
|
*
|
|
864
889
|
* @internal
|
|
865
890
|
*/
|
|
866
|
-
|
|
891
|
+
bind(scope: RuntimeScope | null): void;
|
|
867
892
|
/** Purge any cached values.
|
|
868
893
|
*
|
|
869
894
|
* @internal
|
|
870
895
|
*/
|
|
871
|
-
|
|
896
|
+
unbind(): void;
|
|
872
897
|
}
|
|
873
898
|
/** A semi boxed expression is an MathJSON expression which can include some
|
|
874
899
|
* boxed terms.
|
|
@@ -893,7 +918,7 @@ export interface Pattern extends BoxedExpression {
|
|
|
893
918
|
* equal to the expression. If there are no named wildcards and the expression
|
|
894
919
|
* matches the pattern, and empty object literal `{}` is returned.
|
|
895
920
|
*/
|
|
896
|
-
match(expr: BoxedExpression, options?: PatternMatchOption):
|
|
921
|
+
match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
|
|
897
922
|
/** If `expr` matches the pattern, return `true`, otherwise `false` */
|
|
898
923
|
test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
|
|
899
924
|
/** Return the number of exprs that matched the pattern */
|
|
@@ -909,25 +934,25 @@ export interface ExpressionMapInterface<U> {
|
|
|
909
934
|
[Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
|
|
910
935
|
}
|
|
911
936
|
/**
|
|
912
|
-
* A
|
|
937
|
+
* A symbol table contains definitions for symbols, functions and rules.
|
|
913
938
|
*
|
|
914
939
|
*/
|
|
915
|
-
export declare type
|
|
940
|
+
export declare type SymbolTable = {
|
|
916
941
|
symbols?: SymbolDefinition[];
|
|
917
942
|
functions?: FunctionDefinition[];
|
|
918
943
|
simplifyRules?: BoxedRuleSet;
|
|
919
944
|
};
|
|
920
945
|
/**
|
|
921
|
-
* The entries of a `
|
|
946
|
+
* The entries of a `RuntimeSymbolTable` have been validated and
|
|
922
947
|
* optimized for faster evaluation.
|
|
923
948
|
*
|
|
924
949
|
* When a new scope is created with `pushScope()` or when creating a new
|
|
925
950
|
* engine instance, new instances of `RuntimeDictionary` are created as needed.
|
|
926
951
|
*/
|
|
927
|
-
export declare type
|
|
952
|
+
export declare type RuntimeSymbolTable = {
|
|
928
953
|
symbols: Map<string, BoxedSymbolDefinition>;
|
|
929
954
|
symbolWikidata: Map<string, BoxedSymbolDefinition>;
|
|
930
|
-
functions: Map<string, BoxedFunctionDefinition
|
|
955
|
+
functions: Map<string, BoxedFunctionDefinition>;
|
|
931
956
|
functionWikidata: Map<string, BoxedFunctionDefinition>;
|
|
932
957
|
};
|
|
933
958
|
/**
|
|
@@ -976,7 +1001,7 @@ export declare type Scope = {
|
|
|
976
1001
|
};
|
|
977
1002
|
export declare type RuntimeScope = Scope & {
|
|
978
1003
|
parentScope: RuntimeScope;
|
|
979
|
-
|
|
1004
|
+
symbolTable?: RuntimeSymbolTable;
|
|
980
1005
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
981
1006
|
/** The location of the call site that created this scope */
|
|
982
1007
|
origin?: {
|
|
@@ -995,9 +1020,9 @@ export declare type BaseDefinition = {
|
|
|
995
1020
|
* The name of a symbol or function is an arbitrary string of Unicode
|
|
996
1021
|
* characters, however the following conventions are recommended:
|
|
997
1022
|
*
|
|
998
|
-
* - Use only letters, digits and
|
|
999
|
-
* a letter: `/^[a-zA-Z]
|
|
1000
|
-
* -
|
|
1023
|
+
* - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1024
|
+
* - The first character should be a letter: `/^[a-zA-Z]/`
|
|
1025
|
+
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1001
1026
|
*
|
|
1002
1027
|
*/
|
|
1003
1028
|
name: string;
|
|
@@ -1012,25 +1037,8 @@ export declare type BaseDefinition = {
|
|
|
1012
1037
|
* for the `Pi` constant.
|
|
1013
1038
|
*/
|
|
1014
1039
|
wikidata?: string;
|
|
1015
|
-
/**
|
|
1016
|
-
* The domain of this item.
|
|
1017
|
-
*
|
|
1018
|
-
* For dictionaries, this is the domain of all the items in the dictionary.
|
|
1019
|
-
*
|
|
1020
|
-
* For strings, it's always 'String'.
|
|
1021
|
-
*
|
|
1022
|
-
* For symbols, this is the domain of their value.
|
|
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`.
|
|
1030
|
-
*/
|
|
1031
|
-
domain?: Domain | DomainExpression | string | ((ce: IComputeEngine, args: BoxedExpression[]) => Domain | DomainExpression);
|
|
1032
1040
|
};
|
|
1033
|
-
export
|
|
1041
|
+
export interface BoxedBaseDefinition {
|
|
1034
1042
|
name: string;
|
|
1035
1043
|
wikidata?: string;
|
|
1036
1044
|
description?: string | string[];
|
|
@@ -1041,32 +1049,35 @@ export declare type BoxedBaseDefinition = {
|
|
|
1041
1049
|
* This field is usually undefined, but its value is set by `getDefinition()`
|
|
1042
1050
|
*/
|
|
1043
1051
|
scope: RuntimeScope | undefined;
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1052
|
+
/** When the environment changes, for example the numerical precision,
|
|
1053
|
+
* call `reset()` so that any cached values can be recalculated.
|
|
1054
|
+
*/
|
|
1055
|
+
reset(): any;
|
|
1056
|
+
}
|
|
1047
1057
|
/**
|
|
1048
1058
|
* A function definition can have some flags to indicate specific
|
|
1049
1059
|
* properties of the function.
|
|
1050
1060
|
*/
|
|
1051
1061
|
export declare type FunctionDefinitionFlags = {
|
|
1052
|
-
/** If true
|
|
1053
|
-
* and equations
|
|
1062
|
+
/** If `true`, the function is applied element by element to lists, matrices
|
|
1063
|
+
* (`["List"]` or `["Tuple"]` expressions) and equations (relational
|
|
1064
|
+
* operators).
|
|
1054
1065
|
*
|
|
1055
1066
|
* **Default**: `false`
|
|
1056
1067
|
*/
|
|
1057
1068
|
threadable: boolean;
|
|
1058
|
-
/** If true
|
|
1069
|
+
/** If `true`, `["f", ["f", a], b]` simplifies to `["f", a, b]`
|
|
1059
1070
|
*
|
|
1060
1071
|
* **Default**: `false`
|
|
1061
1072
|
*/
|
|
1062
1073
|
associative: boolean;
|
|
1063
|
-
/** If true
|
|
1074
|
+
/** If `true`, `["f", a, b]` equals `["f", b, a]`. The canonical
|
|
1064
1075
|
* version of the function will order the arguments.
|
|
1065
1076
|
*
|
|
1066
1077
|
* **Default**: `false`
|
|
1067
1078
|
*/
|
|
1068
1079
|
commutative: boolean;
|
|
1069
|
-
/** If true
|
|
1080
|
+
/** If `true`, when the function is univariate, `["f", ["Add", x, c]]` where `c`
|
|
1070
1081
|
* is constant, is simplified to `["Add", ["f", x], c]`.
|
|
1071
1082
|
*
|
|
1072
1083
|
* When the function is multivariate, additivity is considered only on the
|
|
@@ -1076,7 +1087,7 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1076
1087
|
*
|
|
1077
1088
|
* **Default**: `false`
|
|
1078
1089
|
*/
|
|
1079
|
-
/** If true
|
|
1090
|
+
/** If `true`, when the function is univariate, `["f", ["Multiply", x, y]]`
|
|
1080
1091
|
* simplifies to `["Multiply", ["f", x], ["f", y]]`.
|
|
1081
1092
|
*
|
|
1082
1093
|
* When the function is multivariate, multiplicativity is considered only on the
|
|
@@ -1085,26 +1096,26 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1085
1096
|
*
|
|
1086
1097
|
* **Default**: `false`
|
|
1087
1098
|
*/
|
|
1088
|
-
/** If true
|
|
1099
|
+
/** If `true`, when the function is univariate, `["f", ["Multiply", x, c]]`
|
|
1089
1100
|
* simplifies to `["Multiply", ["f", x], c]` where `c` is constant
|
|
1090
1101
|
*
|
|
1091
|
-
* When the function is multivariate, multiplicativity is considered only on
|
|
1092
|
-
* first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1102
|
+
* When the function is multivariate, multiplicativity is considered only on
|
|
1103
|
+
* the first argument: `["f", ["Multiply", x, y], z]` simplifies to
|
|
1093
1104
|
* `["Multiply", ["f", x, z], ["f", y, z]]`
|
|
1094
1105
|
*
|
|
1095
1106
|
* Default: `false`
|
|
1096
1107
|
*/
|
|
1097
|
-
/** If true
|
|
1108
|
+
/** If `true`, `["f", ["f", x]]` simplifies to `["f", x]`.
|
|
1098
1109
|
*
|
|
1099
1110
|
* **Default**: `false`
|
|
1100
1111
|
*/
|
|
1101
1112
|
idempotent: boolean;
|
|
1102
|
-
/** If true
|
|
1113
|
+
/** If `true`, `["f", ["f", x]]` simplifies to `x`.
|
|
1103
1114
|
*
|
|
1104
1115
|
* **Default**: `false`
|
|
1105
1116
|
*/
|
|
1106
1117
|
involution: boolean;
|
|
1107
|
-
/** If true
|
|
1118
|
+
/** If `true`, the value of this function is always the same for a given
|
|
1108
1119
|
* set of arguments and it has no side effects.
|
|
1109
1120
|
*
|
|
1110
1121
|
* An expression using this function is pure if the function and all its
|
|
@@ -1114,7 +1125,7 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1114
1125
|
*
|
|
1115
1126
|
* This information may be used to cache the value of expressions.
|
|
1116
1127
|
*
|
|
1117
|
-
* **Default:** true
|
|
1128
|
+
* **Default:** `true`
|
|
1118
1129
|
*/
|
|
1119
1130
|
pure: boolean;
|
|
1120
1131
|
/**
|
|
@@ -1125,46 +1136,30 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1125
1136
|
* **Default:** false
|
|
1126
1137
|
*/
|
|
1127
1138
|
inert: boolean;
|
|
1128
|
-
};
|
|
1129
|
-
/**
|
|
1130
|
-
* Definition record for a function.
|
|
1131
|
-
*
|
|
1132
|
-
*/
|
|
1133
|
-
export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
1134
1139
|
/**
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
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
|
|
1140
|
+
* All the arguments of a numeric function are numeric,
|
|
1141
|
+
* and its value is numeric.
|
|
1152
1142
|
*/
|
|
1153
|
-
|
|
1143
|
+
numeric: boolean;
|
|
1154
1144
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
* - `rest` The first argument is evaluated, the others aren't
|
|
1145
|
+
* When true, evaluating the function create a temporary scope.
|
|
1146
|
+
* This is used for example by the `Lambda` function to keep track of the
|
|
1147
|
+
* inferred domain of its wildcard `_` arguments
|
|
1159
1148
|
*/
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1149
|
+
scoped: boolean;
|
|
1150
|
+
};
|
|
1151
|
+
/**
|
|
1152
|
+
*
|
|
1153
|
+
*/
|
|
1154
|
+
export declare type FunctionSignature = {
|
|
1155
|
+
/** The domain of this signature, a domain compatible with the `Function`
|
|
1156
|
+
* domain) */
|
|
1157
|
+
domain?: BoxedDomain | DomainExpression;
|
|
1166
1158
|
/** The minimum and maximum values of the result of the function */
|
|
1167
|
-
|
|
1159
|
+
/** An optional handler to determine the codomain of the function.
|
|
1160
|
+
* If not provided, the codomain of the function is determined from `domain`
|
|
1161
|
+
*/
|
|
1162
|
+
codomain?: (ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null;
|
|
1168
1163
|
/**
|
|
1169
1164
|
* Return the canonical form of the expression with the arguments `args`.
|
|
1170
1165
|
*
|
|
@@ -1284,11 +1279,9 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
1284
1279
|
/** Return a compiled (optimized) expression. */
|
|
1285
1280
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1286
1281
|
};
|
|
1287
|
-
export declare type
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
sequenceHold: boolean;
|
|
1291
|
-
range?: [min: number, max: number];
|
|
1282
|
+
export declare type BoxedFunctionSignature = {
|
|
1283
|
+
domain: BoxedDomain;
|
|
1284
|
+
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedDomain[]) => BoxedDomain | null);
|
|
1292
1285
|
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1293
1286
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1294
1287
|
evaluate?: BoxedLambdaExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
@@ -1297,6 +1290,50 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
|
|
|
1297
1290
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
1298
1291
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1299
1292
|
};
|
|
1293
|
+
/**
|
|
1294
|
+
* Definition record for a function.
|
|
1295
|
+
*
|
|
1296
|
+
*/
|
|
1297
|
+
export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
1298
|
+
/**
|
|
1299
|
+
* A number used to order arguments.
|
|
1300
|
+
*
|
|
1301
|
+
* Argument with higher complexity are placed after arguments with lower
|
|
1302
|
+
* complexity when ordered canonically in commutative functions.
|
|
1303
|
+
*
|
|
1304
|
+
* - Additive functions: 1000-1999
|
|
1305
|
+
* - Multiplicative functions: 2000-2999
|
|
1306
|
+
* - Root and power functions: 3000-3999
|
|
1307
|
+
* - Log functions: 4000-4999
|
|
1308
|
+
* - Trigonometric functions: 5000-5999
|
|
1309
|
+
* - Hypertrigonometric functions: 6000-6999
|
|
1310
|
+
* - Special functions (factorial, Gamma, ...): 7000-7999
|
|
1311
|
+
* - Collections: 8000-8999
|
|
1312
|
+
* - Inert and styling: 9000-9999
|
|
1313
|
+
* - Logic: 10000-10999
|
|
1314
|
+
* - Relational: 11000-11999
|
|
1315
|
+
*
|
|
1316
|
+
* **Default**: 100,000
|
|
1317
|
+
*/
|
|
1318
|
+
complexity?: number;
|
|
1319
|
+
/**
|
|
1320
|
+
* - `"none"` Each of the arguments is evaluated (default)
|
|
1321
|
+
* - `"all"` None of the arguments are evaluated and they are passed as is
|
|
1322
|
+
* - `"first"` The first argument is not evaluated, the others are
|
|
1323
|
+
* - `"rest"` The first argument is evaluated, the others aren't
|
|
1324
|
+
* - `"last"`: The last argument is not evaluated, the others are
|
|
1325
|
+
* - `"most"`: All the arguments are evaluated, except the last one
|
|
1326
|
+
*
|
|
1327
|
+
* **Default**: `"none"`
|
|
1328
|
+
*/
|
|
1329
|
+
hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1330
|
+
signature?: FunctionSignature;
|
|
1331
|
+
};
|
|
1332
|
+
export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
|
|
1333
|
+
complexity: number;
|
|
1334
|
+
hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1335
|
+
signature: BoxedFunctionSignature;
|
|
1336
|
+
};
|
|
1300
1337
|
/**
|
|
1301
1338
|
* When used in a `SymbolDefinition`, these flags are optional.
|
|
1302
1339
|
*
|
|
@@ -1358,11 +1395,12 @@ export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & P
|
|
|
1358
1395
|
* `Pi`, the actual value depends on the `precision` setting of the
|
|
1359
1396
|
* `ComputeEngine` */
|
|
1360
1397
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1361
|
-
domain?: string |
|
|
1398
|
+
domain?: string | BoxedDomain;
|
|
1362
1399
|
};
|
|
1363
1400
|
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
|
|
1364
1401
|
get value(): BoxedExpression | undefined;
|
|
1365
1402
|
set value(val: BoxedExpression | undefined);
|
|
1403
|
+
domain: BoxedDomain | undefined;
|
|
1366
1404
|
at?: (index: string | number) => undefined | BoxedExpression;
|
|
1367
1405
|
}
|
|
1368
1406
|
export declare type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
|
|
@@ -1379,41 +1417,41 @@ export interface ComputeEngineStats {
|
|
|
1379
1417
|
/** @internal */
|
|
1380
1418
|
export interface IComputeEngine {
|
|
1381
1419
|
/** @internal */
|
|
1382
|
-
readonly
|
|
1420
|
+
readonly _ZERO: BoxedExpression;
|
|
1383
1421
|
/** @internal */
|
|
1384
|
-
readonly
|
|
1422
|
+
readonly _ONE: BoxedExpression;
|
|
1385
1423
|
/** @internal */
|
|
1386
|
-
readonly
|
|
1424
|
+
readonly _TWO: BoxedExpression;
|
|
1387
1425
|
/** @internal */
|
|
1388
|
-
readonly
|
|
1426
|
+
readonly _HALF: BoxedExpression;
|
|
1389
1427
|
/** @internal */
|
|
1390
|
-
readonly
|
|
1428
|
+
readonly _NEGATIVE_ONE: BoxedExpression;
|
|
1391
1429
|
/** @internal */
|
|
1392
|
-
readonly
|
|
1430
|
+
readonly _I: BoxedExpression;
|
|
1393
1431
|
/** @internal */
|
|
1394
|
-
readonly
|
|
1432
|
+
readonly _NAN: BoxedExpression;
|
|
1395
1433
|
/** @internal */
|
|
1396
|
-
readonly
|
|
1434
|
+
readonly _POSITIVE_INFINITY: BoxedExpression;
|
|
1397
1435
|
/** @internal */
|
|
1398
|
-
readonly
|
|
1436
|
+
readonly _NEGATIVE_INFINITY: BoxedExpression;
|
|
1399
1437
|
/** @internal */
|
|
1400
|
-
readonly
|
|
1438
|
+
readonly _COMPLEX_INFINITY: BoxedExpression;
|
|
1401
1439
|
/** @internal */
|
|
1402
|
-
readonly
|
|
1440
|
+
readonly _DECIMAL_NAN: Decimal;
|
|
1403
1441
|
/** @internal */
|
|
1404
|
-
readonly
|
|
1442
|
+
readonly _DECIMAL_ZERO: Decimal;
|
|
1405
1443
|
/** @internal */
|
|
1406
|
-
readonly
|
|
1444
|
+
readonly _DECIMAL_ONE: Decimal;
|
|
1407
1445
|
/** @internal */
|
|
1408
|
-
readonly
|
|
1446
|
+
readonly _DECIMAL_TWO: Decimal;
|
|
1409
1447
|
/** @internal */
|
|
1410
|
-
readonly
|
|
1448
|
+
readonly _DECIMAL_HALF: Decimal;
|
|
1411
1449
|
/** @internal */
|
|
1412
|
-
readonly
|
|
1450
|
+
readonly _DECIMAL_PI: Decimal;
|
|
1413
1451
|
/** @internal */
|
|
1414
|
-
readonly
|
|
1452
|
+
readonly _DECIMAL_NEGATIVE_ONE: Decimal;
|
|
1415
1453
|
/** The current scope */
|
|
1416
|
-
context: RuntimeScope;
|
|
1454
|
+
context: RuntimeScope | null;
|
|
1417
1455
|
/** Absolute time beyond which evaluation should not proceed
|
|
1418
1456
|
* @internal
|
|
1419
1457
|
*/
|
|
@@ -1424,7 +1462,7 @@ export interface IComputeEngine {
|
|
|
1424
1462
|
readonly iterationLimit: number;
|
|
1425
1463
|
/** @experimental */
|
|
1426
1464
|
readonly recursionLimit: number;
|
|
1427
|
-
defaultDomain: null |
|
|
1465
|
+
defaultDomain: null | BoxedDomain;
|
|
1428
1466
|
/** {@inheritDoc NumericMode} */
|
|
1429
1467
|
numericMode: NumericMode;
|
|
1430
1468
|
tolerance: number;
|
|
@@ -1445,13 +1483,17 @@ export interface IComputeEngine {
|
|
|
1445
1483
|
* If a definition existed previously, it is replaced.
|
|
1446
1484
|
*/
|
|
1447
1485
|
defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1448
|
-
getSymbolDefinition(name: string, wikidata?: string): undefined | BoxedSymbolDefinition;
|
|
1449
1486
|
/**
|
|
1450
|
-
*
|
|
1487
|
+
* Associate a new definition to a function in the current context.
|
|
1488
|
+
*
|
|
1489
|
+
* If a definition existed previously, it is replaced.
|
|
1451
1490
|
*/
|
|
1452
|
-
|
|
1491
|
+
defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1492
|
+
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
1493
|
+
/** Return `undefined` if no definition exist for this `head` */
|
|
1494
|
+
lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
|
|
1453
1495
|
/**
|
|
1454
|
-
*
|
|
1496
|
+
* Return a boxed expression from the input.
|
|
1455
1497
|
*
|
|
1456
1498
|
* The result may not be canonical.
|
|
1457
1499
|
*/
|
|
@@ -1462,14 +1504,22 @@ export interface IComputeEngine {
|
|
|
1462
1504
|
symbol(sym: string, metadata?: Metadata): BoxedExpression;
|
|
1463
1505
|
/** Return a canonical boxed string */
|
|
1464
1506
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
1465
|
-
/** Return a canonical boxed domain
|
|
1466
|
-
|
|
1467
|
-
|
|
1507
|
+
/** Return a canonical boxed domain.
|
|
1508
|
+
*
|
|
1509
|
+
* If the domain is invalid, may return an `["Error"]` expression
|
|
1510
|
+
*
|
|
1511
|
+
*/
|
|
1512
|
+
domain(domain: SemiBoxedExpression | BoxedDomain | string, metadata?: Metadata): BoxedDomain;
|
|
1513
|
+
/** Return a canonical lambda expression */
|
|
1514
|
+
lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
|
|
1515
|
+
/**
|
|
1516
|
+
* Return a canonical expression.
|
|
1468
1517
|
*
|
|
1469
1518
|
* Note that the result may not be a function, or may have a different
|
|
1470
1519
|
* `head` than the one specified.
|
|
1471
1520
|
*
|
|
1472
|
-
* For example
|
|
1521
|
+
* For example:
|
|
1522
|
+
* `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
|
|
1473
1523
|
*
|
|
1474
1524
|
*/
|
|
1475
1525
|
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
@@ -1480,15 +1530,15 @@ export interface IComputeEngine {
|
|
|
1480
1530
|
* In general, consider using `fn()` or `box()` instead.
|
|
1481
1531
|
*
|
|
1482
1532
|
* The result is canonical, but the caller has to ensure that all the
|
|
1483
|
-
* conditions are met (i.e. ops properly normalized and sorted, all
|
|
1484
|
-
* ops canonical, etc..) so that the result is actually canonical.
|
|
1533
|
+
* conditions are met (i.e. `ops` properly normalized and sorted, all
|
|
1534
|
+
* `ops` canonical, etc..) so that the result is actually canonical.
|
|
1485
1535
|
*/
|
|
1486
1536
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1487
1537
|
/** Shortcut for `this.fn("Error"...)`.
|
|
1488
1538
|
*
|
|
1489
1539
|
* The result is canonical.
|
|
1490
1540
|
*/
|
|
1491
|
-
error(
|
|
1541
|
+
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
1492
1542
|
/** Shortcut for `this.fn("Add"...)`.
|
|
1493
1543
|
*
|
|
1494
1544
|
* The result is canonical.
|
|
@@ -1545,7 +1595,7 @@ export interface IComputeEngine {
|
|
|
1545
1595
|
*/
|
|
1546
1596
|
serialize(expr: SemiBoxedExpression): LatexString;
|
|
1547
1597
|
/**
|
|
1548
|
-
* Options to control the
|
|
1598
|
+
* Options to control the serialization of MathJSON expression to LaTeX
|
|
1549
1599
|
* when using `this.latex` or `this.engine.serialize()`.
|
|
1550
1600
|
*
|
|
1551
1601
|
*
|
|
@@ -1574,7 +1624,7 @@ export interface IComputeEngine {
|
|
|
1574
1624
|
*
|
|
1575
1625
|
*
|
|
1576
1626
|
*/
|
|
1577
|
-
assume(symbol: LatexString | SemiBoxedExpression, domain:
|
|
1627
|
+
assume(symbol: LatexString | SemiBoxedExpression, domain: BoxedDomain): AssumeResult;
|
|
1578
1628
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
1579
1629
|
assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
|
|
1580
1630
|
/** Remove all assumptions about one or more symbols */
|
|
@@ -1582,7 +1632,7 @@ export interface IComputeEngine {
|
|
|
1582
1632
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1583
1633
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
1584
1634
|
pushScope(options?: {
|
|
1585
|
-
|
|
1635
|
+
symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
|
|
1586
1636
|
assumptions?: (LatexString | Expression | BoxedExpression)[];
|
|
1587
1637
|
scope?: Partial<Scope>;
|
|
1588
1638
|
}): void;
|
|
@@ -1605,7 +1655,7 @@ export interface IComputeEngine {
|
|
|
1605
1655
|
cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
|
|
1606
1656
|
readonly stats: ComputeEngineStats;
|
|
1607
1657
|
/** @internal */
|
|
1608
|
-
|
|
1658
|
+
reset(): void;
|
|
1609
1659
|
/** @internal */
|
|
1610
1660
|
_register(expr: BoxedExpression): void;
|
|
1611
1661
|
/** @internal */
|