@cortex-js/compute-engine 0.32.0 → 0.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compute-engine.esm.js +42905 -0
- package/dist/compute-engine.min.esm.js +125 -0
- package/dist/compute-engine.min.umd.js +127 -0
- package/dist/compute-engine.umd.js +42930 -0
- package/dist/math-json.esm.js +130 -0
- package/dist/math-json.min.esm.js +130 -0
- package/dist/math-json.min.umd.js +4 -0
- package/dist/math-json.umd.js +155 -0
- package/dist/types/common/ansi-codes.d.ts +41 -0
- package/dist/types/common/configuration-change.d.ts +28 -0
- package/dist/types/common/fuzzy-string-match.d.ts +2 -0
- package/dist/types/common/grapheme-splitter.d.ts +15 -0
- package/dist/types/common/interruptible.d.ts +20 -0
- package/dist/types/common/one-of.d.ts +10 -0
- package/dist/types/common/signals.d.ts +96 -0
- package/dist/types/common/type/ast-nodes.d.ts +146 -0
- package/dist/types/common/type/boxed-type.d.ts +30 -0
- package/dist/types/common/type/lexer.d.ts +51 -0
- package/dist/types/common/type/parse.d.ts +211 -0
- package/dist/types/common/type/parser.d.ts +45 -0
- package/dist/types/common/type/primitive.d.ts +10 -0
- package/dist/types/common/type/serialize.d.ts +2 -0
- package/dist/types/common/type/subtype.d.ts +6 -0
- package/dist/types/common/type/type-builder.d.ts +32 -0
- package/dist/types/common/type/types.d.ts +300 -0
- package/dist/types/common/type/utils.d.ts +36 -0
- package/dist/types/common/utils.d.ts +23 -0
- package/dist/types/compute-engine/assume.d.ts +26 -0
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +165 -0
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +16 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +38 -0
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
- package/dist/types/compute-engine/boxed-expression/box.d.ts +47 -0
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +44 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +136 -0
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +103 -0
- package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +53 -0
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +107 -0
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +27 -0
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +170 -0
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +83 -0
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +7 -0
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/match.d.ts +41 -0
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +11 -0
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +34 -0
- package/dist/types/compute-engine/boxed-expression/order.d.ts +71 -0
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +105 -0
- package/dist/types/compute-engine/boxed-expression/product.d.ts +66 -0
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -0
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +46 -0
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +9 -0
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +64 -0
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +58 -0
- package/dist/types/compute-engine/collection-utils.d.ts +35 -0
- package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
- package/dist/types/compute-engine/compilation/types.d.ts +83 -0
- package/dist/types/compute-engine/cost-function.d.ts +13 -0
- package/dist/types/compute-engine/function-utils.d.ts +120 -0
- package/dist/types/compute-engine/global-types.d.ts +2930 -0
- package/dist/types/compute-engine/index.d.ts +660 -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-complex.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.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-relational-operators.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-statistics.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -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 +88 -0
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
- package/dist/types/compute-engine/latex-syntax/types.d.ts +896 -0
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
- package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
- package/dist/types/compute-engine/library/calculus.d.ts +2 -0
- package/dist/types/compute-engine/library/collections.d.ts +27 -0
- package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
- package/dist/types/compute-engine/library/complex.d.ts +2 -0
- package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -0
- package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
- package/dist/types/compute-engine/library/library.d.ts +17 -0
- package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
- package/dist/types/compute-engine/library/logic-analysis.d.ts +64 -0
- package/dist/types/compute-engine/library/logic-utils.d.ts +58 -0
- package/dist/types/compute-engine/library/logic.d.ts +7 -0
- package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
- package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
- package/dist/types/compute-engine/library/sets.d.ts +2 -0
- package/dist/types/compute-engine/library/statistics.d.ts +2 -0
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/library/utils.d.ts +77 -0
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
- package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
- package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
- package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
- package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
- package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
- package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
- package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
- package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
- package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
- package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
- package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
- package/dist/types/compute-engine/numerics/types.d.ts +30 -0
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
- package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
- package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
- package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +27 -0
- package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
- package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
- package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
- package/dist/types/compute-engine/types.d.ts +8 -0
- package/dist/types/compute-engine.d.ts +3 -0
- package/dist/types/math-json/symbols.d.ts +11 -0
- package/dist/types/math-json/types.d.ts +122 -0
- package/dist/types/math-json/utils.d.ts +87 -0
- package/dist/types/math-json.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import { MathJsonSymbol } from '../../math-json/types';
|
|
3
|
+
import { NumericValue } from '../numeric-value/types';
|
|
4
|
+
/**
|
|
5
|
+
* Given a name and a set of arguments, return a boxed function expression.
|
|
6
|
+
*
|
|
7
|
+
* If available, preserve LaTeX and wikidata metadata in the boxed expression.
|
|
8
|
+
*
|
|
9
|
+
* Note that `boxFunction()` should only be called from `ce.function()`
|
|
10
|
+
*/
|
|
11
|
+
export declare function boxFunction(ce: ComputeEngine, name: MathJsonSymbol, ops: readonly SemiBoxedExpression[], options?: {
|
|
12
|
+
metadata?: Metadata;
|
|
13
|
+
canonical?: CanonicalOptions;
|
|
14
|
+
structural?: boolean;
|
|
15
|
+
scope?: Scope;
|
|
16
|
+
}): BoxedExpression;
|
|
17
|
+
/**
|
|
18
|
+
* Notes about the boxed form:
|
|
19
|
+
*
|
|
20
|
+
* [1] Expression with an operator of `Number`, `String`, `Symbol` and `Dictionary`
|
|
21
|
+
* are converted to the corresponding atomic expression.
|
|
22
|
+
*
|
|
23
|
+
* [2] Expressions with an operator of `Complex` are converted to a (complex) number
|
|
24
|
+
* or a `Add`/`Multiply` expression.
|
|
25
|
+
*
|
|
26
|
+
* The precedence of `Complex` (for serialization) is sometimes the
|
|
27
|
+
* precedence of `Add` (when re and im != 0), sometimes the precedence of
|
|
28
|
+
* `Multiply` (when im or re === 0). Using a number or an explicit
|
|
29
|
+
* `Add`/`Multiply` expression avoids this ambiguity.
|
|
30
|
+
*
|
|
31
|
+
* [3] An expression with a `Rational` operator is converted to a rational
|
|
32
|
+
* number if possible, to a `Divide` otherwise.
|
|
33
|
+
*
|
|
34
|
+
* [4] A `Negate` function applied to a number literal is converted to a number.
|
|
35
|
+
*
|
|
36
|
+
* Note that `Negate` is only distributed over addition. In practice, having
|
|
37
|
+
* `Negate` factored on multiply/divide is more useful to detect patterns.
|
|
38
|
+
*
|
|
39
|
+
* Note that this function should only be called from `ce.box()`
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export declare function box(ce: ComputeEngine, expr: null | undefined | NumericValue | SemiBoxedExpression, options?: {
|
|
43
|
+
canonical?: CanonicalOptions;
|
|
44
|
+
structural?: boolean;
|
|
45
|
+
scope?: Scope;
|
|
46
|
+
}): BoxedExpression;
|
|
47
|
+
export declare function semiCanonical(ce: ComputeEngine, xs: ReadonlyArray<SemiBoxedExpression>, scope?: Scope): ReadonlyArray<BoxedExpression>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
3
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
4
|
+
import { DictionaryValue, Expression } from '../../math-json/types';
|
|
5
|
+
/**
|
|
6
|
+
* BoxedDictionary
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare class BoxedDictionary extends _BoxedExpression implements DictionaryInterface {
|
|
10
|
+
[Symbol.toStringTag]: string;
|
|
11
|
+
private readonly _keyValues;
|
|
12
|
+
private _type;
|
|
13
|
+
/** The input to the constructor is either a ["Dictionary", ["KeyValuePair", ..., ...], ...] expression or a record of key-value pairs */
|
|
14
|
+
constructor(ce: ComputeEngine, keyValues: Record<string, DictionaryValue> | BoxedExpression, options?: {
|
|
15
|
+
metadata?: Metadata;
|
|
16
|
+
canonical?: boolean;
|
|
17
|
+
});
|
|
18
|
+
private _initFromRecord;
|
|
19
|
+
private _initFromExpression;
|
|
20
|
+
get json(): Expression;
|
|
21
|
+
toMathJson(options: Readonly<JsonSerializationOptions>): Expression;
|
|
22
|
+
get hash(): number;
|
|
23
|
+
get operator(): string;
|
|
24
|
+
get type(): BoxedType;
|
|
25
|
+
get isPure(): boolean;
|
|
26
|
+
get isCanonical(): boolean;
|
|
27
|
+
set isCanonical(_va: boolean);
|
|
28
|
+
get value(): BoxedExpression | undefined;
|
|
29
|
+
get complexity(): number;
|
|
30
|
+
get isCollection(): boolean;
|
|
31
|
+
get isIndexedCollection(): boolean;
|
|
32
|
+
get isLazyCollection(): boolean;
|
|
33
|
+
contains(_rhs: BoxedExpression): boolean | undefined;
|
|
34
|
+
get count(): number | undefined;
|
|
35
|
+
get isEmptyCollection(): boolean;
|
|
36
|
+
get isFiniteCollection(): boolean;
|
|
37
|
+
each(): Generator<BoxedExpression>;
|
|
38
|
+
get(key: string): BoxedExpression | undefined;
|
|
39
|
+
has(key: string): boolean;
|
|
40
|
+
get keys(): string[];
|
|
41
|
+
get entries(): [string, BoxedExpression][];
|
|
42
|
+
get values(): BoxedExpression[];
|
|
43
|
+
match(pattern: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
44
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import type { SimplifyOptions, ReplaceOptions, PatternMatchOptions, BoxedExpression, BoxedBaseDefinition, BoxedOperatorDefinition, BoxedRuleSet, BoxedSubstitution, CanonicalOptions, EvaluateOptions, ComputeEngine, Metadata, Rule, Sign, Substitution, Scope, BoxedValueDefinition } from '../global-types';
|
|
3
|
+
import { Type } from '../../common/type/types';
|
|
4
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
5
|
+
import { NumericValue } from '../numeric-value/types';
|
|
6
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
7
|
+
/**
|
|
8
|
+
* A boxed function expression represent an expression composed of an operator
|
|
9
|
+
* (the name of the function) and a list of arguments. For example:
|
|
10
|
+
* `["Add", 1, 2]` is a function expression with the operator "Add" and two
|
|
11
|
+
* arguments 1 and 2.
|
|
12
|
+
*
|
|
13
|
+
* If canonical, it has a definition associated with it, based on the operator.
|
|
14
|
+
*
|
|
15
|
+
* The definition contains its signature and its evaluation handler.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare class BoxedFunction extends _BoxedExpression {
|
|
19
|
+
private readonly _operator;
|
|
20
|
+
private readonly _ops;
|
|
21
|
+
private _def;
|
|
22
|
+
/** @todo: wrong. If the function is scoped (has its own lexical scope), the captured eval context. This includes the lexical scope for this expression
|
|
23
|
+
*/
|
|
24
|
+
private _capturedContext;
|
|
25
|
+
/** If the operator is scoped, the local scope associated with
|
|
26
|
+
* the function expression
|
|
27
|
+
*/
|
|
28
|
+
private _localScope;
|
|
29
|
+
private _isPure;
|
|
30
|
+
private _isStructural;
|
|
31
|
+
private _hash;
|
|
32
|
+
private _value;
|
|
33
|
+
private _valueN;
|
|
34
|
+
private _sgn;
|
|
35
|
+
private _type;
|
|
36
|
+
constructor(ce: ComputeEngine, operator: string, ops: ReadonlyArray<BoxedExpression>, options?: {
|
|
37
|
+
metadata?: Metadata;
|
|
38
|
+
canonical?: boolean;
|
|
39
|
+
structural?: boolean;
|
|
40
|
+
scope?: Scope;
|
|
41
|
+
});
|
|
42
|
+
get hash(): number;
|
|
43
|
+
/**
|
|
44
|
+
* For function expressions, `infer()` infers the result type of the function
|
|
45
|
+
* based on the provided type and inference mode.
|
|
46
|
+
*/
|
|
47
|
+
infer(t: Type, inferenceMode?: 'narrow' | 'widen'): boolean;
|
|
48
|
+
bind(): void;
|
|
49
|
+
reset(): void;
|
|
50
|
+
get value(): BoxedExpression | undefined;
|
|
51
|
+
get isCanonical(): boolean;
|
|
52
|
+
get isPure(): boolean;
|
|
53
|
+
get isConstant(): boolean;
|
|
54
|
+
get constantValue(): number | boolean | string | object | undefined;
|
|
55
|
+
get json(): Expression;
|
|
56
|
+
get operator(): string;
|
|
57
|
+
get ops(): ReadonlyArray<BoxedExpression>;
|
|
58
|
+
get nops(): number;
|
|
59
|
+
get op1(): BoxedExpression;
|
|
60
|
+
get op2(): BoxedExpression;
|
|
61
|
+
get op3(): BoxedExpression;
|
|
62
|
+
get isScoped(): boolean;
|
|
63
|
+
get localScope(): Scope | undefined;
|
|
64
|
+
get isValid(): boolean;
|
|
65
|
+
/** Note: if the expression is not canonical, this will return a canonical
|
|
66
|
+
* version of the expression in the current lexical scope.
|
|
67
|
+
*/
|
|
68
|
+
get canonical(): BoxedExpression;
|
|
69
|
+
get structural(): BoxedExpression;
|
|
70
|
+
get isStructural(): boolean;
|
|
71
|
+
toNumericValue(): [NumericValue, BoxedExpression];
|
|
72
|
+
/**
|
|
73
|
+
* Note: the result is bound to the current scope, not the scope of the
|
|
74
|
+
* original expression.
|
|
75
|
+
* <!-- This may or may not be desirable -->
|
|
76
|
+
*/
|
|
77
|
+
subs(sub: Substitution, options?: {
|
|
78
|
+
canonical?: CanonicalOptions;
|
|
79
|
+
}): BoxedExpression;
|
|
80
|
+
replace(rules: BoxedRuleSet | Rule | Rule[], options?: Partial<ReplaceOptions>): BoxedExpression | null;
|
|
81
|
+
match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
82
|
+
has(v: string | string[]): boolean;
|
|
83
|
+
get sgn(): Sign | undefined;
|
|
84
|
+
get isNaN(): boolean | undefined;
|
|
85
|
+
get isInfinity(): boolean | undefined;
|
|
86
|
+
get isFinite(): boolean | undefined;
|
|
87
|
+
get isOne(): boolean | undefined;
|
|
88
|
+
get isNegativeOne(): boolean | undefined;
|
|
89
|
+
get isPositive(): boolean | undefined;
|
|
90
|
+
get isNonNegative(): boolean | undefined;
|
|
91
|
+
get isNegative(): boolean | undefined;
|
|
92
|
+
get isNonPositive(): boolean | undefined;
|
|
93
|
+
get numerator(): BoxedExpression;
|
|
94
|
+
get denominator(): BoxedExpression;
|
|
95
|
+
get numeratorDenominator(): [BoxedExpression, BoxedExpression];
|
|
96
|
+
neg(): BoxedExpression;
|
|
97
|
+
inv(): BoxedExpression;
|
|
98
|
+
abs(): BoxedExpression;
|
|
99
|
+
add(rhs: number | BoxedExpression): BoxedExpression;
|
|
100
|
+
mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
|
|
101
|
+
div(rhs: number | BoxedExpression): BoxedExpression;
|
|
102
|
+
pow(exp: number | BoxedExpression): BoxedExpression;
|
|
103
|
+
root(exp: number | BoxedExpression): BoxedExpression;
|
|
104
|
+
sqrt(): BoxedExpression;
|
|
105
|
+
ln(semiBase?: number | BoxedExpression): BoxedExpression;
|
|
106
|
+
get complexity(): number | undefined;
|
|
107
|
+
get baseDefinition(): BoxedBaseDefinition | undefined;
|
|
108
|
+
get operatorDefinition(): BoxedOperatorDefinition | undefined;
|
|
109
|
+
get valueDefinition(): BoxedValueDefinition | undefined;
|
|
110
|
+
get isNumber(): boolean | undefined;
|
|
111
|
+
get isInteger(): boolean | undefined;
|
|
112
|
+
get isRational(): boolean | undefined;
|
|
113
|
+
get isReal(): boolean | undefined;
|
|
114
|
+
get isFunctionExpression(): boolean;
|
|
115
|
+
/** The type of the value of the function */
|
|
116
|
+
get type(): BoxedType;
|
|
117
|
+
simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
|
|
118
|
+
evaluate(options?: Partial<EvaluateOptions>): BoxedExpression;
|
|
119
|
+
evaluateAsync(options?: Partial<EvaluateOptions>): Promise<BoxedExpression>;
|
|
120
|
+
N(): BoxedExpression;
|
|
121
|
+
solve(vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
|
|
122
|
+
get isCollection(): boolean;
|
|
123
|
+
get isIndexedCollection(): boolean;
|
|
124
|
+
get isLazyCollection(): boolean;
|
|
125
|
+
contains(rhs: BoxedExpression): boolean | undefined;
|
|
126
|
+
get count(): number | undefined;
|
|
127
|
+
get isEmptyCollection(): boolean | undefined;
|
|
128
|
+
get isFiniteCollection(): boolean | undefined;
|
|
129
|
+
each(): Generator<BoxedExpression>;
|
|
130
|
+
at(index: number): BoxedExpression | undefined;
|
|
131
|
+
get(index: BoxedExpression | string): BoxedExpression | undefined;
|
|
132
|
+
indexWhere(predicate: (element: BoxedExpression) => boolean): number | undefined;
|
|
133
|
+
subsetOf(rhs: BoxedExpression, strict: boolean): boolean;
|
|
134
|
+
_computeValue(options?: Partial<EvaluateOptions>): () => BoxedExpression;
|
|
135
|
+
_computeValueAsync(options?: Partial<EvaluateOptions>): () => Promise<BoxedExpression>;
|
|
136
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import { Decimal } from 'decimal.js';
|
|
3
|
+
import type { Expression, MathJsonNumberObject } from '../../math-json';
|
|
4
|
+
import type { Rational, SmallInteger } from '../numerics/types';
|
|
5
|
+
import { ExactNumericValueData, NumericValue, NumericValueData } from '../numeric-value/types';
|
|
6
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
7
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
8
|
+
import type { BoxedRuleSet, BoxedSubstitution, CanonicalOptions, EvaluateOptions, ComputeEngine, Metadata, Rule, Sign, Substitution, BoxedExpression, PatternMatchOptions, ReplaceOptions, SimplifyOptions } from '../global-types';
|
|
9
|
+
/**
|
|
10
|
+
* BoxedNumber
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export declare class BoxedNumber extends _BoxedExpression {
|
|
14
|
+
protected readonly _value: SmallInteger | NumericValue;
|
|
15
|
+
private _hash;
|
|
16
|
+
/**
|
|
17
|
+
* By the time the constructor is called, the `value` should have been
|
|
18
|
+
* screened for cases where it's a well-known value (0, NaN, +Infinity,
|
|
19
|
+
* etc...) or non-normal (complex number with im = 0, rational with
|
|
20
|
+
* denom = 1, etc...).
|
|
21
|
+
*
|
|
22
|
+
* This is done in `ce.number()`. In general, use `ce.number()` rather
|
|
23
|
+
* than calling this constructor directly.
|
|
24
|
+
*
|
|
25
|
+
* We may store as a machine number if a Decimal is passed that is in machine
|
|
26
|
+
* range
|
|
27
|
+
*/
|
|
28
|
+
constructor(ce: ComputeEngine, value: SmallInteger | NumericValueData | ExactNumericValueData | NumericValue, options?: {
|
|
29
|
+
metadata?: Metadata;
|
|
30
|
+
});
|
|
31
|
+
get hash(): number;
|
|
32
|
+
get json(): Expression;
|
|
33
|
+
get operator(): string;
|
|
34
|
+
get isPure(): boolean;
|
|
35
|
+
get isCanonical(): boolean;
|
|
36
|
+
set isCanonical(val: boolean);
|
|
37
|
+
get complexity(): number;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Return a JavaScript number when possible (most cases); else return a
|
|
41
|
+
* string representation of the number (ComplexInfinity and complex numbers
|
|
42
|
+
* for example).
|
|
43
|
+
*
|
|
44
|
+
* When a JavaScript number is returned, it may have fewer digits than the
|
|
45
|
+
* original number, but it will be a close approximation.
|
|
46
|
+
*
|
|
47
|
+
* @returns {number | string} The value of the number.
|
|
48
|
+
*/
|
|
49
|
+
valueOf(): number | string;
|
|
50
|
+
get numericValue(): number | NumericValue;
|
|
51
|
+
get isNumberLiteral(): boolean;
|
|
52
|
+
get re(): number;
|
|
53
|
+
get im(): number;
|
|
54
|
+
get bignumRe(): Decimal | undefined;
|
|
55
|
+
get bignumIm(): Decimal | undefined;
|
|
56
|
+
neg(): BoxedExpression;
|
|
57
|
+
inv(): BoxedExpression;
|
|
58
|
+
abs(): BoxedExpression;
|
|
59
|
+
add(rhs: number | BoxedExpression): BoxedExpression;
|
|
60
|
+
mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
|
|
61
|
+
div(rhs: number | BoxedExpression): BoxedExpression;
|
|
62
|
+
pow(exp: number | BoxedExpression): BoxedExpression;
|
|
63
|
+
root(exp: number | BoxedExpression): BoxedExpression;
|
|
64
|
+
sqrt(): BoxedExpression;
|
|
65
|
+
ln(semiBase?: number | BoxedExpression): BoxedExpression;
|
|
66
|
+
get value(): BoxedExpression;
|
|
67
|
+
get type(): BoxedType;
|
|
68
|
+
get sgn(): Sign | undefined;
|
|
69
|
+
get numerator(): BoxedExpression;
|
|
70
|
+
get denominator(): BoxedExpression;
|
|
71
|
+
get numeratorDenominator(): [BoxedExpression, BoxedExpression];
|
|
72
|
+
subs(sub: Substitution, options?: {
|
|
73
|
+
canonical?: CanonicalOptions;
|
|
74
|
+
}): BoxedExpression;
|
|
75
|
+
replace(rules: BoxedRuleSet | Rule | Rule[], options?: Partial<ReplaceOptions>): BoxedExpression | null;
|
|
76
|
+
match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
77
|
+
/** x > 0, same as `isGreater(0)` */
|
|
78
|
+
get isPositive(): boolean | undefined;
|
|
79
|
+
/** x >= 0, same as `isGreaterEqual(0)` */
|
|
80
|
+
get isNonNegative(): boolean | undefined;
|
|
81
|
+
/** x < 0, same as `isLess(0)` */
|
|
82
|
+
get isNegative(): boolean | undefined;
|
|
83
|
+
/** x <= 0, same as `isLessEqual(0)` */
|
|
84
|
+
get isNonPositive(): boolean | undefined;
|
|
85
|
+
get isOdd(): boolean | undefined;
|
|
86
|
+
get isEven(): boolean | undefined;
|
|
87
|
+
get isInfinity(): boolean;
|
|
88
|
+
get isNaN(): boolean;
|
|
89
|
+
get isFinite(): boolean;
|
|
90
|
+
get isNumber(): true;
|
|
91
|
+
get isInteger(): boolean;
|
|
92
|
+
get isRational(): boolean;
|
|
93
|
+
get isReal(): boolean;
|
|
94
|
+
is(other: BoxedExpression | number | bigint | boolean): boolean;
|
|
95
|
+
get canonical(): BoxedExpression;
|
|
96
|
+
get isStructural(): boolean;
|
|
97
|
+
get structural(): BoxedExpression;
|
|
98
|
+
toNumericValue(): [NumericValue, BoxedExpression];
|
|
99
|
+
simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
|
|
100
|
+
evaluate(options?: Partial<EvaluateOptions>): BoxedExpression;
|
|
101
|
+
N(): BoxedExpression;
|
|
102
|
+
}
|
|
103
|
+
export declare function canonicalNumber(ce: ComputeEngine, value: number | bigint | string | Decimal | Complex | Rational | NumericValue | MathJsonNumberObject): number | NumericValue;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
3
|
+
import type { OperatorDefinition, BoxedExpression, BoxedOperatorDefinition, CollectionHandlers, CompiledExpression, EvaluateOptions, ComputeEngine, Sign } from '../global-types';
|
|
4
|
+
export declare class _BoxedOperatorDefinition implements BoxedOperatorDefinition {
|
|
5
|
+
engine: ComputeEngine;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string | string[];
|
|
8
|
+
url?: string;
|
|
9
|
+
wikidata?: string;
|
|
10
|
+
broadcastable: boolean;
|
|
11
|
+
associative: boolean;
|
|
12
|
+
commutative: boolean;
|
|
13
|
+
commutativeOrder: ((a: BoxedExpression, b: BoxedExpression) => number) | undefined;
|
|
14
|
+
idempotent: boolean;
|
|
15
|
+
involution: boolean;
|
|
16
|
+
pure: boolean;
|
|
17
|
+
complexity: number;
|
|
18
|
+
lazy: boolean;
|
|
19
|
+
scoped: boolean;
|
|
20
|
+
signature: BoxedType;
|
|
21
|
+
inferredSignature: boolean;
|
|
22
|
+
type?: (ops: ReadonlyArray<BoxedExpression>, options: {
|
|
23
|
+
engine: ComputeEngine;
|
|
24
|
+
}) => BoxedType | Type | TypeString | undefined;
|
|
25
|
+
sgn?: (ops: ReadonlyArray<BoxedExpression>, options: {
|
|
26
|
+
engine: ComputeEngine;
|
|
27
|
+
}) => Sign | undefined;
|
|
28
|
+
eq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
|
|
29
|
+
neq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
|
|
30
|
+
even?: (ops: ReadonlyArray<BoxedExpression>, options: {
|
|
31
|
+
engine: ComputeEngine;
|
|
32
|
+
}) => boolean | undefined;
|
|
33
|
+
canonical?: (ops: ReadonlyArray<BoxedExpression>, options: {
|
|
34
|
+
engine: ComputeEngine;
|
|
35
|
+
}) => BoxedExpression | null;
|
|
36
|
+
evaluate?: (ops: ReadonlyArray<BoxedExpression>, options: Partial<EvaluateOptions> & {
|
|
37
|
+
engine: ComputeEngine;
|
|
38
|
+
}) => BoxedExpression | undefined;
|
|
39
|
+
evaluateAsync?: (ops: ReadonlyArray<BoxedExpression>, options?: Partial<EvaluateOptions> & {
|
|
40
|
+
engine?: ComputeEngine;
|
|
41
|
+
}) => Promise<BoxedExpression | undefined>;
|
|
42
|
+
evalDimension?: (ops: ReadonlyArray<BoxedExpression>, options: {
|
|
43
|
+
engine: ComputeEngine;
|
|
44
|
+
}) => BoxedExpression;
|
|
45
|
+
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
46
|
+
collection?: CollectionHandlers;
|
|
47
|
+
constructor(ce: ComputeEngine, name: string, def: OperatorDefinition);
|
|
48
|
+
/** For debugging */
|
|
49
|
+
toJSON(): any;
|
|
50
|
+
infer(sig: Type): void;
|
|
51
|
+
update(def: OperatorDefinition): void;
|
|
52
|
+
onConfigurationChange(): void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
* # Pattern Matching Wildcards
|
|
3
|
+
*
|
|
4
|
+
* Patterns can contain wildcards that match parts of expressions. There are
|
|
5
|
+
* three types of wildcards:
|
|
6
|
+
*
|
|
7
|
+
* ## Universal Wildcard (`_` or `_name`)
|
|
8
|
+
* Matches exactly **one** expression element.
|
|
9
|
+
*
|
|
10
|
+
* - `_` - Anonymous wildcard (matches one element, not captured)
|
|
11
|
+
* - `_a`, `_x`, `_foo` - Named wildcard (matches one element, captured in substitution)
|
|
12
|
+
*
|
|
13
|
+
* **Examples:**
|
|
14
|
+
* - Pattern `['Add', '_a', 1]` matches `['Add', 'x', 1]` with `{_a: 'x'}`
|
|
15
|
+
* - Pattern `['Add', '_', '_']` matches any binary Add expression
|
|
16
|
+
*
|
|
17
|
+
* ## Sequence Wildcard (`__` or `__name`)
|
|
18
|
+
* Matches **one or more** expression elements.
|
|
19
|
+
*
|
|
20
|
+
* - `__` - Anonymous sequence (matches 1+ elements, not captured)
|
|
21
|
+
* - `__a`, `__args` - Named sequence (matches 1+ elements, captured as array)
|
|
22
|
+
*
|
|
23
|
+
* **Examples:**
|
|
24
|
+
* - Pattern `['Add', '__a']` matches `['Add', 1, 2, 3]` with `{__a: [1, 2, 3]}`
|
|
25
|
+
* - Pattern `['f', '__args']` captures all arguments of function f
|
|
26
|
+
*
|
|
27
|
+
* ## Optional Sequence Wildcard (`___` or `___name`)
|
|
28
|
+
* Matches **zero or more** expression elements.
|
|
29
|
+
*
|
|
30
|
+
* - `___` - Anonymous optional sequence (matches 0+ elements, not captured)
|
|
31
|
+
* - `___a`, `___rest` - Named optional sequence (matches 0+ elements, captured)
|
|
32
|
+
*
|
|
33
|
+
* **Examples:**
|
|
34
|
+
* - Pattern `['Add', 1, '___rest']` matches `['Add', 1]` with `{___rest: []}`
|
|
35
|
+
* - Pattern `['Add', 1, '___rest']` matches `['Add', 1, 2, 3]` with `{___rest: [2, 3]}`
|
|
36
|
+
*
|
|
37
|
+
* ## Validation Rules
|
|
38
|
+
*
|
|
39
|
+
* Consecutive multi-element wildcards (`__` or `___`) are **invalid** because
|
|
40
|
+
* there's no way to determine where one ends and the next begins:
|
|
41
|
+
*
|
|
42
|
+
* - **Invalid:** `['Add', '__a', '__b']` - How to split elements between `__a` and `__b`?
|
|
43
|
+
* - **Invalid:** `['Add', '___a', '___b']` - Same ambiguity
|
|
44
|
+
* - **Invalid:** `['Add', '__a', '___b']` - Same ambiguity
|
|
45
|
+
*
|
|
46
|
+
* However, multi-element wildcards followed by universal wildcards are **valid**
|
|
47
|
+
* because the single-element wildcard provides an anchor point:
|
|
48
|
+
*
|
|
49
|
+
* - **Valid:** `['Add', '__a', '_b']` - `_b` matches last element, `__a` gets the rest
|
|
50
|
+
* - **Valid:** `['Add', '___a', '_b', '___c']` - `_b` anchors the middle
|
|
51
|
+
*
|
|
52
|
+
* Use `validatePattern()` to check patterns for these invalid combinations.
|
|
53
|
+
*
|
|
54
|
+
* @module boxed-patterns
|
|
55
|
+
*/
|
|
56
|
+
import type { BoxedSymbol } from './boxed-symbol';
|
|
57
|
+
import type { BoxedExpression } from '../global-types';
|
|
58
|
+
/**
|
|
59
|
+
* Check if an expression is a wildcard (universal, sequence, or optional sequence).
|
|
60
|
+
*
|
|
61
|
+
* @param expr - The expression to check
|
|
62
|
+
* @returns `true` if the expression is any type of wildcard
|
|
63
|
+
*/
|
|
64
|
+
export declare function isWildcard(expr: BoxedExpression): expr is BoxedSymbol;
|
|
65
|
+
/**
|
|
66
|
+
* Get the string representation of a wildcard expression.
|
|
67
|
+
*
|
|
68
|
+
* Returns the wildcard symbol including its name (if any):
|
|
69
|
+
* - `'_'` for anonymous universal wildcard
|
|
70
|
+
* - `'_a'` for named universal wildcard
|
|
71
|
+
* - `'__'` for anonymous sequence wildcard
|
|
72
|
+
* - `'__args'` for named sequence wildcard
|
|
73
|
+
* - `'___'` for anonymous optional sequence wildcard
|
|
74
|
+
* - `'___rest'` for named optional sequence wildcard
|
|
75
|
+
*
|
|
76
|
+
* @param expr - The expression to get the wildcard name from
|
|
77
|
+
* @returns The wildcard string, or `null` if not a wildcard
|
|
78
|
+
*/
|
|
79
|
+
export declare function wildcardName(expr: BoxedExpression): string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Determine the type of wildcard.
|
|
82
|
+
*
|
|
83
|
+
* @param expr - A BoxedExpression or wildcard symbol string
|
|
84
|
+
* @returns
|
|
85
|
+
* - `'Wildcard'` - Universal wildcard (`_` or `_name`), matches exactly one element
|
|
86
|
+
* - `'Sequence'` - Sequence wildcard (`__` or `__name`), matches one or more elements
|
|
87
|
+
* - `'OptionalSequence'` - Optional sequence (`___` or `___name`), matches zero or more elements
|
|
88
|
+
* - `null` - Not a wildcard
|
|
89
|
+
*/
|
|
90
|
+
export declare function wildcardType(expr: BoxedExpression | string): 'Wildcard' | 'Sequence' | 'OptionalSequence' | null;
|
|
91
|
+
/**
|
|
92
|
+
* Validate a pattern for invalid wildcard combinations.
|
|
93
|
+
*
|
|
94
|
+
* Throws an error if the pattern contains consecutive multi-element wildcards:
|
|
95
|
+
* - Sequence (`__`) followed by Sequence (`__`) or OptionalSequence (`___`)
|
|
96
|
+
* - OptionalSequence (`___`) followed by Sequence (`__`) or OptionalSequence (`___`)
|
|
97
|
+
*
|
|
98
|
+
* These patterns are ambiguous because there's no delimiter to determine where
|
|
99
|
+
* one sequence ends and the next begins.
|
|
100
|
+
*
|
|
101
|
+
* Sequence or OptionalSequence followed by universal Wildcard (`_`) is allowed
|
|
102
|
+
* because the single-element wildcard provides an anchor point.
|
|
103
|
+
*
|
|
104
|
+
* @param pattern - The pattern to validate
|
|
105
|
+
* @throws Error if the pattern contains invalid wildcard combinations
|
|
106
|
+
*/
|
|
107
|
+
export declare function validatePattern(pattern: BoxedExpression): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* 0.32.1 */
|
|
2
|
+
import { _BoxedExpression } from './abstract-boxed-expression';
|
|
3
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
4
|
+
/**
|
|
5
|
+
* BoxedString
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare class BoxedString extends _BoxedExpression {
|
|
9
|
+
[Symbol.toStringTag]: string;
|
|
10
|
+
private readonly _string;
|
|
11
|
+
private _utf8Buffer?;
|
|
12
|
+
private _unicodeScalarValues?;
|
|
13
|
+
constructor(ce: ComputeEngine, expr: string, metadata?: Metadata);
|
|
14
|
+
get json(): string;
|
|
15
|
+
get hash(): number;
|
|
16
|
+
get operator(): string;
|
|
17
|
+
get isPure(): boolean;
|
|
18
|
+
get isCanonical(): boolean;
|
|
19
|
+
set isCanonical(_va: boolean);
|
|
20
|
+
get value(): BoxedExpression;
|
|
21
|
+
get type(): BoxedType;
|
|
22
|
+
get complexity(): number;
|
|
23
|
+
get string(): string;
|
|
24
|
+
get buffer(): Uint8Array;
|
|
25
|
+
get unicodeScalars(): number[];
|
|
26
|
+
match(pattern: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
27
|
+
}
|