@cortex-js/compute-engine 0.15.0 → 0.17.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 +1 -1
- package/dist/compute-engine.esm.js +7319 -5823
- package/dist/compute-engine.js +7319 -5823
- package/dist/compute-engine.min.esm.js +47 -25822
- package/dist/compute-engine.min.js +19 -25805
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -281
- package/dist/types/common/ansi-codes.d.ts +15 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/utils.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 +15 -19
- package/dist/types/compute-engine/boxed-expression/box.d.ts +8 -3
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +9 -9
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +16 -28
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +27 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +9 -21
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +6 -5
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +4 -4
- 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 +13 -12
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +21 -15
- 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 +2 -2
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +30 -9
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +32 -12
- package/dist/types/compute-engine/compile.d.ts +18 -2
- package/dist/types/compute-engine/compute-engine.d.ts +77 -55
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +4 -21
- package/dist/types/compute-engine/function-utils.d.ts +124 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-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-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.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 +31 -13
- 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 +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +2 -2
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +3 -2
- package/dist/types/compute-engine/library/calculus.d.ts +2 -2
- package/dist/types/compute-engine/library/collections.d.ts +2 -2
- package/dist/types/compute-engine/library/complex.d.ts +2 -2
- package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -2
- package/dist/types/compute-engine/library/domains.d.ts +9 -9
- package/dist/types/compute-engine/library/library.d.ts +7 -5
- package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
- package/dist/types/compute-engine/library/logic.d.ts +2 -2
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/sets.d.ts +2 -2
- package/dist/types/compute-engine/library/statistics.d.ts +2 -2
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
- package/dist/types/compute-engine/library/utils.d.ts +1 -3
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +3 -2
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric.d.ts +61 -3
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +281 -189
- 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/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +20 -0
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -2
- 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 +5 -3
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +4 -3
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +25 -22
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.17.0 */
|
|
2
2
|
import { Expression } from '../../math-json/math-json-format';
|
|
3
|
-
import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution, EvaluateOptions } from '../public';
|
|
3
|
+
import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution, EvaluateOptions, BoxedBaseDefinition, Hold } from '../public';
|
|
4
4
|
/**
|
|
5
5
|
* BoxedFunction
|
|
6
6
|
*/
|
|
7
|
-
export declare class BoxedFunction extends
|
|
8
|
-
private _scope;
|
|
7
|
+
export declare class BoxedFunction extends _BoxedExpression {
|
|
9
8
|
private readonly _head;
|
|
10
9
|
private readonly _ops;
|
|
11
10
|
private _canonical;
|
|
11
|
+
private _scope;
|
|
12
12
|
private _def;
|
|
13
13
|
private _isPure;
|
|
14
|
-
/** The domain of the value of the function applied to its arguments */
|
|
15
14
|
private _codomain;
|
|
16
|
-
/** The cached values of applying the tail to the head.
|
|
17
|
-
* If the function is not pure, it is never cached.
|
|
18
|
-
*/
|
|
19
15
|
private _value;
|
|
20
16
|
private _numericValue;
|
|
21
17
|
private _hash;
|
|
22
18
|
constructor(ce: IComputeEngine, head: string | BoxedExpression, ops: BoxedExpression[], options?: {
|
|
23
19
|
metadata?: Metadata;
|
|
24
20
|
canonical?: boolean;
|
|
25
|
-
def?: BoxedFunctionDefinition;
|
|
26
21
|
});
|
|
27
22
|
get hash(): number;
|
|
23
|
+
bind(): void;
|
|
24
|
+
reset(): void;
|
|
28
25
|
get isCanonical(): boolean;
|
|
29
26
|
set isCanonical(val: boolean);
|
|
30
27
|
get isPure(): boolean;
|
|
@@ -48,13 +45,9 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
|
|
|
48
45
|
/** `isSame` is structural/symbolic equality */
|
|
49
46
|
isSame(rhs: BoxedExpression): boolean;
|
|
50
47
|
match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
51
|
-
unbind(): void;
|
|
52
|
-
get wikidata(): string | undefined;
|
|
53
|
-
get description(): string[] | undefined;
|
|
54
|
-
get url(): string | undefined;
|
|
55
48
|
get complexity(): number | undefined;
|
|
49
|
+
get baseDefinition(): BoxedBaseDefinition | undefined;
|
|
56
50
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
57
|
-
bind(_scope: RuntimeScope | null): void;
|
|
58
51
|
get value(): BoxedExpression | undefined;
|
|
59
52
|
/** `isEqual` is mathematical equality */
|
|
60
53
|
isEqual(rhs: BoxedExpression): boolean;
|
|
@@ -79,18 +72,13 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
|
|
|
79
72
|
get isComplex(): boolean | undefined;
|
|
80
73
|
get isImaginary(): boolean | undefined;
|
|
81
74
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
82
|
-
get domain(): BoxedDomain;
|
|
75
|
+
get domain(): BoxedDomain | undefined;
|
|
83
76
|
simplify(options?: SimplifyOptions): BoxedExpression;
|
|
84
77
|
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
85
78
|
N(options?: NOptions): BoxedExpression;
|
|
86
79
|
solve(vars: string[]): null | BoxedExpression[];
|
|
87
80
|
}
|
|
88
81
|
export declare function makeCanonicalFunction(ce: IComputeEngine, head: string | BoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
89
|
-
/** Apply arguments to an expression. If the expression is a lambda expression
|
|
90
|
-
* its wildcard arguments are substituted before being evaluated. Otherwise
|
|
91
|
-
* the expression is just evaluated.
|
|
92
|
-
*/
|
|
93
|
-
export declare function apply(fn: BoxedExpression, args: BoxedExpression[]): BoxedExpression;
|
|
94
82
|
/** Apply the function `f` to elements of `xs`, except to the elements
|
|
95
83
|
* described by `skip`:
|
|
96
84
|
* - `all`: don't apply f to any elements
|
|
@@ -104,4 +92,4 @@ export declare function apply(fn: BoxedExpression, args: BoxedExpression[]): Box
|
|
|
104
92
|
*
|
|
105
93
|
* If `f` returns `null`, the element is not added to the result
|
|
106
94
|
*/
|
|
107
|
-
export declare function holdMap(xs: BoxedExpression[], skip:
|
|
95
|
+
export declare function holdMap(xs: BoxedExpression[], skip: Hold, associativeHead: string, f: (x: BoxedExpression) => BoxedExpression | null): BoxedExpression[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { Decimal } from 'decimal.js';
|
|
3
3
|
import { Expression } from '../../math-json/math-json-format';
|
|
4
|
-
import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution } from '../public';
|
|
5
|
-
import {
|
|
4
|
+
import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution, EvaluateOptions } from '../public';
|
|
5
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
6
6
|
/**
|
|
7
7
|
* BoxedNumber
|
|
8
8
|
*/
|
|
9
|
-
export declare class BoxedNumber extends
|
|
9
|
+
export declare class BoxedNumber extends _BoxedExpression {
|
|
10
10
|
protected readonly _value: number | Decimal | Complex | Rational;
|
|
11
11
|
private _domain;
|
|
12
12
|
private _hash;
|
|
@@ -81,5 +81,6 @@ export declare class BoxedNumber extends AbstractBoxedExpression {
|
|
|
81
81
|
get isExtendedComplex(): boolean | undefined;
|
|
82
82
|
get canonical(): BoxedExpression;
|
|
83
83
|
simplify(_options?: SimplifyOptions): BoxedExpression;
|
|
84
|
+
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
84
85
|
N(_options?: NOptions): BoxedExpression;
|
|
85
86
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
3
3
|
import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOptions, SemiBoxedExpression, Substitution } from '../public';
|
|
4
|
-
export declare class BoxedPattern extends
|
|
4
|
+
export declare class BoxedPattern extends _BoxedExpression implements Pattern {
|
|
5
5
|
_pattern: BoxedExpression;
|
|
6
6
|
constructor(ce: IComputeEngine, pattern: LatexString | SemiBoxedExpression, metadata?: Metadata);
|
|
7
7
|
get hash(): number;
|
|
8
|
-
|
|
8
|
+
reset(): void;
|
|
9
9
|
get json(): Expression;
|
|
10
10
|
get head(): string | BoxedExpression;
|
|
11
11
|
get domain(): BoxedDomain;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
3
3
|
import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution } from '../public';
|
|
4
4
|
/**
|
|
5
5
|
* BoxedString
|
|
6
6
|
*/
|
|
7
|
-
export declare class BoxedString extends
|
|
7
|
+
export declare class BoxedString extends _BoxedExpression {
|
|
8
8
|
private readonly _string;
|
|
9
9
|
constructor(ce: IComputeEngine, expr: string, metadata?: Metadata);
|
|
10
10
|
get hash(): number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.17.0 */
|
|
2
2
|
/**
|
|
3
|
-
* THEORY OF OPERATIONS
|
|
3
|
+
* ## THEORY OF OPERATIONS
|
|
4
4
|
*
|
|
5
5
|
* - The value or domain of a constant cannot be changed.
|
|
6
6
|
* - If set explicitly, the value is the source of truth: it overrides any
|
|
@@ -18,24 +18,25 @@
|
|
|
18
18
|
* Otherwise, the stored flags are (the stored flags are also set when the domain is changed)
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
export declare class
|
|
21
|
+
export declare class _BoxedSymbolDefinition implements BoxedSymbolDefinition {
|
|
22
22
|
readonly name: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
wikidata?: string;
|
|
24
|
+
description?: string | string[];
|
|
25
|
+
url?: string;
|
|
26
26
|
private _engine;
|
|
27
27
|
readonly scope: RuntimeScope | undefined;
|
|
28
28
|
private _defValue?;
|
|
29
29
|
private _value;
|
|
30
30
|
private _domain;
|
|
31
|
+
inferredDomain: boolean;
|
|
31
32
|
private _flags;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
private _at;
|
|
35
|
-
at?: (index: string | number) => undefined | BoxedExpression;
|
|
33
|
+
constant: boolean;
|
|
34
|
+
holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
|
|
36
35
|
prototype?: BoxedFunctionDefinition;
|
|
37
36
|
self?: unknown;
|
|
38
37
|
constructor(ce: IComputeEngine, name: string, def: SymbolDefinition);
|
|
38
|
+
/** The symbol was previously inferred, but now it has a declaration. Update the def accordingly (we can't replace defs, as other expressions may be referencing them) */
|
|
39
|
+
update(def: SymbolDefinition): void;
|
|
39
40
|
reset(): void;
|
|
40
41
|
get value(): BoxedExpression | undefined;
|
|
41
42
|
set value(val: SemiBoxedExpression | number | undefined);
|
|
@@ -89,6 +90,6 @@ export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition
|
|
|
89
90
|
set prime(val: boolean | undefined);
|
|
90
91
|
get composite(): boolean | undefined;
|
|
91
92
|
set composite(val: boolean | undefined);
|
|
92
|
-
updateFlags(flags: Partial<
|
|
93
|
+
updateFlags(flags: Partial<NumericFlags>): void;
|
|
93
94
|
}
|
|
94
|
-
export declare function domainToFlags(dom: BoxedDomain | undefined | null): Partial<
|
|
95
|
+
export declare function domainToFlags(dom: BoxedDomain | undefined | null): Partial<NumericFlags>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { Decimal } from 'decimal.js';
|
|
3
|
+
import { Expression } from '../../math-json/math-json-format';
|
|
4
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
3
5
|
import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
|
|
4
6
|
/**
|
|
5
7
|
* BoxedSymbol
|
|
@@ -14,9 +16,9 @@ import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, E
|
|
|
14
16
|
* not a function expression, i.e. `Sin`, not `["Sin", "Pi"]`. This is used
|
|
15
17
|
* for example in `["InverseFunction", "Sin"]`
|
|
16
18
|
*/
|
|
17
|
-
export declare class BoxedSymbol extends
|
|
19
|
+
export declare class BoxedSymbol extends _BoxedExpression {
|
|
18
20
|
private _scope;
|
|
19
|
-
protected
|
|
21
|
+
protected _id: string;
|
|
20
22
|
private _hash;
|
|
21
23
|
private _def;
|
|
22
24
|
constructor(ce: IComputeEngine, name: string, options?: {
|
|
@@ -25,19 +27,18 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
|
|
|
25
27
|
def?: BoxedSymbolDefinition | BoxedFunctionDefinition;
|
|
26
28
|
});
|
|
27
29
|
get hash(): number;
|
|
28
|
-
unbind(): void;
|
|
29
30
|
get isPure(): boolean;
|
|
30
31
|
get json(): Expression;
|
|
31
32
|
get scope(): RuntimeScope | null;
|
|
32
|
-
/** A free variable either has no definition, or it has a definition, but no value */
|
|
33
|
-
get isFree(): boolean;
|
|
34
33
|
get isConstant(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Associate a definition with this symbol
|
|
36
|
+
*/
|
|
37
|
+
bind(): void;
|
|
38
|
+
reset(): void;
|
|
35
39
|
get isCanonical(): boolean;
|
|
36
40
|
set isCanonical(val: boolean);
|
|
37
41
|
get canonical(): BoxedExpression;
|
|
38
|
-
get wikidata(): string | undefined;
|
|
39
|
-
get description(): string[] | undefined;
|
|
40
|
-
get url(): string | undefined;
|
|
41
42
|
get complexity(): number;
|
|
42
43
|
get head(): string;
|
|
43
44
|
get symbol(): string;
|
|
@@ -45,12 +46,17 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
|
|
|
45
46
|
get baseDefinition(): BoxedBaseDefinition | undefined;
|
|
46
47
|
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
47
48
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
48
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Subsequence inferences will narrow the domain of the symbol.
|
|
51
|
+
* f(:integer), g(:real)
|
|
52
|
+
* g(x) => x:real
|
|
53
|
+
* f(x) => x:integer narrowed from integer to real
|
|
54
|
+
*/
|
|
55
|
+
infer(domain: BoxedDomain): boolean;
|
|
49
56
|
get value(): BoxedExpression | undefined;
|
|
50
|
-
set value(value: BoxedExpression | number | undefined);
|
|
51
|
-
get domain(): BoxedDomain;
|
|
52
|
-
set domain(inDomain:
|
|
53
|
-
get explicitDomain(): BoxedDomain | undefined;
|
|
57
|
+
set value(value: boolean | string | Decimal | Complex | [num: number, denom: number] | BoxedExpression | number | undefined);
|
|
58
|
+
get domain(): BoxedDomain | undefined;
|
|
59
|
+
set domain(inDomain: DomainExpression | BoxedDomain);
|
|
54
60
|
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
55
61
|
has(x: string | string[]): boolean;
|
|
56
62
|
isSame(rhs: BoxedExpression): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.17.0 */
|
|
2
2
|
import { Expression } from '../../math-json/math-json-format';
|
|
3
3
|
import { BoxedExpression, IComputeEngine } from '../public';
|
|
4
4
|
export declare function isLatexString(s: unknown): s is string;
|
|
@@ -12,15 +12,36 @@ export declare function latexString(s: unknown): string | null;
|
|
|
12
12
|
* - ['Multiply', 'ImaginaryUnit', 5]
|
|
13
13
|
*/
|
|
14
14
|
export declare function getImaginaryCoef(expr: BoxedExpression): number | null;
|
|
15
|
+
export declare function getSymbols(expr: BoxedExpression, result: Set<string>): void;
|
|
15
16
|
/**
|
|
16
|
-
* Return the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
export declare function
|
|
23
|
-
|
|
17
|
+
* Return the unknowns in the expression, recursively.
|
|
18
|
+
*
|
|
19
|
+
* An unknown is an identifier (symbol or function) that is not bound
|
|
20
|
+
* to a value.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function getUnknowns(expr: BoxedExpression, result: Set<string>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Return the free variables (non local variable) in the expression,
|
|
26
|
+
* recursively.
|
|
27
|
+
*
|
|
28
|
+
* A free variable is an identifier that is not an argument to a function,
|
|
29
|
+
* or a local variable.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export declare function getFreeVariables(expr: BoxedExpression, result: Set<string>): void;
|
|
33
|
+
/** Return the local variables in the expression.
|
|
34
|
+
*
|
|
35
|
+
* A local variable is an identifier that is declared with a `Declare`
|
|
36
|
+
* expression in a `Block` expression.
|
|
37
|
+
*
|
|
38
|
+
* Note that the canonical form of a `Block` expression will hoist all
|
|
39
|
+
* `Declare` expressions to the top of the block. `Assign` expressions
|
|
40
|
+
* of undeclared variables will also have a matching `Declare` expressions
|
|
41
|
+
* hoisted.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export declare function getLocalVariables(expr: BoxedExpression, result: Set<string>): void;
|
|
24
45
|
export declare function getSubexpressions(expr: BoxedExpression, head: string): BoxedExpression[];
|
|
25
46
|
/**
|
|
26
47
|
* For any numeric result, if `bignumPreferred()` is true, calculate using
|
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
/**
|
|
3
|
+
* Check that the number of arguments is as expected.
|
|
4
|
+
*
|
|
5
|
+
* Converts the arguments to canonical, and flattens the sequence.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkArity(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
|
|
3
8
|
/**
|
|
4
9
|
* Validation of arguments is normally done by checking the signature of the
|
|
5
10
|
* function vs the arguments of the expression. However, we have a fastpath
|
|
6
11
|
* for some common operations (add, multiply, power, neg, etc...) that bypasses
|
|
7
|
-
* the regular checks. This is its replacements.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
12
|
+
* the regular checks. This is its replacements.
|
|
13
|
+
*
|
|
14
|
+
* Since all those fastpath functions are numeric (i.e. have numeric arguments
|
|
15
|
+
* and a numeric result), we do a simple numeric check of all arguments, and
|
|
16
|
+
* verify we have the number of expected arguments.
|
|
17
|
+
*
|
|
18
|
+
* Converts the arguments to canonical, and flattens the sequence.
|
|
11
19
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
export declare function checkNumericArgs(ce: IComputeEngine, ops: BoxedExpression[], options?: number | {
|
|
21
|
+
count?: number;
|
|
22
|
+
flatten?: boolean | string;
|
|
23
|
+
}): BoxedExpression[];
|
|
24
|
+
/**
|
|
25
|
+
* Check that an argument is of the expected domain.
|
|
26
|
+
*
|
|
27
|
+
* Converts the arguments to canonical
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkArg(ce: IComputeEngine, arg: BoxedExpression | undefined | null, dom: BoxedDomain | DomainLiteral | undefined): BoxedExpression;
|
|
30
|
+
export declare function checkArgs(ce: IComputeEngine, args: BoxedExpression[], doms: (BoxedDomain | DomainLiteral)[]): BoxedExpression[];
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* If the arguments match the parameters, return null.
|
|
34
|
+
*
|
|
35
|
+
* Otherwise return a list of expressions indicating the mismatched
|
|
36
|
+
* arguments.
|
|
15
37
|
*
|
|
16
38
|
*/
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function validateArgument(ce: IComputeEngine, arg: BoxedExpression | undefined, dom: BoxedDomain | DomainLiteral | undefined): BoxedExpression;
|
|
19
|
-
export declare function validateArguments(ce: IComputeEngine, args: BoxedExpression[], doms: (BoxedDomain | DomainLiteral)[]): BoxedExpression[];
|
|
39
|
+
export declare function adjustArguments(ce: IComputeEngine, ops: BoxedExpression[], hold: Hold, params: BoxedDomain[], optParams: BoxedDomain[], restParam: BoxedDomain | null): BoxedExpression[] | null;
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { BoxedExpression } from './public';
|
|
2
3
|
export type CompiledType = boolean | number | string | object;
|
|
4
|
+
export type CompiledOperators = Record<MathJsonIdentifier, [
|
|
5
|
+
op: string,
|
|
6
|
+
prec: number
|
|
7
|
+
]>;
|
|
8
|
+
export type CompiledFunctions = {
|
|
9
|
+
[id: MathJsonIdentifier]: string | ((args: BoxedExpression[], compile: (expr: BoxedExpression) => CompiledType) => CompiledType);
|
|
10
|
+
};
|
|
11
|
+
export type CompileTarget = {
|
|
12
|
+
operators?: (op: MathJsonIdentifier) => [op: string, prec: number];
|
|
13
|
+
functions?: (id: MathJsonIdentifier) => string | ((...args: CompiledType[]) => CompiledType);
|
|
14
|
+
var: (id: MathJsonIdentifier) => string | undefined;
|
|
15
|
+
string: (str: string) => string;
|
|
16
|
+
number: (n: number) => string;
|
|
17
|
+
};
|
|
3
18
|
/** This is an extension of the Function class that allows us to pass
|
|
4
19
|
* a custom scope for "global" functions. */
|
|
5
20
|
export declare class ComputeEngineFunction extends Function {
|
|
6
21
|
private sys;
|
|
7
22
|
constructor(body: any);
|
|
8
23
|
}
|
|
24
|
+
export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
|
|
9
25
|
export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
|
|
10
|
-
export declare function compile(expr: BoxedExpression,
|
|
26
|
+
export declare function compile(expr: BoxedExpression, target: CompileTarget, prec?: number): CompiledType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.17.0 */
|
|
2
|
+
import { Decimal } from 'decimal.js';
|
|
3
3
|
import { Expression, MathJsonNumber } from '../math-json/math-json-format';
|
|
4
|
-
import type { LibraryCategory,
|
|
5
|
-
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine,
|
|
4
|
+
import type { LibraryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
5
|
+
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue, DomainLiteral } from './public';
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
|
|
@@ -23,24 +23,25 @@ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefi
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export declare class ComputeEngine implements IComputeEngine {
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
readonly
|
|
32
|
-
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
readonly
|
|
38
|
-
|
|
39
|
-
readonly
|
|
40
|
-
|
|
41
|
-
readonly
|
|
42
|
-
|
|
43
|
-
readonly
|
|
26
|
+
readonly Anything: BoxedDomain;
|
|
27
|
+
readonly Void: BoxedDomain;
|
|
28
|
+
readonly Strings: BoxedDomain;
|
|
29
|
+
readonly Booleans: BoxedDomain;
|
|
30
|
+
readonly Numbers: BoxedDomain;
|
|
31
|
+
readonly True: BoxedExpression;
|
|
32
|
+
readonly False: BoxedExpression;
|
|
33
|
+
readonly Pi: BoxedExpression;
|
|
34
|
+
readonly E: BoxedExpression;
|
|
35
|
+
readonly Nothing: BoxedExpression;
|
|
36
|
+
readonly Zero: BoxedExpression;
|
|
37
|
+
readonly One: BoxedExpression;
|
|
38
|
+
readonly Half: BoxedExpression;
|
|
39
|
+
readonly NegativeOne: BoxedExpression;
|
|
40
|
+
readonly I: BoxedExpression;
|
|
41
|
+
readonly NaN: BoxedExpression;
|
|
42
|
+
readonly PositiveInfinity: BoxedExpression;
|
|
43
|
+
readonly NegativeInfinity: BoxedExpression;
|
|
44
|
+
readonly ComplexInfinity: BoxedExpression;
|
|
44
45
|
/** @internal */
|
|
45
46
|
_BIGNUM_NAN: Decimal;
|
|
46
47
|
/** @internal */
|
|
@@ -93,8 +94,6 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
93
94
|
private _commonNumbers;
|
|
94
95
|
/** @internal */
|
|
95
96
|
private _commonDomains;
|
|
96
|
-
/** @internal */
|
|
97
|
-
private _latexDictionary?;
|
|
98
97
|
/**
|
|
99
98
|
* The current scope.
|
|
100
99
|
*
|
|
@@ -121,19 +120,20 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
121
120
|
* manipulate them.
|
|
122
121
|
*
|
|
123
122
|
*/
|
|
124
|
-
static getStandardLibrary(categories?: LibraryCategory[] | LibraryCategory | 'all'):
|
|
123
|
+
static getStandardLibrary(categories?: LibraryCategory[] | LibraryCategory | 'all'): readonly IdentifierDefinitions[];
|
|
125
124
|
/**
|
|
126
125
|
* Construct a new `ComputeEngine` instance.
|
|
127
126
|
*
|
|
128
127
|
* Identifier tables define functions and symbols (in `options.ids`).
|
|
129
|
-
* If no table is provided the
|
|
128
|
+
* If no table is provided the MathJSON Standard Library is used (`ComputeEngine.getStandardLibrary()`)
|
|
130
129
|
*
|
|
131
130
|
* The LaTeX syntax dictionary is defined in `options.latexDictionary`.
|
|
132
131
|
*
|
|
133
132
|
* The order of the dictionaries matter: the definitions from the later ones
|
|
134
133
|
* override the definitions from earlier ones. The first dictionary should
|
|
135
134
|
* be the `'core'` dictionary which include some basic definitions such
|
|
136
|
-
* as domains (`
|
|
135
|
+
* as domains (`Booleans`, `Numbers`, etc...) that are used by later
|
|
136
|
+
* dictionaries.
|
|
137
137
|
*
|
|
138
138
|
* @param options.numericMode The default mode is `"auto"`. Use `"machine"`
|
|
139
139
|
* to perform numeric calculations using 64-bit floats. Use `"bignum"` to
|
|
@@ -146,17 +146,12 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
146
146
|
* @param options.tolerance If the absolute value of the difference of two
|
|
147
147
|
* numbers is less than `tolerance`, they are considered equal. Used by
|
|
148
148
|
* `chop()` as well.
|
|
149
|
-
*
|
|
150
|
-
* @param options.defaultDomain If an unknown symbol is encountered, assume
|
|
151
|
-
* this is its domain. **Default** `ExtendedRealNumber`
|
|
152
149
|
*/
|
|
153
150
|
constructor(options?: {
|
|
154
151
|
numericMode?: NumericMode;
|
|
155
152
|
numericPrecision?: number;
|
|
156
|
-
ids?:
|
|
157
|
-
latexDictionary?: readonly LatexDictionaryEntry[];
|
|
153
|
+
ids?: readonly IdentifierDefinitions[];
|
|
158
154
|
tolerance?: number;
|
|
159
|
-
defaultDomain?: string;
|
|
160
155
|
});
|
|
161
156
|
get latexDictionary(): readonly LatexDictionaryEntry[];
|
|
162
157
|
set latexDictionary(dic: readonly LatexDictionaryEntry[]);
|
|
@@ -196,16 +191,6 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
196
191
|
get iterationLimit(): number;
|
|
197
192
|
/** @experimental */
|
|
198
193
|
get recursionLimit(): number;
|
|
199
|
-
/**
|
|
200
|
-
* If an unknown symbol is encountered, assume it should
|
|
201
|
-
* be a variable in this domain.
|
|
202
|
-
*
|
|
203
|
-
* If set to `null`, unknown symbols will trigger an error.
|
|
204
|
-
*
|
|
205
|
-
* **Default:** `"ExtendedRealNumber"`
|
|
206
|
-
*/
|
|
207
|
-
get defaultDomain(): BoxedDomain | null;
|
|
208
|
-
set defaultDomain(domain: BoxedDomain | string | null);
|
|
209
194
|
/**
|
|
210
195
|
* Values smaller than the tolerance are considered to be zero for the
|
|
211
196
|
* purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
|
|
@@ -225,7 +210,7 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
225
210
|
isBignum(a: unknown): a is Decimal;
|
|
226
211
|
isComplex(a: unknown): a is Complex;
|
|
227
212
|
private get latexSyntax();
|
|
228
|
-
static getLatexDictionary(domain?: LibraryCategory | 'all'): Readonly<
|
|
213
|
+
static getLatexDictionary(domain?: LibraryCategory | 'all'): readonly Readonly<object>[];
|
|
229
214
|
set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
|
|
230
215
|
get costFunction(): (expr: BoxedExpression) => number;
|
|
231
216
|
/**
|
|
@@ -248,21 +233,59 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
248
233
|
* Add (or replace) a definition for a symbol in the current scope.
|
|
249
234
|
*/
|
|
250
235
|
defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
236
|
+
_defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
251
237
|
defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
238
|
+
_defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
252
239
|
/**
|
|
253
240
|
*
|
|
254
241
|
* Create a new scope and add it to the top of the scope stack
|
|
255
242
|
*
|
|
256
|
-
* The `
|
|
243
|
+
* The `scope` argument can be used to specify custom precision,
|
|
257
244
|
* etc... for this scope
|
|
258
245
|
*
|
|
246
|
+
*
|
|
259
247
|
*/
|
|
260
|
-
pushScope(
|
|
248
|
+
pushScope(scope?: Partial<Scope>): IComputeEngine;
|
|
261
249
|
/** Remove the topmost scope from the scope stack.
|
|
262
250
|
*/
|
|
263
|
-
popScope():
|
|
264
|
-
|
|
265
|
-
|
|
251
|
+
popScope(): IComputeEngine;
|
|
252
|
+
swapScope(scope: RuntimeScope | null): RuntimeScope | null;
|
|
253
|
+
resetContext(): void;
|
|
254
|
+
_printScope(options?: {
|
|
255
|
+
details?: boolean;
|
|
256
|
+
maxDepth?: number;
|
|
257
|
+
}, scope?: RuntimeScope | null, depth?: number): RuntimeScope | null;
|
|
258
|
+
/**
|
|
259
|
+
* Declare one or more identifiers:
|
|
260
|
+
*
|
|
261
|
+
* associate an identifier with a definition, at minimum a domain, optionally
|
|
262
|
+
* a value and some other flags.
|
|
263
|
+
*/
|
|
264
|
+
declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
265
|
+
declare(identifiers: {
|
|
266
|
+
[id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
267
|
+
}): IComputeEngine;
|
|
268
|
+
/**
|
|
269
|
+
* Assign a value to one or more identifiers.
|
|
270
|
+
*
|
|
271
|
+
* Domain of value must be compatible with existing domain.
|
|
272
|
+
*
|
|
273
|
+
* Declare identifier if it hasn't been declared yet.
|
|
274
|
+
*
|
|
275
|
+
*/
|
|
276
|
+
assign(id: string, value: AssignValue): IComputeEngine;
|
|
277
|
+
assign(ids: {
|
|
278
|
+
[id: string]: AssignValue;
|
|
279
|
+
}): IComputeEngine;
|
|
280
|
+
/**
|
|
281
|
+
* Same as assign(), but for internal use:
|
|
282
|
+
* - skips validity checks
|
|
283
|
+
* - does not auto-declare
|
|
284
|
+
* - if assigning to a function, must pass a JS function
|
|
285
|
+
*
|
|
286
|
+
* @internal
|
|
287
|
+
*/
|
|
288
|
+
_assign(id: string, value: AssignValue): IComputeEngine;
|
|
266
289
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
267
290
|
/**
|
|
268
291
|
* Return false if the execution should stop.
|
|
@@ -288,6 +311,7 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
288
311
|
/** @internal */
|
|
289
312
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
290
313
|
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
314
|
+
domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
|
|
291
315
|
hold(expr: SemiBoxedExpression): BoxedExpression;
|
|
292
316
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
293
317
|
neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
@@ -303,7 +327,7 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
303
327
|
metadata?: Metadata;
|
|
304
328
|
canonical?: boolean;
|
|
305
329
|
}): BoxedExpression;
|
|
306
|
-
domain(domain:
|
|
330
|
+
domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
|
|
307
331
|
number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
|
|
308
332
|
canonical?: boolean;
|
|
309
333
|
metadata?: Metadata;
|
|
@@ -331,14 +355,12 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
331
355
|
* Return a list of all the assumptions that match a pattern.
|
|
332
356
|
*
|
|
333
357
|
* ```js
|
|
334
|
-
* ce.assume(x, '
|
|
358
|
+
* ce.assume(['Element', 'x', 'PositiveIntegers');
|
|
335
359
|
* ce.ask(['Greater', 'x', '_val'])
|
|
336
360
|
* // -> [{'val': 0}]
|
|
337
361
|
* ```
|
|
338
362
|
*/
|
|
339
|
-
ask(pattern:
|
|
340
|
-
|
|
341
|
-
assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | Expression | BoxedExpression): AssumeResult;
|
|
342
|
-
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
363
|
+
ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
|
|
364
|
+
assume(predicate: SemiBoxedExpression): AssumeResult;
|
|
343
365
|
forget(symbol: undefined | string | string[]): void;
|
|
344
366
|
}
|