@cortex-js/compute-engine 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{compute-engine.js → compute-engine.cjs} +24718 -24251
- package/dist/compute-engine.esm.js +24718 -24251
- package/dist/compute-engine.min.cjs +129 -0
- package/dist/compute-engine.min.esm.js +55 -68
- package/dist/math-json.cjs +413 -0
- package/dist/math-json.esm.js +287 -7
- package/dist/math-json.min.cjs +6 -0
- package/dist/math-json.min.esm.js +287 -7
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +2 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +2 -2
- package/dist/types/common/json5.d.ts +3 -0
- package/dist/types/common/one-of.d.ts +2 -1
- package/dist/types/common/signals.d.ts +1 -2
- package/dist/types/common/type/boxed-type.d.ts +14 -0
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +2 -1
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +121 -136
- package/dist/types/common/type/utils.d.ts +3 -7
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +17 -18
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +5 -4
- 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 +2 -2
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +20 -14
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +14 -13
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +8 -10
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +4 -5
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -5
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +11 -11
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +7 -10
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -3
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/product.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -2
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +2 -9
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +13 -4
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +9 -10
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +2 -4
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/{boxed-expression/public.d.ts → global-types.d.ts} +887 -849
- package/dist/types/compute-engine/{compute-engine.d.ts → index.d.ts} +29 -19
- 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-linear-algebra.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-relational-operators.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 +2 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/{public.d.ts → types.d.ts} +13 -6
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -2
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +3 -2
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/invisible-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/library.d.ts +3 -3
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +3 -5
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +3 -4
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +3 -5
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
- package/dist/types/compute-engine/numeric-value/{public.d.ts → types.d.ts} +9 -5
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -7
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -5
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +4 -4
- package/dist/types/compute-engine/numerics/statistics.d.ts +2 -2
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +30 -0
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/{boxed-expression → tensor}/tensor-fields.d.ts +19 -18
- package/dist/types/compute-engine/tensor/tensors.d.ts +9 -12
- package/dist/types/compute-engine/types.d.ts +11 -0
- package/dist/types/compute-engine.d.ts +3 -5
- package/dist/types/math-json/identifiers.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +9 -7
- package/dist/types/math-json/utils.d.ts +3 -3
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +9 -9
- package/dist/compute-engine.min.js +0 -142
- package/dist/math-json.js +0 -133
- package/dist/math-json.min.js +0 -4
- package/dist/types/common/buffer.d.ts +0 -9
- package/dist/types/common/styled-text.d.ts +0 -28
- package/dist/types/common/suggest.d.ts +0 -1
- package/dist/types/common/syntax-highlighter.d.ts +0 -40
- package/dist/types/common/terminal.d.ts +0 -19
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +0 -12
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +0 -16
- package/dist/types/compute-engine/debug.d.ts +0 -3
- package/dist/types/compute-engine/numerics/bignum.d.ts +0 -12
- package/dist/types/compute-engine/private.d.ts +0 -29
- package/dist/types/compute-engine/public.d.ts +0 -42
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
infer Head,
|
|
3
3
|
...infer Rem
|
|
4
4
|
] ? MergeTypes<Rem, Res & Head> : Res;
|
|
5
|
+
/** @internal */
|
|
5
6
|
export type OneOf<TypesArray extends any[], Res = never, AllProperties = MergeTypes<TypesArray>> = TypesArray extends [infer Head, ...infer Rem] ? OneOf<Rem, Res | OnlyFirst<Head, AllProperties>, AllProperties> : Res;
|
|
6
7
|
type OnlyFirst<F, S> = F & {
|
|
7
8
|
[Key in keyof Omit<S, keyof F>]?: never;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
/** @category Error Handling */
|
|
1
|
+
/* 0.29.0 */
|
|
3
2
|
export type RuntimeSignalCode = 'timeout' | 'out-of-memory' | 'recursion-depth-exceeded' | 'iteration-limit-exceeded';
|
|
4
3
|
/** @category Error Handling */
|
|
5
4
|
export type SignalCode = RuntimeSignalCode | ('invalid-name' | 'expected-predicate' | 'expected-symbol' | 'operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'prefix-operator-requires-one-operand' | 'unbalanced-symbols' | 'expected-argument' | 'unexpected-command' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry' | 'syntax-error');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* 0.29.0 */
|
|
2
|
+
/** @category Type */
|
|
3
|
+
export declare class BoxedType {
|
|
4
|
+
static unknown: BoxedType;
|
|
5
|
+
type: Type;
|
|
6
|
+
constructor(type: Type | TypeString);
|
|
7
|
+
matches(other: Type | TypeString | BoxedType): boolean;
|
|
8
|
+
is(other: Type | TypeString): boolean;
|
|
9
|
+
get isUnknown(): boolean;
|
|
10
|
+
toString(): string;
|
|
11
|
+
toJSON(): string;
|
|
12
|
+
[Symbol.toPrimitive](hint: string): string | null;
|
|
13
|
+
valueOf(): string;
|
|
14
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
export declare function typeToString(type: Type, precedence?: number): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
* A primitive type is a simple type that represents a concrete value.
|
|
3
3
|
*
|
|
4
4
|
* - `any`: the top type
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
*
|
|
11
11
|
* - `expression`:
|
|
12
12
|
* - a symbolic expression, such as `["Add", "x", 1]`
|
|
13
|
-
* -
|
|
13
|
+
* - `<value>`
|
|
14
14
|
* - `symbol`: a symbol, such as `x`.
|
|
15
15
|
* - `function`: a function expression
|
|
16
16
|
* such as `["Function", ["Add", "x", 1], "x"]`.
|
|
17
17
|
*
|
|
18
18
|
* - `value`
|
|
19
19
|
* - `scalar`
|
|
20
|
-
* -
|
|
20
|
+
* - `<number>`
|
|
21
21
|
* - `boolean`: a boolean value: `True` or `False`.
|
|
22
22
|
* - `string`: a string of characters.
|
|
23
23
|
* - `collection`
|
|
@@ -30,24 +30,26 @@
|
|
|
30
30
|
* `tuple<number, boolean>`, `tuple<x: number, y: boolean>`.
|
|
31
31
|
* - `map`: a set key-value pairs, e.g. `map<x: number, y: boolean>`.
|
|
32
32
|
*
|
|
33
|
-
* - `number`: any numeric value:
|
|
34
|
-
* - `finite_number`: <finite_complex> or <finite_imaginary> or
|
|
35
|
-
* <finite_real> or <finite_rational> or <finite_integer>
|
|
36
|
-
* - `non_finite_number`: `NaN`, `PositiveInfinity`, `NegativeInfinity` or
|
|
37
|
-
* `ComplexInfinity`
|
|
38
|
-
* - `complex` and `finite_complex`: a complex number, with non-zero real
|
|
39
|
-
* and imaginary parts.
|
|
40
|
-
* - `imaginary` and `finite_imaginary`: a complex number with a real part
|
|
41
|
-
* of 0 (pure imaginary).
|
|
42
|
-
* - `real` and `finite_real`: a complex number with an imaginary part of 0.
|
|
43
|
-
* - `rational` and `finite_rational`: a pure rational number
|
|
44
|
-
* (not an integer)
|
|
45
|
-
* - `integer` and `finite_integer`: a whole number
|
|
46
33
|
*
|
|
47
34
|
*
|
|
48
35
|
*/
|
|
49
36
|
export type PrimitiveType = NumericType | 'collection' | 'list' | 'set' | 'map' | 'tuple' | 'value' | 'scalar' | 'function' | 'symbol' | 'boolean' | 'string' | 'expression' | 'unknown' | 'error' | 'nothing' | 'never' | 'any';
|
|
50
|
-
|
|
37
|
+
/**
|
|
38
|
+
* - `number`: any numeric value = `complex` + `real` plus `NaN`
|
|
39
|
+
* - `complex`: a number with non-zero real and imaginary parts = `finite_complex` plus `ComplexInfinity`
|
|
40
|
+
* - `finite_complex`: a finite complex number = `imaginary` + `finite_real`
|
|
41
|
+
* - `imaginary`: a complex number with a real part of 0 (pure imaginary)
|
|
42
|
+
* - `finite_number`: a finite numeric value = `finite_complex`
|
|
43
|
+
* - `finite_real`: a finite real number = `finite_rational` + `finite_integer`
|
|
44
|
+
* - `finite_rational`: a pure rational number
|
|
45
|
+
* - `finite_integer`: a whole number
|
|
46
|
+
* - `real`: a complex number with an imaginary part of 0 = `finite_real` + `non_finite_number`
|
|
47
|
+
* - `non_finite_number`: `PositiveInfinity`, `NegativeInfinity`
|
|
48
|
+
* - `integer`: a whole number = `finite_integer` + `non_finite_number`
|
|
49
|
+
* - `rational`: a pure rational number (not an integer) = `finite_rational` + `non_finite_number`
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export type NumericType = 'number' | 'finite_number' | 'complex' | 'finite_complex' | 'imaginary' | 'real' | 'finite_real' | 'rational' | 'finite_rational' | 'integer' | 'finite_integer' | 'non_finite_number';
|
|
51
53
|
export type NamedElement = {
|
|
52
54
|
name?: string;
|
|
53
55
|
type: Type;
|
|
@@ -71,7 +73,7 @@ export type ValueType = {
|
|
|
71
73
|
kind: 'value';
|
|
72
74
|
value: any;
|
|
73
75
|
};
|
|
74
|
-
/** Map is
|
|
76
|
+
/** Map is a non-indexable collection of key/value pairs.
|
|
75
77
|
* An element of a map whose type is a subtype of `nothing` is optional.
|
|
76
78
|
* For example, in `{x: number, y: boolean | nothing}` the element `y` is optional.
|
|
77
79
|
*/
|
|
@@ -90,8 +92,8 @@ export type CollectionType = {
|
|
|
90
92
|
/**
|
|
91
93
|
* The elements of a list are ordered.
|
|
92
94
|
*
|
|
93
|
-
* All elements of a list have the same type
|
|
94
|
-
* up to `any
|
|
95
|
+
* All elements of a list have the same type, but it can be a broad type,
|
|
96
|
+
* up to `any`.
|
|
95
97
|
*
|
|
96
98
|
* The same element can be present in the list more than once.
|
|
97
99
|
*
|
|
@@ -128,122 +130,105 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
128
130
|
* The type is represented either by a primitive type (e.g. number, complex, collection, etc.), or a compound type (e.g. tuple, function signature, etc.).
|
|
129
131
|
*
|
|
130
132
|
* Types are described using the following BNF grammar:
|
|
131
|
-
|
|
132
|
-
```bnf
|
|
133
|
-
<type> ::= <union_type>
|
|
134
|
-
|
|
135
|
-
<union_type> ::= <intersection_type> (" | " <intersection_type>)*
|
|
136
|
-
|
|
137
|
-
<intersection_type> ::= <primary_type> (" & " <primary_type>)*
|
|
138
|
-
|
|
139
|
-
<primary_type> ::= <primitive>
|
|
140
|
-
| <tuple_type>
|
|
141
|
-
| <
|
|
142
|
-
| <list_type>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<
|
|
149
|
-
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
<
|
|
169
|
-
| <
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
<
|
|
195
|
-
|
|
196
|
-
<
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
<
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
"[(number, boolean)]" -- a collection of tuples
|
|
231
|
-
"[(value:number, seen:boolean)]" -- a collection of named tuples
|
|
232
|
-
"[boolean]^32" -- a collection type with a fixed size of 32 elements
|
|
233
|
-
"[integer]^(2x3)" -- an integer matrix of 2 columns and 3 rows
|
|
234
|
-
"[integer]^(2x3x4)" -- a tensor of dimensions 2x3x4
|
|
235
|
-
|
|
236
|
-
"number -> number" -- a function type with a single argument
|
|
237
|
-
"(x: number, number) -> number" -- a function type with a named argument
|
|
238
|
-
"(number, y:number?) -> number" -- a function type with an optional named argument (can have several optional arguments, at the end)
|
|
239
|
-
"(number, ...number) -> number" -- a function type with a rest argument (can have only one, and no optional arguments if there is a rest argument).
|
|
240
|
-
"() -> number" -- a function type with an empty argument list
|
|
241
|
-
|
|
242
|
-
"number | boolean" -- a union type
|
|
243
|
-
"(x: number) & (y: number)" -- an intersection type
|
|
244
|
-
"number | ((x: number) & (y: number))" -- a union type with an intersection type
|
|
245
|
-
"(number -> number) | number" -- a union type with a function type
|
|
246
|
-
*/
|
|
133
|
+
*
|
|
134
|
+
* ```bnf
|
|
135
|
+
* <type> ::= <union_type> | "(" <type> ")"
|
|
136
|
+
*
|
|
137
|
+
* <union_type> ::= <intersection_type> (" | " <intersection_type>)*
|
|
138
|
+
*
|
|
139
|
+
* <intersection_type> ::= <primary_type> (" & " <primary_type>)*
|
|
140
|
+
*
|
|
141
|
+
* <primary_type> ::= <primitive>
|
|
142
|
+
* | <tuple_type>
|
|
143
|
+
* | <signature>
|
|
144
|
+
* | <list_type>
|
|
145
|
+
*
|
|
146
|
+
* <primitive> ::= "any" | "unknown" | <value-type> | <symbolic-type> | <numeric-type>
|
|
147
|
+
*
|
|
148
|
+
* <numeric-type> ::= "number" | "complex" | "imaginary" | "real" | "rational" | "integer"
|
|
149
|
+
*
|
|
150
|
+
* <value-type> ::= "value" | <numeric-type> | "collection" | "boolean" | "string"
|
|
151
|
+
*
|
|
152
|
+
* <symbolic-type> ::= "expression" | "function" | "symbol"
|
|
153
|
+
*
|
|
154
|
+
* <tuple_type> ::= "tuple<" (<name> <type> "," <named_tuple_elements>*) ">"
|
|
155
|
+
* | "tuple<" (<type> "," <unnamed_tuple_elements>*) ">" |
|
|
156
|
+
* | "tuple<" <tuple_elements> ">"
|
|
157
|
+
*
|
|
158
|
+
* <tuple_elements> ::= <unnamed_tuple_elements> | <named_tuple_elements>
|
|
159
|
+
*
|
|
160
|
+
* <unnamed_tuple_elements> ::= <type> ("," <type>)*
|
|
161
|
+
*
|
|
162
|
+
* <named_tuple_elements> ::= <name> <type> ("," <name> <type>)*
|
|
163
|
+
*
|
|
164
|
+
* <signature> ::= <arguments> " -> " <type>
|
|
165
|
+
*
|
|
166
|
+
* <arguments> ::= "()"
|
|
167
|
+
* | <argument>
|
|
168
|
+
* | "(" <argument-list> ")"
|
|
169
|
+
*
|
|
170
|
+
* <argument> ::= <type>
|
|
171
|
+
* | <name> <type>
|
|
172
|
+
*
|
|
173
|
+
* <rest_argument> ::= "..." <type>
|
|
174
|
+
* | <name> "..." <type>
|
|
175
|
+
*
|
|
176
|
+
* <optional_argument> ::= <argument> "?"
|
|
177
|
+
*
|
|
178
|
+
* <optional_arguments> ::= <optional_argument> ("," <optional_argument>)*
|
|
179
|
+
*
|
|
180
|
+
* <required_arguments> ::= <argument> ("," <argument>)*
|
|
181
|
+
*
|
|
182
|
+
* <argument-list> ::= <required_arguments> ("," <rest_argument>)?
|
|
183
|
+
* | <required_arguments> <optional_arguments>?
|
|
184
|
+
* | <optional_arguments>?
|
|
185
|
+
* | <rest_argument>
|
|
186
|
+
*
|
|
187
|
+
* <list_type> ::= "list<" <type> <dimensions>? ">"
|
|
188
|
+
*
|
|
189
|
+
* <dimensions> ::= "^" <fixed_size>
|
|
190
|
+
* | "^(" <multi_dimensional_size> ")"
|
|
191
|
+
*
|
|
192
|
+
* <fixed_size> ::= <positive-integer_literal>
|
|
193
|
+
*
|
|
194
|
+
* <multi_dimensional_size> ::= <positive-integer_literal> "x" <positive-integer_literal> ("x" <positive-integer_literal>)*
|
|
195
|
+
*
|
|
196
|
+
* <map> ::= "map" | "map<" <map_elements> ">"
|
|
197
|
+
*
|
|
198
|
+
* <map_elements> ::= <name> <type> ("," <name> <type>)*
|
|
199
|
+
*
|
|
200
|
+
* <set> ::= "set<" <type> ">"
|
|
201
|
+
*
|
|
202
|
+
* <collection ::= "collection<" <type> ">"
|
|
203
|
+
*
|
|
204
|
+
* <name> ::= <identifier> ":"
|
|
205
|
+
*
|
|
206
|
+
* <identifier> ::= [a-zA-Z_][a-zA-Z0-9_]*
|
|
207
|
+
*
|
|
208
|
+
* <positive-integer_literal> ::= [1-9][0-9]*
|
|
209
|
+
*```
|
|
210
|
+
*
|
|
211
|
+
* Examples of types strings:
|
|
212
|
+
* - `"number"` -- a simple type primitive
|
|
213
|
+
* - `"(number, boolean)"` -- a tuple type
|
|
214
|
+
* - `"(x: number, y:boolean)"` -- a named tuple/record type. Either all arguments are named, or none are
|
|
215
|
+
* - `"collection<any>"` -- an arbitrary collection type, with no length or element type restrictions
|
|
216
|
+
* - `"collection<integer>"` -- a collection type where all the elements are integers
|
|
217
|
+
* - `"collection<(number, boolean)>"` -- a collection of tuples
|
|
218
|
+
* - `"collection<(value:number, seen:boolean)>"` -- a collection of named tuples
|
|
219
|
+
* - `"[boolean]^32"` -- a collection type with a fixed size of 32 elements
|
|
220
|
+
* - `"[integer]^(2x3)"` -- an integer matrix of 2 columns and 3 rows
|
|
221
|
+
* - `"[integer]^(2x3x4)"` -- a tensor of dimensions 2x3x4
|
|
222
|
+
* - `"number -> number"` -- a signature with a single argument
|
|
223
|
+
* - `"(x: number, number) -> number"` -- a signature with a named argument
|
|
224
|
+
* - `"(number, y:number?) -> number"` -- a signature with an optional named argument (can have several optional arguments, at the end)
|
|
225
|
+
* - `"(number, ...number) -> number"` -- a signature with a rest argument (can have only one, and no optional arguments if there is a rest argument).
|
|
226
|
+
* - `"() -> number"` -- a signature with an empty argument list
|
|
227
|
+
* - `"number | boolean"` -- a union type
|
|
228
|
+
* - `"(x: number) & (y: number)"` -- an intersection type
|
|
229
|
+
* - `"number | ((x: number) & (y: number))"` -- a union type with an intersection type
|
|
230
|
+
* - `"(number -> number) | number"` -- a union type with a signature and a primitive type
|
|
231
|
+
*/
|
|
247
232
|
export type TypeString = string;
|
|
248
233
|
export type TypeCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
249
234
|
export type TypeResolver = (name: string) => Type | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
/** Convert two or more types into a more specific type that is a subtype of
|
|
3
3
|
* all the input types. The resulting type is usually more constrained and
|
|
4
4
|
* only encompasses values that belong to both input types.
|
|
@@ -27,13 +27,9 @@ export declare function narrow(...types: Readonly<Type>[]): Type;
|
|
|
27
27
|
* widen('number', 'expression') => 'expression'
|
|
28
28
|
* widen('number', 'string') => 'any'
|
|
29
29
|
*/
|
|
30
|
-
export declare function widen(...types: Readonly<Type>[]): Type
|
|
30
|
+
export declare function widen(...types: Readonly<Type>[]): Readonly<Type>;
|
|
31
31
|
export declare function isSignatureType(type: Readonly<Type> | TypeString): type is FunctionSignature;
|
|
32
32
|
export declare function functionSignature(type: Readonly<Type>): Type | undefined;
|
|
33
|
-
export declare function functionResult(type: Readonly<Type>): Type | undefined;
|
|
33
|
+
export declare function functionResult(type: Readonly<Type> | undefined): Type | undefined;
|
|
34
34
|
export declare function collectionElementType(type: Readonly<Type>): Type | undefined;
|
|
35
35
|
export declare function isValidType(t: any): t is Readonly<Type>;
|
|
36
|
-
/**
|
|
37
|
-
* Add a `toString()` method to the type object
|
|
38
|
-
*/
|
|
39
|
-
export declare function makeType(type: Type): Readonly<Type>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
export declare function hidePrivateProperties(obj: any): void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
import { Expression, MathJsonIdentifier } from '../../math-json/types';
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
3
|
+
import type { Type, TypeString } from '../../common/type/types';
|
|
4
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
5
|
+
import type { BoxedSubstitution, Metadata, RuntimeScope, Substitution, CanonicalOptions, BoxedRuleSet, Rule, BoxedBaseDefinition, BoxedSymbolDefinition, BoxedFunctionDefinition, EvaluateOptions, CompiledType, Sign, BoxedExpression, JsonSerializationOptions, PatternMatchOptions, SimplifyOptions, TensorData, ComputeEngine } from '../global-types';
|
|
6
|
+
import type { NumericValue } from '../numeric-value/types';
|
|
7
|
+
import type { SmallInteger } from '../numerics/types';
|
|
8
|
+
import type { LatexString, SerializeLatexOptions } from '../latex-syntax/types';
|
|
8
9
|
import { AsciiMathOptions } from './ascii-math';
|
|
9
10
|
/**
|
|
10
11
|
* _BoxedExpression
|
|
@@ -18,12 +19,12 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
18
19
|
abstract get isCanonical(): boolean;
|
|
19
20
|
abstract set isCanonical(_val: boolean);
|
|
20
21
|
abstract match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
21
|
-
readonly engine:
|
|
22
|
+
readonly engine: ComputeEngine;
|
|
22
23
|
/** Verbatim LaTeX, obtained from a source, i.e. from parsing,
|
|
23
24
|
* not generated synthetically
|
|
24
25
|
*/
|
|
25
26
|
verbatimLatex?: string;
|
|
26
|
-
constructor(ce:
|
|
27
|
+
constructor(ce: ComputeEngine, metadata?: Metadata);
|
|
27
28
|
isSame(rhs: BoxedExpression): boolean;
|
|
28
29
|
isEqual(rhs: number | BoxedExpression): boolean | undefined;
|
|
29
30
|
isLess(_rhs: number | BoxedExpression): boolean | undefined;
|
|
@@ -60,7 +61,7 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
60
61
|
get latex(): LatexString;
|
|
61
62
|
set latex(val: LatexString);
|
|
62
63
|
get symbol(): string | null;
|
|
63
|
-
get tensor(): null |
|
|
64
|
+
get tensor(): null | TensorData<'expression'>;
|
|
64
65
|
get string(): string | null;
|
|
65
66
|
getSubexpressions(operator: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
|
|
66
67
|
get subexpressions(): ReadonlyArray<BoxedExpression>;
|
|
@@ -116,7 +117,7 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
116
117
|
canonical: CanonicalOptions;
|
|
117
118
|
recursive?: boolean;
|
|
118
119
|
}): BoxedExpression;
|
|
119
|
-
solve(_vars
|
|
120
|
+
solve(_vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
|
|
120
121
|
replace(_rules: BoxedRuleSet | Rule | Rule[]): null | BoxedExpression;
|
|
121
122
|
has(_v: string | string[]): boolean;
|
|
122
123
|
get isPositive(): boolean | undefined;
|
|
@@ -130,13 +131,13 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
130
131
|
get baseDefinition(): BoxedBaseDefinition | undefined;
|
|
131
132
|
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
132
133
|
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
133
|
-
infer(
|
|
134
|
+
infer(_t: Type): boolean;
|
|
134
135
|
bind(): void;
|
|
135
136
|
reset(): void;
|
|
136
137
|
get value(): number | boolean | string | object | undefined;
|
|
137
138
|
set value(_value: BoxedExpression | number | boolean | string | number[] | undefined);
|
|
138
|
-
get type():
|
|
139
|
-
set type(_type: Type);
|
|
139
|
+
get type(): BoxedType;
|
|
140
|
+
set type(_type: Type | TypeString | BoxedType);
|
|
140
141
|
get isNumber(): boolean | undefined;
|
|
141
142
|
get isInteger(): boolean | undefined;
|
|
142
143
|
get isRational(): boolean | undefined;
|
|
@@ -144,15 +145,15 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
144
145
|
simplify(_options?: Partial<SimplifyOptions>): BoxedExpression;
|
|
145
146
|
expand(): BoxedExpression;
|
|
146
147
|
evaluate(_options?: Partial<EvaluateOptions>): BoxedExpression;
|
|
148
|
+
evaluateAsync(_options?: Partial<EvaluateOptions>): Promise<BoxedExpression>;
|
|
147
149
|
N(): BoxedExpression;
|
|
148
150
|
compile(options?: {
|
|
149
151
|
to?: 'javascript';
|
|
150
|
-
optimize?: ('simplify' | 'evaluate')[];
|
|
151
152
|
functions?: Record<MathJsonIdentifier, string | ((...any: any[]) => any)>;
|
|
152
153
|
vars?: Record<MathJsonIdentifier, string>;
|
|
153
|
-
imports?:
|
|
154
|
+
imports?: ((...any: any[]) => any)[];
|
|
154
155
|
preamble?: string;
|
|
155
|
-
}): (args: Record<string, any>) =>
|
|
156
|
+
}): (args: Record<string, any>) => CompiledType;
|
|
156
157
|
get isCollection(): boolean;
|
|
157
158
|
contains(_rhs: BoxedExpression): boolean;
|
|
158
159
|
subsetOf(_target: BoxedExpression, _strict: boolean): boolean;
|
|
@@ -163,5 +164,3 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
|
|
|
163
164
|
indexOf(_expr: BoxedExpression): number;
|
|
164
165
|
}
|
|
165
166
|
export declare function getSubexpressions(expr: BoxedExpression, name: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
|
|
166
|
-
import { Type } from '../../common/type/types';
|
|
167
|
-
import { AbstractTensor } from '../tensor/tensors';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
import { Decimal } from 'decimal.js';
|
|
3
|
-
import type { BoxedExpression } from '../
|
|
3
|
+
import type { BoxedExpression } from '../global-types';
|
|
4
4
|
export declare function apply(expr: BoxedExpression, fn: (x: number) => number | Complex, bigFn?: (x: Decimal) => Decimal | Complex | number, complexFn?: (x: Complex) => number | Complex): BoxedExpression | undefined;
|
|
5
5
|
export declare function apply2(expr1: BoxedExpression, expr2: BoxedExpression, fn: (x1: number, x2: number) => number | Complex, bigFn?: (x1: Decimal, x2: Decimal) => Decimal | Complex | number, complexFn?: (x1: Complex, x2: number | Complex) => Complex | number): BoxedExpression | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import {
|
|
1
|
+
/* 0.29.0 */
|
|
2
|
+
import { BoxedType } from '../../common/type/boxed-type';
|
|
3
|
+
import type { BoxedExpression, ComputeEngine } from '../global-types';
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
5
6
|
* The canonical form of `Add`:
|
|
@@ -9,7 +10,7 @@ import { Type } from '../../common/type/types';
|
|
|
9
10
|
* - sort the terms
|
|
10
11
|
*
|
|
11
12
|
*/
|
|
12
|
-
export declare function canonicalAdd(ce:
|
|
13
|
-
export declare function addType(args: ReadonlyArray<BoxedExpression>): Type;
|
|
13
|
+
export declare function canonicalAdd(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
14
|
+
export declare function addType(args: ReadonlyArray<BoxedExpression>): Type | BoxedType;
|
|
14
15
|
export declare function add(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
15
16
|
export declare function addN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* 0.29.0 */
|
|
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 numerator and denominator are integer literals, return a rational number
|
|
8
|
+
* or Rational expression
|
|
9
|
+
* - evaluate number literals
|
|
10
|
+
*/
|
|
11
|
+
export declare function canonicalDivide(op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
|
|
12
|
+
export declare function div(num: BoxedExpression, denom: number | BoxedExpression): BoxedExpression;
|
|
13
|
+
/**
|
|
14
|
+
* The canonical form of `Multiply`:
|
|
15
|
+
* - removes `1` anb `-1`
|
|
16
|
+
* - simplifies the signs:
|
|
17
|
+
* - i.e. `-y \times -x` -> `x \times y`
|
|
18
|
+
* - `2 \times -x` -> `-2 \times x`
|
|
19
|
+
* - arguments are sorted
|
|
20
|
+
* - complex numbers promoted (['Multiply', 2, 'ImaginaryUnit'] -> 2i)
|
|
21
|
+
* - Numeric values are promoted (['Multiply', 2, 'Sqrt', 3] -> 2√3)
|
|
22
|
+
*
|
|
23
|
+
* The input ops may not be canonical, the result is canonical.
|
|
24
|
+
*/
|
|
25
|
+
export declare function canonicalMultiply(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
26
|
+
export declare function mul(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
27
|
+
export declare function mulN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import type { Rational } from '../numerics/
|
|
1
|
+
/* 0.29.0 */
|
|
2
|
+
import type { Rational } from '../numerics/types';
|
|
3
3
|
export declare function asRadical(expr: BoxedExpression): Rational | null;
|
|
4
4
|
export declare function canonicalPower(a: BoxedExpression, b: BoxedExpression): BoxedExpression;
|
|
5
5
|
export declare function canonicalRoot(a: BoxedExpression, b: BoxedExpression | number): BoxedExpression;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.29.0 */
|
|
2
2
|
import { Decimal } from 'decimal.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { SemiBoxedExpression, BoxedExpression, CanonicalOptions, ComputeEngine, Metadata } from '../global-types';
|
|
4
4
|
import { MathJsonIdentifier } from '../../math-json/types';
|
|
5
|
-
import { NumericValue } from '../numeric-value/
|
|
5
|
+
import { NumericValue } from '../numeric-value/types';
|
|
6
6
|
/**
|
|
7
7
|
* Given a name and a set of arguments, return a boxed function expression.
|
|
8
8
|
*
|
|
@@ -10,7 +10,7 @@ import { NumericValue } from '../numeric-value/public';
|
|
|
10
10
|
*
|
|
11
11
|
* Note that `boxFunction()` should only be called from `ce.function()`
|
|
12
12
|
*/
|
|
13
|
-
export declare function boxFunction(ce:
|
|
13
|
+
export declare function boxFunction(ce: ComputeEngine, name: MathJsonIdentifier, ops: readonly SemiBoxedExpression[], options?: {
|
|
14
14
|
metadata?: Metadata;
|
|
15
15
|
canonical?: CanonicalOptions;
|
|
16
16
|
structural?: boolean;
|
|
@@ -40,7 +40,7 @@ export declare function boxFunction(ce: IComputeEngine, name: MathJsonIdentifier
|
|
|
40
40
|
* Note that this function should only be called from `ce.box()`
|
|
41
41
|
*
|
|
42
42
|
*/
|
|
43
|
-
export declare function box(ce:
|
|
43
|
+
export declare function box(ce: ComputeEngine, expr: null | undefined | NumericValue | SemiBoxedExpression, options?: {
|
|
44
44
|
canonical?: CanonicalOptions;
|
|
45
45
|
structural?: boolean;
|
|
46
46
|
}): BoxedExpression;
|