@cortex-js/compute-engine 0.27.0 → 0.28.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.esm.js +2055 -964
- package/dist/compute-engine.js +2055 -964
- package/dist/compute-engine.min.esm.js +54 -51
- package/dist/compute-engine.min.js +54 -51
- package/dist/math-json.esm.js +287 -7
- package/dist/math-json.js +287 -7
- package/dist/math-json.min.esm.js +287 -7
- package/dist/math-json.min.js +4 -2
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/buffer.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 +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/styled-text.d.ts +1 -1
- package/dist/types/common/syntax-highlighter.d.ts +1 -1
- package/dist/types/common/terminal.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +13 -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 +39 -49
- 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 +10 -8
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +10 -3
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +11 -7
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +5 -4
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +6 -5
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +3 -3
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/public.d.ts +64 -54
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- 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 -1
- package/dist/types/compute-engine/boxed-expression/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +2 -2
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +25 -12
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/debug.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-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 +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +11 -6
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/public.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bignum.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 +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/private.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +1 -1
- 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/tensor/tensors.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +3 -2
- package/dist/types/math-json/identifiers.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +6 -6
- package/dist/types/math-json/utils.d.ts +3 -3
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +3 -3
- package/dist/types/common/suggest.d.ts +0 -1
|
@@ -1,4 +1,275 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
1
|
+
/** Compute Engine 0.28.0 */
|
|
2
|
+
|
|
3
|
+
// src/common/json5.ts
|
|
4
|
+
var JSON5 = class {
|
|
5
|
+
static parse(input) {
|
|
6
|
+
const parser = new JSON5Parser(input);
|
|
7
|
+
const value = parser.parseValue();
|
|
8
|
+
parser.skipWhitespace();
|
|
9
|
+
if (!parser.isAtEnd()) {
|
|
10
|
+
throw parser.error(
|
|
11
|
+
`Unexpected token '${parser.currentChar()}' after parsing complete value`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var JSON5Parser = class {
|
|
18
|
+
constructor(input) {
|
|
19
|
+
this.index = 0;
|
|
20
|
+
this.text = input;
|
|
21
|
+
}
|
|
22
|
+
parseValue() {
|
|
23
|
+
this.skipWhitespace();
|
|
24
|
+
if (this.isAtEnd()) {
|
|
25
|
+
throw this.error("Unexpected end of input");
|
|
26
|
+
}
|
|
27
|
+
const ch = this.currentChar();
|
|
28
|
+
if (ch === "{") return this.parseObject();
|
|
29
|
+
if (ch === "[") return this.parseArray();
|
|
30
|
+
if (ch === '"' || ch === "'") return this.parseString();
|
|
31
|
+
if (ch === "-" || ch === "+" || ch >= "0" && ch <= "9" || ch === ".")
|
|
32
|
+
return this.parseNumber();
|
|
33
|
+
return this.parseIdentifier();
|
|
34
|
+
}
|
|
35
|
+
parseObject() {
|
|
36
|
+
const obj = {};
|
|
37
|
+
this.expectChar("{");
|
|
38
|
+
this.skipWhitespace();
|
|
39
|
+
if (this.currentChar() === "}") {
|
|
40
|
+
this.index++;
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
while (true) {
|
|
44
|
+
this.skipWhitespace();
|
|
45
|
+
let key;
|
|
46
|
+
const ch = this.currentChar();
|
|
47
|
+
if (ch === '"' || ch === "'") {
|
|
48
|
+
key = this.parseString();
|
|
49
|
+
} else {
|
|
50
|
+
key = this.parseIdentifier();
|
|
51
|
+
}
|
|
52
|
+
this.skipWhitespace();
|
|
53
|
+
this.expectChar(":");
|
|
54
|
+
this.skipWhitespace();
|
|
55
|
+
const value = this.parseValue();
|
|
56
|
+
obj[key] = value;
|
|
57
|
+
this.skipWhitespace();
|
|
58
|
+
if (this.currentChar() === ",") {
|
|
59
|
+
this.index++;
|
|
60
|
+
this.skipWhitespace();
|
|
61
|
+
if (this.currentChar() === "}") {
|
|
62
|
+
this.index++;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
} else if (this.currentChar() === "}") {
|
|
66
|
+
this.index++;
|
|
67
|
+
break;
|
|
68
|
+
} else {
|
|
69
|
+
throw this.error(
|
|
70
|
+
`Expected ',' or '}' in object but found '${this.currentChar()}'`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
parseArray() {
|
|
77
|
+
const arr = [];
|
|
78
|
+
this.expectChar("[");
|
|
79
|
+
this.skipWhitespace();
|
|
80
|
+
if (this.currentChar() === "]") {
|
|
81
|
+
this.index++;
|
|
82
|
+
return arr;
|
|
83
|
+
}
|
|
84
|
+
while (true) {
|
|
85
|
+
this.skipWhitespace();
|
|
86
|
+
arr.push(this.parseValue());
|
|
87
|
+
this.skipWhitespace();
|
|
88
|
+
if (this.currentChar() === ",") {
|
|
89
|
+
this.index++;
|
|
90
|
+
this.skipWhitespace();
|
|
91
|
+
if (this.currentChar() === "]") {
|
|
92
|
+
this.index++;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
} else if (this.currentChar() === "]") {
|
|
96
|
+
this.index++;
|
|
97
|
+
break;
|
|
98
|
+
} else {
|
|
99
|
+
throw this.error(
|
|
100
|
+
`Expected ',' or ']' in array but found '${this.currentChar()}'`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return arr;
|
|
105
|
+
}
|
|
106
|
+
parseString() {
|
|
107
|
+
const quote = this.currentChar();
|
|
108
|
+
if (quote !== '"' && quote !== "'") {
|
|
109
|
+
throw this.error(`String should start with a quote, got '${quote}'`);
|
|
110
|
+
}
|
|
111
|
+
this.index++;
|
|
112
|
+
let result = "";
|
|
113
|
+
while (!this.isAtEnd()) {
|
|
114
|
+
const ch = this.currentChar();
|
|
115
|
+
if (ch === quote) {
|
|
116
|
+
this.index++;
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
if (ch === "\\") {
|
|
120
|
+
this.index++;
|
|
121
|
+
if (this.isAtEnd()) {
|
|
122
|
+
throw this.error("Unterminated escape sequence in string");
|
|
123
|
+
}
|
|
124
|
+
const esc = this.currentChar();
|
|
125
|
+
switch (esc) {
|
|
126
|
+
case "b":
|
|
127
|
+
result += "\b";
|
|
128
|
+
break;
|
|
129
|
+
case "f":
|
|
130
|
+
result += "\f";
|
|
131
|
+
break;
|
|
132
|
+
case "n":
|
|
133
|
+
result += "\n";
|
|
134
|
+
break;
|
|
135
|
+
case "r":
|
|
136
|
+
result += "\r";
|
|
137
|
+
break;
|
|
138
|
+
case "t":
|
|
139
|
+
result += " ";
|
|
140
|
+
break;
|
|
141
|
+
case "v":
|
|
142
|
+
result += "\v";
|
|
143
|
+
break;
|
|
144
|
+
case "\\":
|
|
145
|
+
result += "\\";
|
|
146
|
+
break;
|
|
147
|
+
case "'":
|
|
148
|
+
result += "'";
|
|
149
|
+
break;
|
|
150
|
+
case '"':
|
|
151
|
+
result += '"';
|
|
152
|
+
break;
|
|
153
|
+
case "0":
|
|
154
|
+
result += "\0";
|
|
155
|
+
break;
|
|
156
|
+
case "u": {
|
|
157
|
+
this.index++;
|
|
158
|
+
const hex = this.text.substr(this.index, 4);
|
|
159
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
160
|
+
throw this.error(`Invalid Unicode escape sequence: \\u${hex}`);
|
|
161
|
+
}
|
|
162
|
+
result += String.fromCharCode(parseInt(hex, 16));
|
|
163
|
+
this.index += 3;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
default:
|
|
167
|
+
result += esc;
|
|
168
|
+
}
|
|
169
|
+
this.index++;
|
|
170
|
+
} else {
|
|
171
|
+
result += ch;
|
|
172
|
+
this.index++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
throw this.error("Unterminated string literal");
|
|
176
|
+
}
|
|
177
|
+
parseNumber() {
|
|
178
|
+
const start = this.index;
|
|
179
|
+
if (this.text.startsWith("-Infinity", this.index)) {
|
|
180
|
+
this.index += "-Infinity".length;
|
|
181
|
+
return -Infinity;
|
|
182
|
+
}
|
|
183
|
+
if (this.text.startsWith("+Infinity", this.index)) {
|
|
184
|
+
this.index += "+Infinity".length;
|
|
185
|
+
return Infinity;
|
|
186
|
+
}
|
|
187
|
+
if (this.text.startsWith("Infinity", this.index)) {
|
|
188
|
+
this.index += "Infinity".length;
|
|
189
|
+
return Infinity;
|
|
190
|
+
}
|
|
191
|
+
while (!this.isAtEnd() && /[0-9+\-_.eE]/.test(this.currentChar())) {
|
|
192
|
+
this.index++;
|
|
193
|
+
}
|
|
194
|
+
const token = this.text.slice(start, this.index);
|
|
195
|
+
const normalized = token.replace(/_/g, "");
|
|
196
|
+
const num = Number(normalized);
|
|
197
|
+
if (isNaN(num)) {
|
|
198
|
+
throw this.error(`Invalid number: ${token}`);
|
|
199
|
+
}
|
|
200
|
+
return num;
|
|
201
|
+
}
|
|
202
|
+
parseIdentifier() {
|
|
203
|
+
const start = this.index;
|
|
204
|
+
const firstChar = this.currentChar();
|
|
205
|
+
if (!/[a-zA-Z$_]/.test(firstChar)) {
|
|
206
|
+
throw this.error(`Unexpected token '${firstChar}'`);
|
|
207
|
+
}
|
|
208
|
+
this.index++;
|
|
209
|
+
while (!this.isAtEnd()) {
|
|
210
|
+
const ch = this.currentChar();
|
|
211
|
+
if (!/[a-zA-Z0-9$_]/.test(ch)) break;
|
|
212
|
+
this.index++;
|
|
213
|
+
}
|
|
214
|
+
const token = this.text.slice(start, this.index);
|
|
215
|
+
if (token === "true") return true;
|
|
216
|
+
if (token === "false") return false;
|
|
217
|
+
if (token === "null") return null;
|
|
218
|
+
if (token === "Infinity") return Infinity;
|
|
219
|
+
if (token === "NaN") return NaN;
|
|
220
|
+
return token;
|
|
221
|
+
}
|
|
222
|
+
skipWhitespace() {
|
|
223
|
+
while (!this.isAtEnd()) {
|
|
224
|
+
const ch = this.currentChar();
|
|
225
|
+
if (/\s/.test(ch)) {
|
|
226
|
+
this.index++;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (ch === "/") {
|
|
230
|
+
const next = this.peekChar(1);
|
|
231
|
+
if (next === "/") {
|
|
232
|
+
this.index += 2;
|
|
233
|
+
while (!this.isAtEnd() && this.currentChar() !== "\n") {
|
|
234
|
+
this.index++;
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
} else if (next === "*") {
|
|
238
|
+
this.index += 2;
|
|
239
|
+
while (!this.isAtEnd() && !(this.currentChar() === "*" && this.peekChar(1) === "/")) {
|
|
240
|
+
this.index++;
|
|
241
|
+
}
|
|
242
|
+
if (this.isAtEnd()) {
|
|
243
|
+
throw this.error("Unterminated multi-line comment");
|
|
244
|
+
}
|
|
245
|
+
this.index += 2;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
expectChar(expected) {
|
|
253
|
+
if (this.currentChar() !== expected) {
|
|
254
|
+
throw this.error(
|
|
255
|
+
`Expected '${expected}' but found '${this.currentChar()}'`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
this.index++;
|
|
259
|
+
}
|
|
260
|
+
currentChar() {
|
|
261
|
+
return this.text[this.index];
|
|
262
|
+
}
|
|
263
|
+
peekChar(offset) {
|
|
264
|
+
return this.text[this.index + offset];
|
|
265
|
+
}
|
|
266
|
+
isAtEnd() {
|
|
267
|
+
return this.index >= this.text.length;
|
|
268
|
+
}
|
|
269
|
+
error(message) {
|
|
270
|
+
return new Error(`${message} at position ${this.index}`);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
2
273
|
|
|
3
274
|
// src/math-json/utils.ts
|
|
4
275
|
function isSymbolObject(expr) {
|
|
@@ -62,12 +333,21 @@ function keyValuePair(expr) {
|
|
|
62
333
|
}
|
|
63
334
|
return null;
|
|
64
335
|
}
|
|
65
|
-
function
|
|
336
|
+
function dictionaryFromExpression(expr) {
|
|
66
337
|
if (expr === null) return null;
|
|
338
|
+
if (typeof expr === "object" && !("sym" in expr) && !("num" in expr) && !("str" in expr) && !("fn" in expr)) {
|
|
339
|
+
return expr;
|
|
340
|
+
}
|
|
341
|
+
if (typeof expr === "string" && expr[0] === "{" && expr[expr.length - 1] === "}") {
|
|
342
|
+
try {
|
|
343
|
+
return JSON5.parse(expr);
|
|
344
|
+
} catch {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
67
348
|
const kv = keyValuePair(expr);
|
|
68
349
|
if (kv) return { [kv[0]]: kv[1] };
|
|
69
|
-
|
|
70
|
-
if (h === "Dictionary") {
|
|
350
|
+
if (operator(expr) === "Dictionary") {
|
|
71
351
|
const result = {};
|
|
72
352
|
const ops = operands(expr);
|
|
73
353
|
for (let i = 1; i < nops(expr); i++) {
|
|
@@ -93,16 +373,16 @@ function mapArgs(expr, fn) {
|
|
|
93
373
|
}
|
|
94
374
|
|
|
95
375
|
// src/math-json.ts
|
|
96
|
-
var version = "0.
|
|
376
|
+
var version = "0.28.0";
|
|
97
377
|
export {
|
|
98
|
-
|
|
99
|
-
stringValue as getStringValue,
|
|
378
|
+
dictionaryFromExpression,
|
|
100
379
|
isFunctionObject,
|
|
101
380
|
isStringObject,
|
|
102
381
|
isSymbolObject,
|
|
103
382
|
mapArgs,
|
|
104
383
|
operand,
|
|
105
384
|
operator,
|
|
385
|
+
stringValue,
|
|
106
386
|
symbol,
|
|
107
387
|
version
|
|
108
388
|
};
|
package/dist/math-json.min.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/** MathJSON 0.
|
|
1
|
+
/** MathJSON 0.28.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
|
|
3
|
-
var MathJson=(()=>{var
|
|
3
|
+
var MathJson=(()=>{var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var i in t)a(n,i,{get:t[i],enumerable:!0})},w=(n,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!x.call(n,r)&&r!==i&&a(n,r,{get:()=>t[r],enumerable:!(e=k(t,r))||e.enumerable});return n};var I=n=>w(a({},"__esModule",{value:!0}),n);var S={};A(S,{dictionaryFromExpression:()=>g,isFunctionObject:()=>u,isStringObject:()=>y,isSymbolObject:()=>f,mapArgs:()=>E,operand:()=>b,operator:()=>l,stringValue:()=>c,symbol:()=>m,version:()=>v});var o=class{static parse(t){let i=new h(t),e=i.parseValue();if(i.skipWhitespace(),!i.isAtEnd())throw i.error(`Unexpected token '${i.currentChar()}' after parsing complete value`);return e}},h=class{constructor(t){this.index=0;this.text=t}parseValue(){if(this.skipWhitespace(),this.isAtEnd())throw this.error("Unexpected end of input");let t=this.currentChar();return t==="{"?this.parseObject():t==="["?this.parseArray():t==='"'||t==="'"?this.parseString():t==="-"||t==="+"||t>="0"&&t<="9"||t==="."?this.parseNumber():this.parseIdentifier()}parseObject(){let t={};if(this.expectChar("{"),this.skipWhitespace(),this.currentChar()==="}")return this.index++,t;for(;;){this.skipWhitespace();let i,e=this.currentChar();e==='"'||e==="'"?i=this.parseString():i=this.parseIdentifier(),this.skipWhitespace(),this.expectChar(":"),this.skipWhitespace();let r=this.parseValue();if(t[i]=r,this.skipWhitespace(),this.currentChar()===","){if(this.index++,this.skipWhitespace(),this.currentChar()==="}"){this.index++;break}}else if(this.currentChar()==="}"){this.index++;break}else throw this.error(`Expected ',' or '}' in object but found '${this.currentChar()}'`)}return t}parseArray(){let t=[];if(this.expectChar("["),this.skipWhitespace(),this.currentChar()==="]")return this.index++,t;for(;;)if(this.skipWhitespace(),t.push(this.parseValue()),this.skipWhitespace(),this.currentChar()===","){if(this.index++,this.skipWhitespace(),this.currentChar()==="]"){this.index++;break}}else if(this.currentChar()==="]"){this.index++;break}else throw this.error(`Expected ',' or ']' in array but found '${this.currentChar()}'`);return t}parseString(){let t=this.currentChar();if(t!=='"'&&t!=="'")throw this.error(`String should start with a quote, got '${t}'`);this.index++;let i="";for(;!this.isAtEnd();){let e=this.currentChar();if(e===t)return this.index++,i;if(e==="\\"){if(this.index++,this.isAtEnd())throw this.error("Unterminated escape sequence in string");let r=this.currentChar();switch(r){case"b":i+="\b";break;case"f":i+="\f";break;case"n":i+=`
|
|
4
|
+
`;break;case"r":i+="\r";break;case"t":i+=" ";break;case"v":i+="\v";break;case"\\":i+="\\";break;case"'":i+="'";break;case'"':i+='"';break;case"0":i+="\0";break;case"u":{this.index++;let s=this.text.substr(this.index,4);if(!/^[0-9a-fA-F]{4}$/.test(s))throw this.error(`Invalid Unicode escape sequence: \\u${s}`);i+=String.fromCharCode(parseInt(s,16)),this.index+=3;break}default:i+=r}this.index++}else i+=e,this.index++}throw this.error("Unterminated string literal")}parseNumber(){let t=this.index;if(this.text.startsWith("-Infinity",this.index))return this.index+=9,-1/0;if(this.text.startsWith("+Infinity",this.index))return this.index+=9,1/0;if(this.text.startsWith("Infinity",this.index))return this.index+=8,1/0;for(;!this.isAtEnd()&&/[0-9+\-_.eE]/.test(this.currentChar());)this.index++;let i=this.text.slice(t,this.index),e=i.replace(/_/g,""),r=Number(e);if(isNaN(r))throw this.error(`Invalid number: ${i}`);return r}parseIdentifier(){let t=this.index,i=this.currentChar();if(!/[a-zA-Z$_]/.test(i))throw this.error(`Unexpected token '${i}'`);for(this.index++;!this.isAtEnd();){let r=this.currentChar();if(!/[a-zA-Z0-9$_]/.test(r))break;this.index++}let e=this.text.slice(t,this.index);return e==="true"?!0:e==="false"?!1:e==="null"?null:e==="Infinity"?1/0:e==="NaN"?NaN:e}skipWhitespace(){for(;!this.isAtEnd();){let t=this.currentChar();if(/\s/.test(t)){this.index++;continue}if(t==="/"){let i=this.peekChar(1);if(i==="/"){for(this.index+=2;!this.isAtEnd()&&this.currentChar()!==`
|
|
5
|
+
`;)this.index++;continue}else if(i==="*"){for(this.index+=2;!this.isAtEnd()&&!(this.currentChar()==="*"&&this.peekChar(1)==="/");)this.index++;if(this.isAtEnd())throw this.error("Unterminated multi-line comment");this.index+=2;continue}}break}}expectChar(t){if(this.currentChar()!==t)throw this.error(`Expected '${t}' but found '${this.currentChar()}'`);this.index++}currentChar(){return this.text[this.index]}peekChar(t){return this.text[this.index+t]}isAtEnd(){return this.index>=this.text.length}error(t){return new Error(`${t} at position ${this.index}`)}};function f(n){return n!==null&&typeof n=="object"&&"sym"in n}function y(n){return n!==null&&typeof n=="object"&&"str"in n}function u(n){return n!==null&&typeof n=="object"&&"fn"in n}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"||n.length<2||n.at(0)!=="'"||n.at(-1)!=="'"?null:n.substring(1,n.length-1)}function l(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function p(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function b(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function N(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):u(n)?Math.max(0,n.fn.length-1):0}function m(n){if(typeof n=="string")return/^[+-]?[0-9\.]/.test(n)||n.length>=2&&n[0]==="'"&&n[n.length-1]==="'"?null:n;if(n==null)return null;let t=f(n)?n.sym:n;return typeof t!="string"?null:t}function d(n){let t=l(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,e]=p(n),r=c(i);return r?[r,e??"Nothing"]:null}return null}function g(n){if(n===null)return null;if(typeof n=="object"&&!("sym"in n)&&!("num"in n)&&!("str"in n)&&!("fn"in n))return n;if(typeof n=="string"&&n[0]==="{"&&n[n.length-1]==="}")try{return o.parse(n)}catch{return null}let t=d(n);if(t)return{[t[0]]:t[1]};if(l(n)==="Dictionary"){let i={},e=p(n);for(let r=1;r<N(n);r++){let s=d(e[r]);s&&(i[s[0]]=s[1])}return i}return null}function E(n,t){let i=null;if(Array.isArray(n)&&(i=n),u(n)&&(i=n.fn),i===null)return[];let e=1,r=[];for(;e<i.length;)r.push(t(i[e])),e+=1;return r}var v="0.28.0";return I(S);})();
|
|
4
6
|
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.28.0 */
|
|
2
2
|
cause: unknown;
|
|
3
3
|
value: T;
|
|
4
4
|
constructor({ message, value, cause, }?: {
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
* @returns The final value produced by the generator.
|
|
17
17
|
* @throws CancellationError if the operation is canceled or times out.
|
|
18
18
|
*/
|
|
19
|
-
export declare function runAsync<T>(gen: Generator<T>, timeLimitMs: number, signal
|
|
19
|
+
export declare function runAsync<T>(gen: Generator<T>, timeLimitMs: number, signal?: AbortSignal): Promise<T>;
|
|
20
20
|
export declare function run<T>(gen: Generator<T>, timeLimitMs: number): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* 0.28.0 */
|
|
2
|
+
export declare class BoxedType {
|
|
3
|
+
static unknown: BoxedType;
|
|
4
|
+
type: Type;
|
|
5
|
+
constructor(type: Type | TypeString);
|
|
6
|
+
matches(other: Type | TypeString | BoxedType): boolean;
|
|
7
|
+
is(other: Type | TypeString): boolean;
|
|
8
|
+
get isUnknown(): boolean;
|
|
9
|
+
toString(): string;
|
|
10
|
+
toJSON(): string;
|
|
11
|
+
[Symbol.toPrimitive](hint: string): string | null;
|
|
12
|
+
valueOf(): string;
|
|
13
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.28.0 */
|
|
2
2
|
export declare function typeToString(type: Type, precedence?: number): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.28.0 */
|
|
2
2
|
* A primitive type is a simple type that represents a concrete value.
|
|
3
3
|
*
|
|
4
4
|
* - `any`: the top type
|
|
@@ -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
|
*
|
|
@@ -130,7 +132,7 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
130
132
|
* Types are described using the following BNF grammar:
|
|
131
133
|
|
|
132
134
|
```bnf
|
|
133
|
-
<type> ::= <union_type>
|
|
135
|
+
<type> ::= <union_type> | "(" <type> ")"
|
|
134
136
|
|
|
135
137
|
<union_type> ::= <intersection_type> (" | " <intersection_type>)*
|
|
136
138
|
|
|
@@ -138,12 +140,8 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
138
140
|
|
|
139
141
|
<primary_type> ::= <primitive>
|
|
140
142
|
| <tuple_type>
|
|
141
|
-
| <
|
|
143
|
+
| <signature>
|
|
142
144
|
| <list_type>
|
|
143
|
-
| <wrapped_primary_type>
|
|
144
|
-
|
|
145
|
-
<wrapped_primary_type> ::= "(" <primary_type> ")"
|
|
146
|
-
|
|
147
145
|
|
|
148
146
|
<primitive> ::= "any" | "unknown" | <value-type> | <symbolic-type> | <numeric-type>
|
|
149
147
|
|
|
@@ -153,9 +151,9 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
153
151
|
|
|
154
152
|
<symbolic-type> ::= "expression" | "function" | "symbol"
|
|
155
153
|
|
|
156
|
-
<tuple_type> ::= "
|
|
157
|
-
| "
|
|
158
|
-
| "tuple
|
|
154
|
+
<tuple_type> ::= "tuple<" (<name> <type> "," <named_tuple_elements>*) ">"
|
|
155
|
+
| "tuple<" (<type> "," <unnamed_tuple_elements>*) ">" |
|
|
156
|
+
| "tuple<" <tuple_elements> ">"
|
|
159
157
|
|
|
160
158
|
<tuple_elements> ::= <unnamed_tuple_elements> | <named_tuple_elements>
|
|
161
159
|
|
|
@@ -163,15 +161,11 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
163
161
|
|
|
164
162
|
<named_tuple_elements> ::= <name> <type> ("," <name> <type>)*
|
|
165
163
|
|
|
166
|
-
<
|
|
164
|
+
<signature> ::= <arguments> " -> " <type>
|
|
167
165
|
|
|
168
166
|
<arguments> ::= "()"
|
|
169
167
|
| <argument>
|
|
170
168
|
| "(" <argument-list> ")"
|
|
171
|
-
| <deferred_evaluation>
|
|
172
|
-
|
|
173
|
-
<deferred_evaluation> ::= "???" <argument>
|
|
174
|
-
| "???" "(" <argument-list> ")"
|
|
175
169
|
|
|
176
170
|
<argument> ::= <type>
|
|
177
171
|
| <name> <type>
|
|
@@ -191,7 +185,7 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
191
185
|
| <rest_argument>
|
|
192
186
|
|
|
193
187
|
|
|
194
|
-
<list_type> ::= "
|
|
188
|
+
<list_type> ::= "list<" <type> <dimensions>? ">"
|
|
195
189
|
|
|
196
190
|
<dimensions> ::= "^" <fixed_size>
|
|
197
191
|
| "^(" <multi_dimensional_size> ")"
|
|
@@ -200,9 +194,7 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
200
194
|
|
|
201
195
|
<multi_dimensional_size> ::= <positive-integer_literal> "x" <positive-integer_literal> ("x" <positive-integer_literal>)*
|
|
202
196
|
|
|
203
|
-
<map> ::= "
|
|
204
|
-
|"{" <map_elements> "}"
|
|
205
|
-
| "map(" <map_elements> ")"
|
|
197
|
+
<map> ::= "map" | "map<" <map_elements> ">"
|
|
206
198
|
|
|
207
199
|
<map_elements> ::= <name> <type> ("," <name> <type>)*
|
|
208
200
|
|
|
@@ -218,31 +210,29 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
|
|
|
218
210
|
```
|
|
219
211
|
|
|
220
212
|
|
|
221
|
-
Examples of types:
|
|
213
|
+
Examples of types strings:
|
|
222
214
|
"number" -- a simple type primitive
|
|
223
|
-
|
|
224
|
-
|
|
225
215
|
"(number, boolean)" -- a tuple type
|
|
226
216
|
"(x: number, y:boolean)" -- a named tuple/record type. Either all arguments are named, or none are
|
|
227
217
|
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
218
|
+
"collection<any>" -- an arbitrary collection type, with no length or element type restrictions
|
|
219
|
+
"collection<integer>" -- a collection type where all the elements are integers
|
|
220
|
+
"collection<(number, boolean)>" -- a collection of tuples
|
|
221
|
+
"collection<(value:number, seen:boolean)>" -- a collection of named tuples
|
|
232
222
|
"[boolean]^32" -- a collection type with a fixed size of 32 elements
|
|
233
223
|
"[integer]^(2x3)" -- an integer matrix of 2 columns and 3 rows
|
|
234
224
|
"[integer]^(2x3x4)" -- a tensor of dimensions 2x3x4
|
|
235
225
|
|
|
236
|
-
"number -> number" -- a
|
|
237
|
-
"(x: number, number) -> number" -- a
|
|
238
|
-
"(number, y:number?) -> number" -- a
|
|
239
|
-
"(number, ...number) -> number" -- a
|
|
240
|
-
"() -> number" -- a
|
|
226
|
+
"number -> number" -- a signature with a single argument
|
|
227
|
+
"(x: number, number) -> number" -- a signature with a named argument
|
|
228
|
+
"(number, y:number?) -> number" -- a signature with an optional named argument (can have several optional arguments, at the end)
|
|
229
|
+
"(number, ...number) -> number" -- a signature with a rest argument (can have only one, and no optional arguments if there is a rest argument).
|
|
230
|
+
"() -> number" -- a signature with an empty argument list
|
|
241
231
|
|
|
242
232
|
"number | boolean" -- a union type
|
|
243
233
|
"(x: number) & (y: number)" -- an intersection type
|
|
244
234
|
"number | ((x: number) & (y: number))" -- a union type with an intersection type
|
|
245
|
-
"(number -> number) | number" -- a union type with a
|
|
235
|
+
"(number -> number) | number" -- a union type with a signature and a primitive type
|
|
246
236
|
*/
|
|
247
237
|
export type TypeString = string;
|
|
248
238
|
export type TypeCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|