@cortex-js/compute-engine 0.4.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/compute-engine.esm.js +18900 -18332
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +44 -6141
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +8 -7
- package/dist/types/compute-engine/boxed-expression/box.d.ts +3 -5
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +32 -6
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +7 -3
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -6
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +3 -3
- package/dist/types/compute-engine/compute-engine.d.ts +101 -50
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +2 -2
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/core.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -2
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -13
- package/dist/types/compute-engine/latex-syntax/public.d.ts +69 -44
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +3 -5
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +551 -228
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +3 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +3 -4
- package/dist/types/math-json.d.ts +3 -4
- package/package.json +17 -18
- package/dist/compute-engine.js +0 -23523
- package/dist/math-json.js +0 -6339
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import { BoxedExpression, IComputeEngine, Metadata } from '../public';
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* 0.6.0 */
|
|
2
|
+
import { BoxedExpression, Domain, DomainExpression, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
|
|
3
|
+
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
4
|
+
export declare class _Domain extends AbstractBoxedExpression implements Domain {
|
|
5
|
+
_value: DomainExpression;
|
|
6
|
+
private _hash;
|
|
7
|
+
constructor(ce: IComputeEngine, dom: DomainExpression, metadata?: Metadata);
|
|
8
|
+
get domainExpression(): DomainExpression;
|
|
9
|
+
get hash(): number;
|
|
10
|
+
get isCanonical(): boolean;
|
|
11
|
+
isEqual(rhs: BoxedExpression): boolean;
|
|
12
|
+
isSame(rhs: BoxedExpression): boolean;
|
|
13
|
+
isSubdomainOf(rhs: _Domain | string): boolean;
|
|
14
|
+
isMemberOf(expr: BoxedExpression): boolean;
|
|
15
|
+
get json(): Expression;
|
|
16
|
+
match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
|
|
5
17
|
get head(): string;
|
|
6
|
-
get domain():
|
|
7
|
-
|
|
18
|
+
get domain(): Domain;
|
|
19
|
+
get codomain(): Domain | null;
|
|
20
|
+
is(rhs: BoxedExpression): boolean;
|
|
21
|
+
get isNothing(): boolean;
|
|
22
|
+
get isFunction(): boolean;
|
|
23
|
+
get isPredicate(): boolean;
|
|
24
|
+
get isNumericFunction(): boolean;
|
|
25
|
+
get isBoolean(): boolean;
|
|
26
|
+
get isRealFunction(): boolean;
|
|
27
|
+
get isNumeric(): boolean;
|
|
28
|
+
get isLogicOperator(): boolean;
|
|
29
|
+
get isRelationalOperator(): boolean;
|
|
8
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Note that `boxDomain()` should only be called from `ComputeEngine`
|
|
33
|
+
*/
|
|
34
|
+
export declare function boxDomain(ce: IComputeEngine, dom: Domain | DomainExpression, metadata?: Metadata): Domain;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare function makeFunctionDefinition(engine: IComputeEngine, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
import { Expression } from '../../math-json/math-json-format';
|
|
3
|
-
import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOption } from '../public';
|
|
3
|
+
import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOption, Domain } from '../public';
|
|
4
4
|
/**
|
|
5
5
|
* BoxedFunction
|
|
6
6
|
*/
|
|
@@ -35,8 +35,10 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
|
|
|
35
35
|
get op3(): BoxedExpression;
|
|
36
36
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
37
37
|
_repairDefinition(): void;
|
|
38
|
+
/** Signature of the function */
|
|
39
|
+
get domain(): Domain;
|
|
38
40
|
/** Domain of the value of the function */
|
|
39
|
-
get
|
|
41
|
+
get valueDomain(): Domain;
|
|
40
42
|
isLess(rhs: BoxedExpression): boolean | undefined;
|
|
41
43
|
isLessEqual(rhs: BoxedExpression): boolean | undefined;
|
|
42
44
|
isGreater(rhs: BoxedExpression): boolean | undefined;
|
|
@@ -88,6 +90,8 @@ export declare function ungroup(expr: BoxedExpression): BoxedExpression;
|
|
|
88
90
|
* - 'last': apply `f` to all elements except the last
|
|
89
91
|
* - 'most': apply `f` to the last elements, skip the others
|
|
90
92
|
*
|
|
93
|
+
* Account for `Hold`, `ReleaseHold` and `Nothing`.
|
|
94
|
+
*
|
|
91
95
|
* If `f` returns `null`, the element is not added to the result
|
|
92
96
|
*/
|
|
93
97
|
export declare function holdMap(xs: BoxedExpression[], skip: 'all' | 'none' | 'first' | 'rest' | 'last' | 'most', f: (BoxedExpression: any) => BoxedExpression | null): BoxedExpression[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
import { Complex } from 'complex.js';
|
|
3
3
|
import { Expression } from '../../math-json/math-json-format';
|
|
4
|
-
import { BoxedExpression, IComputeEngine, Metadata, NOptions, PatternMatchOption, SimplifyOptions, Substitution } from '../public';
|
|
4
|
+
import { BoxedExpression, Domain, IComputeEngine, Metadata, NOptions, PatternMatchOption, SimplifyOptions, Substitution } from '../public';
|
|
5
5
|
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
6
6
|
/**
|
|
7
7
|
* BoxedNumber
|
|
@@ -34,7 +34,7 @@ export declare class BoxedNumber extends AbstractBoxedExpression {
|
|
|
34
34
|
get asFloat(): number | null;
|
|
35
35
|
get asSmallInteger(): number | null;
|
|
36
36
|
get asRational(): [number, number] | [null, null];
|
|
37
|
-
get domain():
|
|
37
|
+
get domain(): Domain;
|
|
38
38
|
get json(): Expression;
|
|
39
39
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
40
40
|
isSame(rhs: BoxedExpression): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
3
|
-
import { BoxedExpression, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOption, SemiBoxedExpression, Substitution } from '../public';
|
|
3
|
+
import { BoxedExpression, Domain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOption, SemiBoxedExpression, Substitution } from '../public';
|
|
4
4
|
export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
|
|
5
5
|
_pattern: BoxedExpression;
|
|
6
6
|
_canonicalPattern: BoxedExpression | undefined;
|
|
@@ -9,7 +9,7 @@ export declare class BoxedPattern extends AbstractBoxedExpression implements Pat
|
|
|
9
9
|
_purge(): undefined;
|
|
10
10
|
get json(): Expression;
|
|
11
11
|
get head(): string | BoxedExpression;
|
|
12
|
-
get
|
|
12
|
+
get valueDomain(): Domain;
|
|
13
13
|
get isCanonical(): boolean;
|
|
14
14
|
set isCanonical(_val: boolean);
|
|
15
15
|
isSame(rhs: BoxedExpression): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
3
|
-
import { BoxedExpression, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
|
|
3
|
+
import { BoxedExpression, Domain, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
|
|
4
4
|
/**
|
|
5
5
|
* BoxedString
|
|
6
6
|
*/
|
|
@@ -14,7 +14,7 @@ export declare class BoxedString extends AbstractBoxedExpression {
|
|
|
14
14
|
get isLiteral(): boolean;
|
|
15
15
|
get isCanonical(): boolean;
|
|
16
16
|
set isCanonical(_va: boolean);
|
|
17
|
-
get domain():
|
|
17
|
+
get domain(): Domain;
|
|
18
18
|
get complexity(): number;
|
|
19
19
|
get string(): string;
|
|
20
20
|
isEqual(rhs: BoxedExpression): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare function domainToFlags(dom:
|
|
1
|
+
/* 0.6.0 */
|
|
2
|
+
export declare function domainToFlags(dom: Domain | undefined | null): Partial<SymbolFlags>;
|
|
3
3
|
export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition {
|
|
4
4
|
private _engine;
|
|
5
5
|
private _value;
|
|
@@ -38,13 +38,13 @@ export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition
|
|
|
38
38
|
readonly hold: boolean;
|
|
39
39
|
private _def;
|
|
40
40
|
prototype?: BoxedFunctionDefinition;
|
|
41
|
-
self?:
|
|
41
|
+
self?: unknown;
|
|
42
42
|
constructor(ce: IComputeEngine, def: SymbolDefinition);
|
|
43
43
|
_purge(): undefined;
|
|
44
44
|
get value(): BoxedExpression | undefined;
|
|
45
|
-
set value(val: BoxedExpression | undefined);
|
|
46
|
-
get domain():
|
|
47
|
-
set domain(domain:
|
|
45
|
+
set value(val: BoxedExpression | number | undefined);
|
|
46
|
+
get domain(): Domain | undefined;
|
|
47
|
+
set domain(domain: Domain | undefined | string);
|
|
48
48
|
updateFlags(flags: Partial<SymbolFlags>): void;
|
|
49
49
|
setProps(props: Omit<Partial<BoxedSymbolDefinition>, 'domain' | 'value'>): void;
|
|
50
50
|
get number(): boolean | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
3
|
-
import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions,
|
|
3
|
+
import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption, Domain } from '../public';
|
|
4
4
|
/**
|
|
5
5
|
* BoxedSymbol
|
|
6
6
|
*
|
|
@@ -29,10 +29,10 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
|
|
|
29
29
|
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
30
30
|
_repairDefinition(): void;
|
|
31
31
|
get value(): BoxedExpression | undefined;
|
|
32
|
-
set value(value:
|
|
32
|
+
set value(value: BoxedExpression | number | undefined);
|
|
33
33
|
get numericValue(): BoxedExpression | undefined;
|
|
34
|
-
get domain():
|
|
35
|
-
set domain(d:
|
|
34
|
+
get domain(): Domain;
|
|
35
|
+
set domain(d: Domain);
|
|
36
36
|
get json(): Expression;
|
|
37
37
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
38
38
|
has(x: string | string[]): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare function isLatexString(s:
|
|
3
|
-
export declare function latexString(s:
|
|
1
|
+
/* 0.6.0 */
|
|
2
|
+
export declare function isLatexString(s: unknown): s is string;
|
|
3
|
+
export declare function latexString(s: unknown): string | null;
|
|
4
4
|
/**
|
|
5
5
|
* Return a multiple of the imaginary unit, e.g.
|
|
6
6
|
* - 'ImaginaryUnit'
|
|
@@ -1,33 +1,62 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import { DictionaryCategory, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
3
|
-
import { Decimal } from 'decimal.js';
|
|
1
|
+
/* 0.6.0 */
|
|
4
2
|
import { Complex } from 'complex.js';
|
|
3
|
+
import { Expression, MathJsonNumber } from '../math-json/math-json-format';
|
|
5
4
|
import { SignalMessage, WarningSignal } from '../common/signals';
|
|
6
|
-
import {
|
|
5
|
+
import type { DictionaryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
6
|
+
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, Dictionary, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, Domain, DomainExpression } from './public';
|
|
7
7
|
/**
|
|
8
|
-
* Create a `CustomEngine` instance to customize its behavior and the syntax
|
|
9
|
-
* and operation dictionaries it uses.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
|
|
10
|
+
*
|
|
11
|
+
* Use the instance to create expressions with `ce.parse()` and `ce.box()`.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const ce = new ComputeEngine();
|
|
16
|
+
* let expr = ce.parse("e^{i\\pi}");
|
|
17
|
+
* console.log(expr.N().latex);
|
|
18
|
+
* // ➔ "-1"
|
|
19
|
+
*
|
|
20
|
+
* expr = ce.box(["Expand", ["Power", ["Add", "a", "b"], 2]]);
|
|
21
|
+
* console.log(expr.evaluate().latex);
|
|
22
|
+
* // ➔ "a^2 + 2ab + b^2"
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
13
25
|
*/
|
|
14
26
|
export declare class ComputeEngine implements IComputeEngine {
|
|
27
|
+
/** @internal */
|
|
15
28
|
readonly ZERO: BoxedExpression;
|
|
29
|
+
/** @internal */
|
|
16
30
|
readonly ONE: BoxedExpression;
|
|
31
|
+
/** @internal */
|
|
17
32
|
readonly TWO: BoxedExpression;
|
|
33
|
+
/** @internal */
|
|
18
34
|
readonly HALF: BoxedExpression;
|
|
35
|
+
/** @internal */
|
|
19
36
|
readonly NEGATIVE_ONE: BoxedExpression;
|
|
37
|
+
/** @internal */
|
|
20
38
|
readonly I: BoxedExpression;
|
|
39
|
+
/** @internal */
|
|
21
40
|
readonly NAN: BoxedExpression;
|
|
41
|
+
/** @internal */
|
|
22
42
|
readonly POSITIVE_INFINITY: BoxedExpression;
|
|
43
|
+
/** @internal */
|
|
23
44
|
readonly NEGATIVE_INFINITY: BoxedExpression;
|
|
45
|
+
/** @internal */
|
|
24
46
|
readonly COMPLEX_INFINITY: BoxedExpression;
|
|
47
|
+
/** @internal */
|
|
25
48
|
DECIMAL_NAN: Decimal;
|
|
49
|
+
/** @internal */
|
|
26
50
|
DECIMAL_ZERO: Decimal;
|
|
51
|
+
/** @internal */
|
|
27
52
|
DECIMAL_ONE: Decimal;
|
|
53
|
+
/** @internal */
|
|
28
54
|
DECIMAL_TWO: Decimal;
|
|
55
|
+
/** @internal */
|
|
29
56
|
DECIMAL_HALF: Decimal;
|
|
57
|
+
/** @internal */
|
|
30
58
|
DECIMAL_PI: Decimal;
|
|
59
|
+
/** @internal */
|
|
31
60
|
DECIMAL_NEGATIVE_ONE: Decimal;
|
|
32
61
|
private _precision;
|
|
33
62
|
private _numericMode;
|
|
@@ -45,17 +74,22 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
45
74
|
private _commonSymbols;
|
|
46
75
|
private _commonNumbers;
|
|
47
76
|
private _commonDomains;
|
|
77
|
+
private _latexDictionary?;
|
|
48
78
|
/**
|
|
49
79
|
* The current scope.
|
|
50
80
|
*
|
|
51
|
-
* A scope
|
|
81
|
+
* A **scope** stores the definition of symbols and assumptions.
|
|
52
82
|
*
|
|
53
83
|
* Scopes form a stack, and definitions in more recent
|
|
54
84
|
* scopes can obscure definitions from older scopes.
|
|
55
85
|
*
|
|
86
|
+
* The `ce.context` property represents the current scope.
|
|
87
|
+
*
|
|
56
88
|
*/
|
|
57
89
|
context: RuntimeScope;
|
|
58
|
-
/** Absolute time beyond which evaluation should not proceed
|
|
90
|
+
/** Absolute time beyond which evaluation should not proceed.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
59
93
|
deadline?: number;
|
|
60
94
|
/**
|
|
61
95
|
* Return dictionaries suitable for the specified categories, or `"all"`
|
|
@@ -67,22 +101,37 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
67
101
|
*/
|
|
68
102
|
static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
|
|
69
103
|
/**
|
|
70
|
-
* Construct a new `ComputeEngine`
|
|
104
|
+
* Construct a new `ComputeEngine` instance.
|
|
105
|
+
*
|
|
106
|
+
* Dictionaries define functions and symbols (in `options.dictionaries`) and
|
|
107
|
+
* the LaTeX syntax (in `options.latexDictionaries`). If no dictionaries
|
|
108
|
+
* are provided, the default ones are used.
|
|
71
109
|
*
|
|
72
|
-
* If no `options.dictionaries` is provided a default set of dictionaries
|
|
73
|
-
* is used. The `ComputeEngine.getDictionaries()` method can be called
|
|
74
|
-
* to access some subset of dictionaries, e.g. for arithmetic, calculus, etc...
|
|
75
110
|
* The order of the dictionaries matter: the definitions from the later ones
|
|
76
111
|
* override the definitions from earlier ones. The first dictionary should
|
|
77
112
|
* be the `'core'` dictionary which include some basic definitions such
|
|
78
113
|
* as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
|
|
114
|
+
*
|
|
115
|
+
* @param options.numericMode The default mode is `auto`. Use `machine` to only
|
|
116
|
+
* use 64-bit float, use `decimal` to always use arbitrary precision floating
|
|
117
|
+
* point numbers or `complex` for complex numbers.
|
|
118
|
+
*
|
|
119
|
+
* @param options.numericPrecision Specific how many digits of precision for the
|
|
120
|
+
* numeric calculations. Default is 100.
|
|
121
|
+
*
|
|
122
|
+
* @param options.tolerance If the absolute value of the difference of two numbers
|
|
123
|
+
* is less than `toleranc`, they are considered equal. Used by `chop()` as well.
|
|
124
|
+
*
|
|
125
|
+
* @param options.defaultDomain If an unknown symbol is encountered, assume it should
|
|
126
|
+
* be a variable in this domain. **Default** `ExtendedRealNumber`
|
|
79
127
|
*/
|
|
80
128
|
constructor(options?: {
|
|
81
129
|
dictionaries?: Readonly<Dictionary>[];
|
|
130
|
+
latexDictionary?: readonly LatexDictionaryEntry[];
|
|
82
131
|
numericMode?: NumericMode;
|
|
83
|
-
assumptions?: (LatexString | Expression)[];
|
|
84
132
|
numericPrecision?: number;
|
|
85
133
|
tolerance?: number;
|
|
134
|
+
assumptions?: (LatexString | Expression)[];
|
|
86
135
|
defaultDomain?: string;
|
|
87
136
|
});
|
|
88
137
|
/** After the configuration of the engine has changed, clear the caches
|
|
@@ -90,15 +139,21 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
90
139
|
*
|
|
91
140
|
* This needs to happen for example when the numeric precision changes.
|
|
92
141
|
*
|
|
142
|
+
* @internal
|
|
93
143
|
*/
|
|
94
144
|
purge(): void;
|
|
145
|
+
/** @internal */
|
|
95
146
|
_register(expr: BoxedExpression): void;
|
|
147
|
+
/** @internal */
|
|
96
148
|
_unregister(expr: BoxedExpression): void;
|
|
97
149
|
get stats(): ComputeEngineStats;
|
|
150
|
+
/** @internal */
|
|
98
151
|
_decimal: Decimal.Constructor;
|
|
152
|
+
/** @internal */
|
|
99
153
|
decimal: (a: Decimal.Value) => Decimal;
|
|
154
|
+
/** @internal */
|
|
100
155
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
101
|
-
/** The precision, or number of significant digits, for
|
|
156
|
+
/** The precision, or number of significant digits, for numeric calculations
|
|
102
157
|
* such as when calling `ce.N()`.
|
|
103
158
|
*
|
|
104
159
|
* To make calculations using more digits, at the cost of expended memory
|
|
@@ -109,26 +164,24 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
109
164
|
*/
|
|
110
165
|
get precision(): number;
|
|
111
166
|
set precision(p: number | 'machine');
|
|
112
|
-
/**
|
|
113
|
-
* Mode to use for numerical calculations:
|
|
114
|
-
*
|
|
115
|
-
* - `auto`: use machine number if the precision is 15 or less, Decimal
|
|
116
|
-
* otherwise. Complex numbers are allowed.
|
|
117
|
-
* - `number`: use the machine format (64-bit float, 52-bit mantissa, about
|
|
118
|
-
* 15 digits of precision).
|
|
119
|
-
* - `decimal`: arbitrary precision floating-point numbers, as provided by the
|
|
120
|
-
* "decimal.js" library
|
|
121
|
-
* - `complex`: machine and complex numbers: two 64-bit float, as provided by the
|
|
122
|
-
* "complex.js" library
|
|
123
|
-
*
|
|
124
|
-
*/
|
|
125
167
|
get numericMode(): NumericMode;
|
|
126
168
|
set numericMode(f: NumericMode);
|
|
169
|
+
/** @experimental */
|
|
127
170
|
get timeLimit(): number;
|
|
171
|
+
/** @experimental */
|
|
128
172
|
get iterationLimit(): number;
|
|
173
|
+
/** @experimental */
|
|
129
174
|
get recursionLimit(): number;
|
|
130
|
-
|
|
131
|
-
|
|
175
|
+
/**
|
|
176
|
+
* If an unknown symbol is encountered, assume it should
|
|
177
|
+
* be a variable in this domain.
|
|
178
|
+
*
|
|
179
|
+
* If set to `null`, unknown symbols will trigger an error.
|
|
180
|
+
*
|
|
181
|
+
* **Default:** `"ExtendedRealNumber"`
|
|
182
|
+
*/
|
|
183
|
+
get defaultDomain(): Domain | null;
|
|
184
|
+
set defaultDomain(domain: Domain | string | null);
|
|
132
185
|
/**
|
|
133
186
|
* Values smaller than the tolerance are considered to be zero for the
|
|
134
187
|
* purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
|
|
@@ -136,10 +189,15 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
136
189
|
*/
|
|
137
190
|
get tolerance(): number;
|
|
138
191
|
set tolerance(val: number);
|
|
192
|
+
/** Replace a number that is close to 0 with the exact integer 0.
|
|
193
|
+
*
|
|
194
|
+
* How close to 0 the number has to be to be considered 0 is determined by {@link tolerance}.
|
|
195
|
+
*/
|
|
139
196
|
chop(n: number): number;
|
|
140
197
|
chop(n: Decimal): Decimal | 0;
|
|
141
198
|
chop(n: Complex): Complex | 0;
|
|
142
199
|
private get latexSyntax();
|
|
200
|
+
static getLatexDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
|
|
143
201
|
set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
|
|
144
202
|
get costFunction(): (expr: BoxedExpression) => number;
|
|
145
203
|
/**
|
|
@@ -148,11 +206,12 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
148
206
|
*/
|
|
149
207
|
getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
|
|
150
208
|
/**
|
|
151
|
-
* Return the definition for a function matching this head
|
|
209
|
+
* Return the definition for a function matching this head and
|
|
210
|
+
* these arguments.
|
|
152
211
|
*
|
|
153
212
|
* Start looking in the current scope, than up the scope chain.
|
|
154
213
|
*/
|
|
155
|
-
getFunctionDefinition(head: string): undefined | BoxedFunctionDefinition;
|
|
214
|
+
getFunctionDefinition(head: string, args?: BoxedExpression[]): undefined | BoxedFunctionDefinition;
|
|
156
215
|
/**
|
|
157
216
|
* Add (or replace) a definition for a symbol in the current scope.
|
|
158
217
|
*/
|
|
@@ -180,8 +239,11 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
180
239
|
* This can occur if:
|
|
181
240
|
* - an error has been signaled
|
|
182
241
|
* - the time limit or memory limit has been exceeded
|
|
242
|
+
*
|
|
243
|
+
* @internal
|
|
183
244
|
*/
|
|
184
245
|
shouldContinueExecution(): boolean;
|
|
246
|
+
/** @internal */
|
|
185
247
|
checkContinueExecution(): void;
|
|
186
248
|
assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
187
249
|
/**
|
|
@@ -196,9 +258,11 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
196
258
|
*/
|
|
197
259
|
signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
198
260
|
signal(sig: WarningSignal): void;
|
|
261
|
+
/** @internal */
|
|
199
262
|
cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
|
|
200
263
|
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
|
|
201
264
|
fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
265
|
+
/** @internal */
|
|
202
266
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
203
267
|
error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
|
|
204
268
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
@@ -211,16 +275,16 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
211
275
|
tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
212
276
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
213
277
|
symbol(sym: string, metadata?: Metadata): BoxedExpression;
|
|
214
|
-
domain(domain: BoxedExpression |
|
|
278
|
+
domain(domain: BoxedExpression | DomainExpression | Domain, metadata?: Metadata): Domain;
|
|
215
279
|
number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
|
|
216
280
|
rules(rules: Rule[]): BoxedRuleSet;
|
|
217
281
|
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
218
|
-
parse(s: null): null;
|
|
219
282
|
parse(s: LatexString | string): BoxedExpression;
|
|
283
|
+
parse(s: null): null;
|
|
220
284
|
parse(s: LatexString | string | null): null | BoxedExpression;
|
|
221
285
|
serialize(x: Expression | BoxedExpression): string;
|
|
222
|
-
get latexOptions():
|
|
223
|
-
set latexOptions(opts: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions);
|
|
286
|
+
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
287
|
+
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
224
288
|
get jsonSerializationOptions(): JsonSerializationOptions;
|
|
225
289
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
226
290
|
/**
|
|
@@ -233,19 +297,6 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
233
297
|
* ```
|
|
234
298
|
*/
|
|
235
299
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
236
|
-
/**
|
|
237
|
-
* Add an assumption.
|
|
238
|
-
*
|
|
239
|
-
* Return `contradiction` if the new assumption is incompatible with previous
|
|
240
|
-
* ones.
|
|
241
|
-
*
|
|
242
|
-
* Return `tautology` if the new assumption is redundant with previous ones.
|
|
243
|
-
*
|
|
244
|
-
* Return `ok` if the assumption was successfully added to the assumption set.
|
|
245
|
-
*
|
|
246
|
-
* Note that the assumption is put into canonical form before being added.
|
|
247
|
-
*
|
|
248
|
-
*/
|
|
249
300
|
assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
|
|
250
301
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
251
302
|
forget(symbol: undefined | string | string[]): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
/** The canonical form of `Add`:
|
|
3
3
|
* - removes `0`
|
|
4
4
|
* - adds up small integers and rational numbers
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* - groups repeated terms (a + a -> 2a)
|
|
7
7
|
* */
|
|
8
8
|
export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
9
|
-
export declare function domainAdd(
|
|
9
|
+
export declare function domainAdd(_ce: IComputeEngine, args: BoxedExpression[]): Domain | string | null;
|
|
10
10
|
export declare function numEvalAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
|
|
11
11
|
export declare function processAdd(ce: IComputeEngine, args: BoxedExpression[], _mode: 'simplify' | 'evaluate'): BoxedExpression | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const ARITHMETIC_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const COLLECTIONS_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const CORE_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const LOGIC_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const POLYNOMIALS_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const RELOP_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const SETS_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const TRIGONOMETRY_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const DEFINITIONS_CALCULUS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.6.0 */
|
|
2
2
|
export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
|