@cortex-js/compute-engine 0.4.0 → 0.4.3
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 -2
- package/dist/compute-engine.esm.js +22846 -16608
- package/dist/compute-engine.js +23518 -17282
- package/dist/compute-engine.min.esm.js +2 -7
- package/dist/compute-engine.min.js +2 -7
- package/dist/math-json.esm.js +4337 -10529
- package/dist/math-json.js +4354 -10532
- package/dist/math-json.min.esm.js +2 -7
- package/dist/math-json.min.js +2 -7
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +90 -0
- package/dist/types/compute-engine/assume.d.ts +21 -0
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
- package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +93 -0
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
- package/dist/types/compute-engine/boxed-expression/order.d.ts +52 -0
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
- package/dist/types/compute-engine/compute-engine.d.ts +252 -0
- package/dist/types/compute-engine/cost-function.d.ts +3 -0
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
- package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
- package/dist/types/compute-engine/dictionary/collections.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/core.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +26 -0
- package/dist/types/compute-engine/dictionary/logic.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/sets.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/domain-utils.d.ts +30 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
- package/dist/types/compute-engine/latex-syntax/public.d.ts +550 -0
- package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +2 -3
- package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +43 -0
- package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
- package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
- package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
- package/dist/types/compute-engine/public.d.ts +1076 -434
- package/dist/types/compute-engine/rules.d.ts +18 -0
- package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
- package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
- package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
- package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
- package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
- package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
- package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
- package/dist/types/compute-engine.d.ts +3 -0
- package/dist/types/math-json/math-json-format.d.ts +101 -0
- package/dist/types/math-json/utils.d.ts +97 -0
- package/dist/types/math-json.d.ts +5 -3
- package/package.json +39 -36
- package/dist/types/common/utils.d.ts +0 -153
- package/dist/types/compute-engine/expression-map.d.ts +0 -11
- package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
- package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
- package/dist/types/compute-engine/numeric.d.ts +0 -21
- package/dist/types/compute-engine/patterns.d.ts +0 -22
- package/dist/types/compute-engine/predicates.d.ts +0 -42
- package/dist/types/compute-engine/utils.d.ts +0 -15
- package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
- package/dist/types/latex-syntax/definitions.d.ts +0 -40
- package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
- package/dist/types/latex-syntax/parse.d.ts +0 -138
- package/dist/types/latex-syntax/public.d.ts +0 -455
- package/dist/types/latex-syntax/serializer.d.ts +0 -26
- package/dist/types/latex-syntax/utils.d.ts +0 -10
- package/dist/types/public.d.ts +0 -163
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
import { AbstractBoxedExpression } from './abstract-boxed-expression';
|
|
3
|
+
import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SemiBoxedExpression, SimplifyOptions, Substitution, Metadata, PatternMatchOption } from '../public';
|
|
4
|
+
/**
|
|
5
|
+
* BoxedSymbol
|
|
6
|
+
*
|
|
7
|
+
* A boxed symbol is a reference to a BoxedSymbolDefinition.
|
|
8
|
+
* The BoxedSymbolDefinition "owns" all the information
|
|
9
|
+
* about the symbol, its value, domain and various attributes.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BoxedSymbol extends AbstractBoxedExpression {
|
|
12
|
+
protected _name: string;
|
|
13
|
+
private _hash;
|
|
14
|
+
private _def;
|
|
15
|
+
constructor(ce: IComputeEngine, name: string, metadata?: Metadata);
|
|
16
|
+
get hash(): number;
|
|
17
|
+
_purge(): undefined;
|
|
18
|
+
get isPure(): boolean;
|
|
19
|
+
get isCanonical(): boolean;
|
|
20
|
+
set isCanonical(_va: boolean);
|
|
21
|
+
get wikidata(): string;
|
|
22
|
+
get description(): string[];
|
|
23
|
+
get url(): string;
|
|
24
|
+
get complexity(): number;
|
|
25
|
+
get head(): string;
|
|
26
|
+
get symbol(): string;
|
|
27
|
+
get isMissing(): boolean;
|
|
28
|
+
get isLiteral(): boolean;
|
|
29
|
+
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
30
|
+
_repairDefinition(): void;
|
|
31
|
+
get value(): BoxedExpression | undefined;
|
|
32
|
+
set value(value: SemiBoxedExpression | undefined);
|
|
33
|
+
get numericValue(): BoxedExpression | undefined;
|
|
34
|
+
get domain(): BoxedExpression;
|
|
35
|
+
set domain(d: BoxedExpression);
|
|
36
|
+
get json(): Expression;
|
|
37
|
+
get sgn(): -1 | 0 | 1 | undefined | null;
|
|
38
|
+
has(x: string | string[]): boolean;
|
|
39
|
+
isSame(rhs: BoxedExpression): boolean;
|
|
40
|
+
match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
|
|
41
|
+
isEqual(rhs: BoxedExpression): boolean;
|
|
42
|
+
isLess(rhs: BoxedExpression): boolean | undefined;
|
|
43
|
+
isLessEqual(rhs: BoxedExpression): boolean | undefined;
|
|
44
|
+
isGreater(rhs: BoxedExpression): boolean | undefined;
|
|
45
|
+
isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
|
|
46
|
+
get isZero(): boolean | undefined;
|
|
47
|
+
get isNotZero(): boolean | undefined;
|
|
48
|
+
get isOne(): boolean | undefined;
|
|
49
|
+
get isNegativeOne(): boolean | undefined;
|
|
50
|
+
get isOdd(): boolean | undefined;
|
|
51
|
+
get isEven(): boolean | undefined;
|
|
52
|
+
get isPrime(): boolean | undefined;
|
|
53
|
+
get isComposite(): boolean | undefined;
|
|
54
|
+
get isInfinity(): boolean | undefined;
|
|
55
|
+
get isNaN(): boolean | undefined;
|
|
56
|
+
get isPositive(): boolean | undefined;
|
|
57
|
+
get isNonPositive(): boolean | undefined;
|
|
58
|
+
get isNegative(): boolean | undefined;
|
|
59
|
+
get isNonNegative(): boolean | undefined;
|
|
60
|
+
get isNumber(): boolean | undefined;
|
|
61
|
+
get isInteger(): boolean | undefined;
|
|
62
|
+
get isRational(): boolean | undefined;
|
|
63
|
+
get isAlgebraic(): boolean | undefined;
|
|
64
|
+
get isReal(): boolean | undefined;
|
|
65
|
+
get isExtendedReal(): boolean | undefined;
|
|
66
|
+
get isComplex(): boolean | undefined;
|
|
67
|
+
get isImaginary(): boolean | undefined;
|
|
68
|
+
get canonical(): BoxedExpression;
|
|
69
|
+
simplify(options?: SimplifyOptions): BoxedExpression;
|
|
70
|
+
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
71
|
+
N(options?: NOptions): BoxedExpression;
|
|
72
|
+
replace(rules: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
|
|
73
|
+
subs(sub: Substitution): BoxedExpression;
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
|
|
3
|
+
readonly _items: Map<BoxedExpression, U>;
|
|
4
|
+
constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
|
|
5
|
+
has(expr: BoxedExpression): boolean;
|
|
6
|
+
get(expr: BoxedExpression): U | undefined;
|
|
7
|
+
clear(): void;
|
|
8
|
+
set(expr: BoxedExpression, value: U): void;
|
|
9
|
+
delete(expr: BoxedExpression): void;
|
|
10
|
+
[Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
|
|
11
|
+
entries(): IterableIterator<[BoxedExpression, U]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export declare type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
|
|
3
|
+
/**
|
|
4
|
+
* Sort by higher total degree (sum of degree), if tied, sort by max degree,
|
|
5
|
+
* if tied,
|
|
6
|
+
*/
|
|
7
|
+
export declare function sortAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression[];
|
|
8
|
+
/**
|
|
9
|
+
* Given two expressions `a` and `b`, return:
|
|
10
|
+
* - `-1` if `a` should be ordered before `b`
|
|
11
|
+
* - `+1` if `b` should be ordered before `a`
|
|
12
|
+
* - `0` if they have the same order (they are structurally equal)
|
|
13
|
+
*
|
|
14
|
+
* The default order is as follow:
|
|
15
|
+
*
|
|
16
|
+
* 1/ Literal numeric values (rational, machine numbers and Decimal numbers),
|
|
17
|
+
* ordered by they numeric value (smaller numbers before larger numbers)
|
|
18
|
+
*
|
|
19
|
+
* 2/ Literal complex numbers, ordered by their real parts. In case of a tie,
|
|
20
|
+
* ordered by the absolute value of their imaginary parts. In case of a tie,
|
|
21
|
+
* ordered by the value of their imaginary parts.
|
|
22
|
+
*
|
|
23
|
+
* 3/ Symbols, ordered by their name as strings
|
|
24
|
+
*
|
|
25
|
+
* 4/ Addition, ordered as a polynom, with higher degree terms first
|
|
26
|
+
*
|
|
27
|
+
* 5/ Other functions, ordered by their `complexity` property. In case
|
|
28
|
+
* of a tie, ordered by the head of the expression as a string. In case of a
|
|
29
|
+
* tie, by the leaf count of each expression. In case of a tie, by the order
|
|
30
|
+
* of each argument, left to right.
|
|
31
|
+
*
|
|
32
|
+
* 6/ Strings, ordered by comparing their Unicode code point values. While this
|
|
33
|
+
* sort order is quick to calculate, it can produce unexpected results, for
|
|
34
|
+
* example "E" < "e" < "È" and "11" < "2". This ordering is not suitable to
|
|
35
|
+
* collate natural language strings.
|
|
36
|
+
*
|
|
37
|
+
* 7/ Dictionaries, ordered by the number of keys. If there is a tie, by the
|
|
38
|
+
* sum of the complexities of the values of the dictionary
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export declare function order(a: BoxedExpression, b: BoxedExpression): number;
|
|
43
|
+
/**
|
|
44
|
+
* Sort the terms of a polynomial expression (`Add` expression) according
|
|
45
|
+
* to the deglex polynomial ordering
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export declare function polynomialOrder(expr: BoxedExpression): SemiBoxedExpression;
|
|
49
|
+
export declare function lexicographicOrder(expr: BoxedExpression, vars?: string[]): SemiBoxedExpression;
|
|
50
|
+
export declare function degreeLexicographicOrder(expr: BoxedExpression, vars?: string[]): SemiBoxedExpression;
|
|
51
|
+
export declare function degreeReverseLexicographicOrder(expr: BoxedExpression, vars?: string[]): SemiBoxedExpression;
|
|
52
|
+
export declare function eliminationOrder(expr: BoxedExpression, vars?: string[]): SemiBoxedExpression;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
3
|
+
import { Expression } from '../../math-json/math-json-format';
|
|
4
|
+
import { BoxedExpression, IComputeEngine, Metadata } from '../public';
|
|
5
|
+
/**
|
|
6
|
+
* The canonical version of `serializeJsonFunction()` applies
|
|
7
|
+
* additional transformations to "reverse" some of the effects
|
|
8
|
+
* of canonicalization (or boxing), for example it uses `Divide`
|
|
9
|
+
* instead of `Multiply`/`Power` when applicable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function serializeJsonCanonicalFunction(ce: IComputeEngine, head: string | BoxedExpression, args: BoxedExpression[], metadata?: Metadata): Expression;
|
|
12
|
+
export declare function serializeJsonFunction(ce: IComputeEngine, head: string | BoxedExpression, args: BoxedExpression[], metadata?: Metadata): Expression;
|
|
13
|
+
export declare function serializeJsonString(ce: IComputeEngine, s: string): Expression;
|
|
14
|
+
export declare function serializeJsonSymbol(ce: IComputeEngine, sym: string, metadata?: Metadata): Expression;
|
|
15
|
+
export declare function serializeJsonNumber(ce: IComputeEngine, value: number | Decimal | Complex | [number, number], metadata?: Metadata): Expression;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export declare function isLatexString(s: any): s is string;
|
|
3
|
+
export declare function latexString(s: any): string | null;
|
|
4
|
+
/**
|
|
5
|
+
* Return a multiple of the imaginary unit, e.g.
|
|
6
|
+
* - 'ImaginaryUnit'
|
|
7
|
+
* - ['Negate', 'ImaginaryUnit']
|
|
8
|
+
* - ['Negate', ['Multiply', 3, 'ImaginaryUnit']]
|
|
9
|
+
* - ['Multiply', 5, 'ImaginaryUnit']
|
|
10
|
+
* - ['Multiply', 'ImaginaryUnit', 5]
|
|
11
|
+
*/
|
|
12
|
+
export declare function getImaginaryCoef(expr: BoxedExpression): number;
|
|
13
|
+
/**
|
|
14
|
+
* Return the free symbols in the expression, recursively.
|
|
15
|
+
* A variable, or free symbol,is a symbol that is not bound to a value.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getVars(expr: BoxedExpression): string[];
|
|
18
|
+
/**
|
|
19
|
+
* For any numeric result, or when boxing numbers,
|
|
20
|
+
* if `ce.useDecimal` is true, create them as Decimal number
|
|
21
|
+
* if `ce.useDecimal` is false, create them as machine number
|
|
22
|
+
*/
|
|
23
|
+
export declare function useDecimal(ce: IComputeEngine): boolean;
|
|
24
|
+
/** If result of a numeric evaluation is a complex number,
|
|
25
|
+
* return `NaN` if `ce.useComplex` is false
|
|
26
|
+
*/
|
|
27
|
+
export declare function complexAllowed(ce: IComputeEngine): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Assert that `expr` is in fact canonical.
|
|
30
|
+
*
|
|
31
|
+
* Called for example from within a `canonical` handler.
|
|
32
|
+
*
|
|
33
|
+
* To make an expression whose canonical status is unknown, canonical, call
|
|
34
|
+
* `expr.canonical`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function asCanonical(expr: BoxedExpression): BoxedExpression;
|
|
37
|
+
export declare function hashCode(s: string): number;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
import { DictionaryCategory, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
3
|
+
import { Decimal } from 'decimal.js';
|
|
4
|
+
import { Complex } from 'complex.js';
|
|
5
|
+
import { SignalMessage, WarningSignal } from '../common/signals';
|
|
6
|
+
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, Dictionary, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata } from './public';
|
|
7
|
+
/**
|
|
8
|
+
* Create a `CustomEngine` instance to customize its behavior and the syntax
|
|
9
|
+
* and operation dictionaries it uses.
|
|
10
|
+
*
|
|
11
|
+
* The constructor of `ComputeEngine` will compile and optimize the dictionary
|
|
12
|
+
* upfront.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ComputeEngine implements IComputeEngine {
|
|
15
|
+
readonly ZERO: BoxedExpression;
|
|
16
|
+
readonly ONE: BoxedExpression;
|
|
17
|
+
readonly TWO: BoxedExpression;
|
|
18
|
+
readonly HALF: BoxedExpression;
|
|
19
|
+
readonly NEGATIVE_ONE: BoxedExpression;
|
|
20
|
+
readonly I: BoxedExpression;
|
|
21
|
+
readonly NAN: BoxedExpression;
|
|
22
|
+
readonly POSITIVE_INFINITY: BoxedExpression;
|
|
23
|
+
readonly NEGATIVE_INFINITY: BoxedExpression;
|
|
24
|
+
readonly COMPLEX_INFINITY: BoxedExpression;
|
|
25
|
+
DECIMAL_NAN: Decimal;
|
|
26
|
+
DECIMAL_ZERO: Decimal;
|
|
27
|
+
DECIMAL_ONE: Decimal;
|
|
28
|
+
DECIMAL_TWO: Decimal;
|
|
29
|
+
DECIMAL_HALF: Decimal;
|
|
30
|
+
DECIMAL_PI: Decimal;
|
|
31
|
+
DECIMAL_NEGATIVE_ONE: Decimal;
|
|
32
|
+
private _precision;
|
|
33
|
+
private _numericMode;
|
|
34
|
+
private _latexSyntax?;
|
|
35
|
+
private _tolerance;
|
|
36
|
+
private _decimalTolerance;
|
|
37
|
+
private _cache;
|
|
38
|
+
private _stats;
|
|
39
|
+
private _cost?;
|
|
40
|
+
private _jsonSerializationOptions;
|
|
41
|
+
/** The domain of unknown symbols. If `null` unknown symbols do not have a
|
|
42
|
+
* definition automatically associated with them.
|
|
43
|
+
*/
|
|
44
|
+
private _defaultDomain;
|
|
45
|
+
private _commonSymbols;
|
|
46
|
+
private _commonNumbers;
|
|
47
|
+
private _commonDomains;
|
|
48
|
+
/**
|
|
49
|
+
* The current scope.
|
|
50
|
+
*
|
|
51
|
+
* A scope is a dictionary that contains the definition of local symbols.
|
|
52
|
+
*
|
|
53
|
+
* Scopes form a stack, and definitions in more recent
|
|
54
|
+
* scopes can obscure definitions from older scopes.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
context: RuntimeScope;
|
|
58
|
+
/** Absolute time beyond which evaluation should not proceed */
|
|
59
|
+
deadline?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Return dictionaries suitable for the specified categories, or `"all"`
|
|
62
|
+
* for all categories (`"arithmetic"`, `"algebra"`, etc...).
|
|
63
|
+
*
|
|
64
|
+
* A symbol dictionary defines how the symbols and function names in a MathJSON
|
|
65
|
+
* expression should be interpreted, i.e. how to evaluate and manipulate them.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
|
|
69
|
+
/**
|
|
70
|
+
* Construct a new `ComputeEngine` environment.
|
|
71
|
+
*
|
|
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
|
+
* The order of the dictionaries matter: the definitions from the later ones
|
|
76
|
+
* override the definitions from earlier ones. The first dictionary should
|
|
77
|
+
* be the `'core'` dictionary which include some basic definitions such
|
|
78
|
+
* as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
|
|
79
|
+
*/
|
|
80
|
+
constructor(options?: {
|
|
81
|
+
dictionaries?: Readonly<Dictionary>[];
|
|
82
|
+
numericMode?: NumericMode;
|
|
83
|
+
assumptions?: (LatexString | Expression)[];
|
|
84
|
+
numericPrecision?: number;
|
|
85
|
+
tolerance?: number;
|
|
86
|
+
defaultDomain?: string;
|
|
87
|
+
});
|
|
88
|
+
/** After the configuration of the engine has changed, clear the caches
|
|
89
|
+
* so that new values can be recalculated.
|
|
90
|
+
*
|
|
91
|
+
* This needs to happen for example when the numeric precision changes.
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
purge(): void;
|
|
95
|
+
_register(expr: BoxedExpression): void;
|
|
96
|
+
_unregister(expr: BoxedExpression): void;
|
|
97
|
+
get stats(): ComputeEngineStats;
|
|
98
|
+
_decimal: Decimal.Constructor;
|
|
99
|
+
decimal: (a: Decimal.Value) => Decimal;
|
|
100
|
+
complex: (a: number | Complex, b?: number) => Complex;
|
|
101
|
+
/** The precision, or number of significant digits, for numerical calculations
|
|
102
|
+
* such as when calling `ce.N()`.
|
|
103
|
+
*
|
|
104
|
+
* To make calculations using more digits, at the cost of expended memory
|
|
105
|
+
* usage and slower computations, set the `precision` higher.
|
|
106
|
+
*
|
|
107
|
+
* Trigonometric operations are accurate for precision up to 1,000.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
get precision(): number;
|
|
111
|
+
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
|
+
get numericMode(): NumericMode;
|
|
126
|
+
set numericMode(f: NumericMode);
|
|
127
|
+
get timeLimit(): number;
|
|
128
|
+
get iterationLimit(): number;
|
|
129
|
+
get recursionLimit(): number;
|
|
130
|
+
get defaultDomain(): BoxedExpression | null;
|
|
131
|
+
set defaultDomain(domain: BoxedExpression | string | null);
|
|
132
|
+
/**
|
|
133
|
+
* Values smaller than the tolerance are considered to be zero for the
|
|
134
|
+
* purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
|
|
135
|
+
* equal to `a`.
|
|
136
|
+
*/
|
|
137
|
+
get tolerance(): number;
|
|
138
|
+
set tolerance(val: number);
|
|
139
|
+
chop(n: number): number;
|
|
140
|
+
chop(n: Decimal): Decimal | 0;
|
|
141
|
+
chop(n: Complex): Complex | 0;
|
|
142
|
+
private get latexSyntax();
|
|
143
|
+
set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
|
|
144
|
+
get costFunction(): (expr: BoxedExpression) => number;
|
|
145
|
+
/**
|
|
146
|
+
* Return a matching symbol definition, starting with the current
|
|
147
|
+
* scope and going up the scope chain.
|
|
148
|
+
*/
|
|
149
|
+
getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
|
|
150
|
+
/**
|
|
151
|
+
* Return the definition for a function matching this head.
|
|
152
|
+
*
|
|
153
|
+
* Start looking in the current scope, than up the scope chain.
|
|
154
|
+
*/
|
|
155
|
+
getFunctionDefinition(head: string): undefined | BoxedFunctionDefinition;
|
|
156
|
+
/**
|
|
157
|
+
* Add (or replace) a definition for a symbol in the current scope.
|
|
158
|
+
*/
|
|
159
|
+
defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* Create a new scope and add it to the top of the scope stack
|
|
163
|
+
*
|
|
164
|
+
* The `options.scope` property can be used to specify custom precision,
|
|
165
|
+
* etc... for this scope
|
|
166
|
+
*
|
|
167
|
+
*/
|
|
168
|
+
pushScope(options?: {
|
|
169
|
+
dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
|
|
170
|
+
assumptions?: (LatexString | Expression)[];
|
|
171
|
+
scope?: Partial<Scope>;
|
|
172
|
+
}): void;
|
|
173
|
+
/** Remove the topmost scope from the scope stack.
|
|
174
|
+
*/
|
|
175
|
+
popScope(): void;
|
|
176
|
+
get assumptions(): ExpressionMapInterface<boolean>;
|
|
177
|
+
/**
|
|
178
|
+
* Return false if the execution should stop.
|
|
179
|
+
*
|
|
180
|
+
* This can occur if:
|
|
181
|
+
* - an error has been signaled
|
|
182
|
+
* - the time limit or memory limit has been exceeded
|
|
183
|
+
*/
|
|
184
|
+
shouldContinueExecution(): boolean;
|
|
185
|
+
checkContinueExecution(): void;
|
|
186
|
+
assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
187
|
+
/**
|
|
188
|
+
* Call this function if an unexpected condition occurs during execution of a
|
|
189
|
+
* function in the engine.
|
|
190
|
+
*
|
|
191
|
+
* An `ErrorSignal` is a problem that cannot be recovered from.
|
|
192
|
+
*
|
|
193
|
+
* A `WarningSignal` indicates a minor problem that does not prevent the
|
|
194
|
+
* execution to continue.
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
198
|
+
signal(sig: WarningSignal): void;
|
|
199
|
+
cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
|
|
200
|
+
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
|
|
201
|
+
fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
202
|
+
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
203
|
+
error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
|
|
204
|
+
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
205
|
+
mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
206
|
+
power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
207
|
+
inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
208
|
+
negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
209
|
+
divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
210
|
+
pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
211
|
+
tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
212
|
+
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
213
|
+
symbol(sym: string, metadata?: Metadata): BoxedExpression;
|
|
214
|
+
domain(domain: BoxedExpression | string, metadata?: Metadata): BoxedExpression;
|
|
215
|
+
number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
|
|
216
|
+
rules(rules: Rule[]): BoxedRuleSet;
|
|
217
|
+
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
218
|
+
parse(s: null): null;
|
|
219
|
+
parse(s: LatexString | string): BoxedExpression;
|
|
220
|
+
parse(s: LatexString | string | null): null | BoxedExpression;
|
|
221
|
+
serialize(x: Expression | BoxedExpression): string;
|
|
222
|
+
get latexOptions(): Required<NumberFormattingOptions> & Required<ParseLatexOptions> & Required<SerializeLatexOptions>;
|
|
223
|
+
set latexOptions(opts: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions);
|
|
224
|
+
get jsonSerializationOptions(): JsonSerializationOptions;
|
|
225
|
+
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
226
|
+
/**
|
|
227
|
+
* Return a list of all the assumptions that match a pattern.
|
|
228
|
+
*
|
|
229
|
+
* ```js
|
|
230
|
+
* ce.assume(x, 'PositiveInteger');
|
|
231
|
+
* ce.ask(['Greater', 'x', '_val'])
|
|
232
|
+
* // -> [{'val': 0}]
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
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
|
+
assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
|
|
250
|
+
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
251
|
+
forget(symbol: undefined | string | string[]): void;
|
|
252
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
/** The canonical form of `Add`:
|
|
3
|
+
* - removes `0`
|
|
4
|
+
* - adds up small integers and rational numbers
|
|
5
|
+
* - capture complex numbers (a + ib or ai +b)
|
|
6
|
+
* - groups repeated terms (a + a -> 2a)
|
|
7
|
+
* */
|
|
8
|
+
export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
9
|
+
export declare function domainAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression | string;
|
|
10
|
+
export declare function numEvalAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
|
|
11
|
+
export declare function processAdd(ce: IComputeEngine, args: BoxedExpression[], _mode: 'simplify' | 'evaluate'): BoxedExpression | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
/**
|
|
3
|
+
* Canonical form of 'Divide' (and 'Rational')
|
|
4
|
+
* - remove denominator of 1
|
|
5
|
+
* - simplify the signs
|
|
6
|
+
* - factor out negate (make the numerator and denominator positive)
|
|
7
|
+
* - if Divide, transform into Multiply/Power
|
|
8
|
+
*/
|
|
9
|
+
export declare function canonicalDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
/** The canonical form of `Multiply`:
|
|
3
|
+
* - remove `1`
|
|
4
|
+
* - combine literal small integers and rationals
|
|
5
|
+
* - any arg is literal 0 -> return 0
|
|
6
|
+
* - simplify signs
|
|
7
|
+
* - combine terms with same base
|
|
8
|
+
* `a a^3` -> `a^4`
|
|
9
|
+
* - simplify the signs:
|
|
10
|
+
* - i.e. `-2 \times -3` -> `2 \times 3`
|
|
11
|
+
* - `2 \times -x` -> `-2 \times x`
|
|
12
|
+
*
|
|
13
|
+
* The ops must be canonical, the result is canonical.
|
|
14
|
+
*/
|
|
15
|
+
export declare function canonicalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
16
|
+
export declare function processMultiply(ce: IComputeEngine, ops: BoxedExpression[], _mode: 'simplify' | 'evaluate'): BoxedExpression | undefined;
|
|
17
|
+
export declare function numEvalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Return `null` if there is no canonicalization necessary and the result is
|
|
5
|
+
* simply `ce._fn('Power', [base, exponent])`
|
|
6
|
+
*/
|
|
7
|
+
export declare function canonicalPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, metadata?: Metadata): BoxedExpression | null;
|
|
8
|
+
export declare function square(ce: IComputeEngine, base: BoxedExpression): BoxedExpression;
|
|
9
|
+
export declare function processPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
/* 0.4.
|
|
2
|
-
|
|
3
|
-
export declare const ARITHMETIC_DICTIONARY: Dictionary<Numeric>;
|
|
4
|
-
/** Apply some simplifications for `Negate`.
|
|
5
|
-
* Used by `canonical-negate` and `simplify`
|
|
6
|
-
*/
|
|
7
|
-
export declare function applyNegate(expr: Expression): Expression;
|
|
8
|
-
export declare function ungroup(expr: Expression | null): Expression;
|
|
9
|
-
export declare function applyPower(engine: ComputeEngine, expr: Expression): Expression;
|
|
10
|
-
/** Used by `simplify` and `canonical` to simplify some arithmetic
|
|
11
|
-
* and trigonometric constants */
|
|
12
|
-
export declare function applyConstants(expr: Expression): Expression;
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export declare const ARITHMETIC_DICTIONARY: Dictionary[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
import { IComputeEngine, Dictionary } from '../public';
|
|
3
|
+
export declare function getDefaultDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
|
|
4
|
+
export declare const DICTIONARIES: {
|
|
5
|
+
[category in DictionaryCategory]?: Readonly<Dictionary> | Readonly<Dictionary>[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Set the dictionary of the current context (`engine.context`) to `dicts`
|
|
9
|
+
*
|
|
10
|
+
* `dicts` can be an array of dictionaries, in order to deal with circular
|
|
11
|
+
* dependencies: it is possible to partition a dictionary into multiple
|
|
12
|
+
* sub-dictionary, to control the order in which they are processe and
|
|
13
|
+
* avoid having expressions in the definition of an entry reference a symbol
|
|
14
|
+
* or function name that has not yet been added to the dictionary.
|
|
15
|
+
*
|
|
16
|
+
* Specifically:
|
|
17
|
+
* - Expressions (for values, evaluate, domain, isElementOf, etc..) are boxed
|
|
18
|
+
* - The domain of entries is inferred and validated:
|
|
19
|
+
* - check that domains are in canonical form
|
|
20
|
+
* - check that domains are consistent with declarations
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function setCurrentContextDictionary(engine: IComputeEngine, dicts: Dictionary | Dictionary[] | undefined): void;
|
|
24
|
+
/**
|
|
25
|
+
* For debugging: a textual representation of the inheritance chain of sets.
|
|
26
|
+
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
import { Decimal } from 'decimal.js';
|
|
3
|
+
import { BoxedExpression } from './public';
|
|
4
|
+
/** Quickly determine the numeric domain of a number or constant
|
|
5
|
+
* For the symbols, this is a hard-coded optimization that doesn't rely on the
|
|
6
|
+
* dictionaries. The regular path is in `internalDomain()`
|
|
7
|
+
*/
|
|
8
|
+
export declare function inferNumericDomain(value: number | Decimal | Complex | [numer: number, denom: number]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Simple description of a numeric domain as a base domain, a min and
|
|
11
|
+
* max value, possibly open ends, and some excluded values.
|
|
12
|
+
*/
|
|
13
|
+
export declare type NumericDomainInfo = {
|
|
14
|
+
domain?: string;
|
|
15
|
+
min?: number;
|
|
16
|
+
max?: number;
|
|
17
|
+
open?: 'left' | 'right' | 'both';
|
|
18
|
+
/** Values from _excludedValues_ are considered not in this domain */
|
|
19
|
+
excludedValues?: number[];
|
|
20
|
+
/** If defined, the values in this domain must follow the relation
|
|
21
|
+
* _period_ * _n_ + _phase_ when _n_ is in _domain_.
|
|
22
|
+
*/
|
|
23
|
+
multiple?: [period: number, domain: BoxedExpression, phase: number];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Return an efficient data structure describing a numeric domain,
|
|
27
|
+
* an `Interval` or `Range`
|
|
28
|
+
* @todo could also check for `Multiple`
|
|
29
|
+
*/
|
|
30
|
+
export declare function inferNumericDomainInfo(expr: BoxedExpression): NumericDomainInfo | null;
|