@cortex-js/compute-engine 0.29.1 → 0.30.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 +28319 -24614
- package/dist/compute-engine.min.esm.js +70 -68
- package/dist/compute-engine.min.umd.js +131 -0
- package/dist/{compute-engine.cjs → compute-engine.umd.js} +29615 -25910
- package/dist/math-json.esm.js +22 -294
- package/dist/math-json.min.esm.js +22 -294
- package/dist/math-json.min.umd.js +4 -0
- package/dist/math-json.umd.js +141 -0
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/configuration-change.d.ts +28 -0
- package/dist/types/common/fuzzy-string-match.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +20 -4
- package/dist/types/common/type/parse.d.ts +4 -4
- package/dist/types/common/type/primitive.d.ts +3 -2
- 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 +91 -25
- package/dist/types/common/type/utils.d.ts +2 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -73
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +19 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +6 -6
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +42 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +48 -27
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +17 -5
- package/dist/types/compute-engine/boxed-expression/{boxed-function-definition.d.ts → boxed-operator-definition.d.ts} +12 -12
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -8
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +91 -52
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +22 -25
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
- 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 +2 -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 +30 -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 +2 -2
- 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 +41 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +3 -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 +23 -23
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +2 -1
- package/dist/types/compute-engine/collection-utils.d.ts +22 -57
- package/dist/types/compute-engine/compile.d.ts +61 -10
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +46 -29
- package/dist/types/compute-engine/global-types.d.ts +1432 -893
- package/dist/types/compute-engine/index.d.ts +154 -124
- 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 +3 -3
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -12
- 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 +2 -2
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +51 -39
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
- package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
- package/dist/types/compute-engine/library/calculus.d.ts +2 -2
- package/dist/types/compute-engine/library/collections.d.ts +3 -3
- package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
- package/dist/types/compute-engine/library/complex.d.ts +2 -2
- package/dist/types/compute-engine/library/control-structures.d.ts +2 -2
- package/dist/types/compute-engine/library/core.d.ts +2 -2
- package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +5 -5
- package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -2
- package/dist/types/compute-engine/library/logic.d.ts +2 -2
- package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/sets.d.ts +2 -2
- package/dist/types/compute-engine/library/statistics.d.ts +2 -2
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
- package/dist/types/compute-engine/library/utils.d.ts +24 -2
- 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 -3
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
- package/dist/types/compute-engine/numeric-value/types.d.ts +7 -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 +4 -19
- 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 +9 -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/numerics/types.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
- package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -4
- 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/tensor-fields.d.ts +5 -46
- package/dist/types/compute-engine/tensor/tensors.d.ts +4 -14
- package/dist/types/compute-engine/types.d.ts +1 -4
- package/dist/types/compute-engine.d.ts +1 -1
- package/dist/types/math-json/symbols.d.ts +11 -0
- package/dist/types/math-json/types.d.ts +19 -11
- package/dist/types/math-json/utils.d.ts +18 -9
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +13 -11
- package/dist/compute-engine.min.cjs +0 -129
- package/dist/math-json.cjs +0 -413
- package/dist/math-json.min.cjs +0 -6
- package/dist/types/common/json5.d.ts +0 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +0 -64
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +0 -21
- package/dist/types/math-json/identifiers.d.ts +0 -11
|
@@ -1,275 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 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
|
-
};
|
|
1
|
+
/** Compute Engine 0.30.1 */
|
|
273
2
|
|
|
274
3
|
// src/math-json/utils.ts
|
|
275
4
|
function isSymbolObject(expr) {
|
|
@@ -278,16 +7,20 @@ function isSymbolObject(expr) {
|
|
|
278
7
|
function isStringObject(expr) {
|
|
279
8
|
return expr !== null && typeof expr === "object" && "str" in expr;
|
|
280
9
|
}
|
|
10
|
+
function isDictionaryObject(expr) {
|
|
11
|
+
return expr !== null && typeof expr === "object" && "dict" in expr && typeof expr.dict === "object" && !Array.isArray(expr.dict) && expr.dict !== null;
|
|
12
|
+
}
|
|
281
13
|
function isFunctionObject(expr) {
|
|
282
|
-
return expr !== null && typeof expr === "object" && "fn" in expr;
|
|
14
|
+
return expr !== null && typeof expr === "object" && "fn" in expr && Array.isArray(expr.fn) && expr.fn.length > 0 && typeof expr.fn[0] === "string";
|
|
283
15
|
}
|
|
284
16
|
function stringValue(expr) {
|
|
285
17
|
if (expr === null || expr === void 0) return null;
|
|
286
18
|
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
287
19
|
if (typeof expr !== "string") return null;
|
|
288
|
-
if (expr.length
|
|
289
|
-
|
|
290
|
-
|
|
20
|
+
if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'")
|
|
21
|
+
return expr.substring(1, expr.length - 1);
|
|
22
|
+
if (matchesNumber(expr) || matchesSymbol(expr)) return null;
|
|
23
|
+
return expr;
|
|
291
24
|
}
|
|
292
25
|
function operator(expr) {
|
|
293
26
|
if (Array.isArray(expr)) return expr[0];
|
|
@@ -312,16 +45,14 @@ function nops(expr) {
|
|
|
312
45
|
return 0;
|
|
313
46
|
}
|
|
314
47
|
function symbol(expr) {
|
|
315
|
-
if (typeof expr === "string") {
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
return null;
|
|
48
|
+
if (typeof expr === "string" && matchesSymbol(expr)) {
|
|
49
|
+
if (expr.length >= 2 && expr.at(0) === "`" && expr.at(-1) === "`")
|
|
50
|
+
return expr.slice(1, -1);
|
|
319
51
|
return expr;
|
|
320
52
|
}
|
|
321
53
|
if (expr === null || expr === void 0) return null;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return s;
|
|
54
|
+
if (isSymbolObject(expr)) return expr.sym;
|
|
55
|
+
return null;
|
|
325
56
|
}
|
|
326
57
|
function keyValuePair(expr) {
|
|
327
58
|
const h = operator(expr);
|
|
@@ -335,16 +66,7 @@ function keyValuePair(expr) {
|
|
|
335
66
|
}
|
|
336
67
|
function dictionaryFromExpression(expr) {
|
|
337
68
|
if (expr === null) return null;
|
|
338
|
-
if (
|
|
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
|
-
}
|
|
69
|
+
if (isDictionaryObject(expr)) return expr;
|
|
348
70
|
const kv = keyValuePair(expr);
|
|
349
71
|
if (kv) return { [kv[0]]: kv[1] };
|
|
350
72
|
if (operator(expr) === "Dictionary") {
|
|
@@ -371,9 +93,15 @@ function mapArgs(expr, fn) {
|
|
|
371
93
|
}
|
|
372
94
|
return result;
|
|
373
95
|
}
|
|
96
|
+
function matchesNumber(s) {
|
|
97
|
+
return /^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(s) || /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(s);
|
|
98
|
+
}
|
|
99
|
+
function matchesSymbol(s) {
|
|
100
|
+
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
|
|
101
|
+
}
|
|
374
102
|
|
|
375
103
|
// src/math-json.ts
|
|
376
|
-
var version = "0.
|
|
104
|
+
var version = "0.30.1";
|
|
377
105
|
export {
|
|
378
106
|
dictionaryFromExpression,
|
|
379
107
|
isFunctionObject,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** MathJSON 0.30.1 */
|
|
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 s=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var i in t)s(n,i,{get:t[i],enumerable:!0})},J=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of O(t))!M.call(n,e)&&e!==i&&s(n,e,{get:()=>t[e],enumerable:!(r=j(t,e))||r.enumerable});return n};var A=n=>J(s({},"__esModule",{value:!0}),n);var F={};S(F,{dictionaryFromExpression:()=>E,isFunctionObject:()=>u,isStringObject:()=>y,isSymbolObject:()=>f,mapArgs:()=>h,operand:()=>d,operator:()=>o,stringValue:()=>c,symbol:()=>m,version:()=>k});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 N(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function u(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):p(n)||g(n)?null:n}function o(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function b(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function D(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){return typeof n=="string"&&g(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:f(n)?n.sym:null}function a(n){let t=o(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,r]=b(n),e=c(i);return e?[e,r??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(N(n))return n;let t=a(n);if(t)return{[t[0]]:t[1]};if(o(n)==="Dictionary"){let i={},r=b(n);for(let e=1;e<D(n);e++){let l=a(r[e]);l&&(i[l[0]]=l[1])}return i}return null}function h(n,t){let i=null;if(Array.isArray(n)&&(i=n),u(n)&&(i=n.fn),i===null)return[];let r=1,e=[];for(;r<i.length;)e.push(t(i[r])),r+=1;return e}function p(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function g(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}var k="0.30.1";return A(F);})();
|
|
4
|
+
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** MathJSON 0.30.1 */
|
|
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 = (() => {
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/math-json.ts
|
|
23
|
+
var math_json_exports = {};
|
|
24
|
+
__export(math_json_exports, {
|
|
25
|
+
dictionaryFromExpression: () => dictionaryFromExpression,
|
|
26
|
+
isFunctionObject: () => isFunctionObject,
|
|
27
|
+
isStringObject: () => isStringObject,
|
|
28
|
+
isSymbolObject: () => isSymbolObject,
|
|
29
|
+
mapArgs: () => mapArgs,
|
|
30
|
+
operand: () => operand,
|
|
31
|
+
operator: () => operator,
|
|
32
|
+
stringValue: () => stringValue,
|
|
33
|
+
symbol: () => symbol,
|
|
34
|
+
version: () => version
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/math-json/utils.ts
|
|
38
|
+
function isSymbolObject(expr) {
|
|
39
|
+
return expr !== null && typeof expr === "object" && "sym" in expr;
|
|
40
|
+
}
|
|
41
|
+
function isStringObject(expr) {
|
|
42
|
+
return expr !== null && typeof expr === "object" && "str" in expr;
|
|
43
|
+
}
|
|
44
|
+
function isDictionaryObject(expr) {
|
|
45
|
+
return expr !== null && typeof expr === "object" && "dict" in expr && typeof expr.dict === "object" && !Array.isArray(expr.dict) && expr.dict !== null;
|
|
46
|
+
}
|
|
47
|
+
function isFunctionObject(expr) {
|
|
48
|
+
return expr !== null && typeof expr === "object" && "fn" in expr && Array.isArray(expr.fn) && expr.fn.length > 0 && typeof expr.fn[0] === "string";
|
|
49
|
+
}
|
|
50
|
+
function stringValue(expr) {
|
|
51
|
+
if (expr === null || expr === void 0) return null;
|
|
52
|
+
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
53
|
+
if (typeof expr !== "string") return null;
|
|
54
|
+
if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'")
|
|
55
|
+
return expr.substring(1, expr.length - 1);
|
|
56
|
+
if (matchesNumber(expr) || matchesSymbol(expr)) return null;
|
|
57
|
+
return expr;
|
|
58
|
+
}
|
|
59
|
+
function operator(expr) {
|
|
60
|
+
if (Array.isArray(expr)) return expr[0];
|
|
61
|
+
if (expr === null || expr === void 0) return "";
|
|
62
|
+
if (isFunctionObject(expr)) return expr.fn[0];
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
function operands(expr) {
|
|
66
|
+
if (Array.isArray(expr)) return expr.slice(1);
|
|
67
|
+
if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
function operand(expr, n) {
|
|
71
|
+
if (Array.isArray(expr)) return expr[n] ?? null;
|
|
72
|
+
if (expr === null || !isFunctionObject(expr)) return null;
|
|
73
|
+
return expr.fn[n] ?? null;
|
|
74
|
+
}
|
|
75
|
+
function nops(expr) {
|
|
76
|
+
if (expr === null || expr === void 0) return 0;
|
|
77
|
+
if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
|
|
78
|
+
if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
function symbol(expr) {
|
|
82
|
+
if (typeof expr === "string" && matchesSymbol(expr)) {
|
|
83
|
+
if (expr.length >= 2 && expr.at(0) === "`" && expr.at(-1) === "`")
|
|
84
|
+
return expr.slice(1, -1);
|
|
85
|
+
return expr;
|
|
86
|
+
}
|
|
87
|
+
if (expr === null || expr === void 0) return null;
|
|
88
|
+
if (isSymbolObject(expr)) return expr.sym;
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function keyValuePair(expr) {
|
|
92
|
+
const h = operator(expr);
|
|
93
|
+
if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
|
|
94
|
+
const [k, v] = operands(expr);
|
|
95
|
+
const key = stringValue(k);
|
|
96
|
+
if (!key) return null;
|
|
97
|
+
return [key, v ?? "Nothing"];
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function dictionaryFromExpression(expr) {
|
|
102
|
+
if (expr === null) return null;
|
|
103
|
+
if (isDictionaryObject(expr)) return expr;
|
|
104
|
+
const kv = keyValuePair(expr);
|
|
105
|
+
if (kv) return { [kv[0]]: kv[1] };
|
|
106
|
+
if (operator(expr) === "Dictionary") {
|
|
107
|
+
const result = {};
|
|
108
|
+
const ops = operands(expr);
|
|
109
|
+
for (let i = 1; i < nops(expr); i++) {
|
|
110
|
+
const kv2 = keyValuePair(ops[i]);
|
|
111
|
+
if (kv2) result[kv2[0]] = kv2[1];
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
function mapArgs(expr, fn) {
|
|
118
|
+
let args = null;
|
|
119
|
+
if (Array.isArray(expr)) args = expr;
|
|
120
|
+
if (isFunctionObject(expr)) args = expr.fn;
|
|
121
|
+
if (args === null) return [];
|
|
122
|
+
let i = 1;
|
|
123
|
+
const result = [];
|
|
124
|
+
while (i < args.length) {
|
|
125
|
+
result.push(fn(args[i]));
|
|
126
|
+
i += 1;
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function matchesNumber(s) {
|
|
131
|
+
return /^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(s) || /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(s);
|
|
132
|
+
}
|
|
133
|
+
function matchesSymbol(s) {
|
|
134
|
+
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/math-json.ts
|
|
138
|
+
var version = "0.30.1";
|
|
139
|
+
return __toCommonJS(math_json_exports);
|
|
140
|
+
})();
|
|
141
|
+
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* 0.30.1 */
|
|
2
|
+
private _listeners;
|
|
3
|
+
private _pending;
|
|
4
|
+
private _version;
|
|
5
|
+
/**
|
|
6
|
+
* Registers a listener for configuration changes.
|
|
7
|
+
* Returns a function to unsubscribe the listener.
|
|
8
|
+
* Prevents duplicate subscriptions: if the listener is already registered,
|
|
9
|
+
* returns the existing unsubscribe logic without adding a duplicate.
|
|
10
|
+
*/
|
|
11
|
+
listen(listener: ConfigurationChangeListener): () => void;
|
|
12
|
+
private _unsubscribe;
|
|
13
|
+
/**
|
|
14
|
+
* Notifies all live listeners of a configuration change.
|
|
15
|
+
* Also prunes any dead references from the list.
|
|
16
|
+
* Prevents infinite loops from recursive notify() calls.
|
|
17
|
+
*/
|
|
18
|
+
notify(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Immediately notifies all live listeners of a configuration change.
|
|
21
|
+
* Also prunes any dead references from the list.
|
|
22
|
+
* Increments the version and clears the pending flag.
|
|
23
|
+
*/
|
|
24
|
+
notifyNow(): void;
|
|
25
|
+
}
|
|
26
|
+
export interface ConfigurationChangeListener {
|
|
27
|
+
onConfigurationChange?: () => void;
|
|
28
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.30.1 */
|
|
2
2
|
export declare function fuzzyStringMatch(invalidWord: string, validWords: string[]): string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.30.1 */
|
|
2
2
|
export type RuntimeSignalCode = 'timeout' | 'out-of-memory' | 'recursion-depth-exceeded' | 'iteration-limit-exceeded';
|
|
3
3
|
/** @category Error Handling */
|
|
4
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');
|
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.30.1 */
|
|
2
2
|
/** @category Type */
|
|
3
3
|
export declare class BoxedType {
|
|
4
4
|
static unknown: BoxedType;
|
|
5
|
+
static number: BoxedType;
|
|
6
|
+
static non_finite_number: BoxedType;
|
|
7
|
+
static finite_number: BoxedType;
|
|
8
|
+
static finite_integer: BoxedType;
|
|
9
|
+
static finite_real: BoxedType;
|
|
10
|
+
static string: BoxedType;
|
|
11
|
+
static dictionary: BoxedType;
|
|
12
|
+
static setNumber: BoxedType;
|
|
13
|
+
static setComplex: BoxedType;
|
|
14
|
+
static setImaginary: BoxedType;
|
|
15
|
+
static setReal: BoxedType;
|
|
16
|
+
static setRational: BoxedType;
|
|
17
|
+
static setFiniteInteger: BoxedType;
|
|
18
|
+
static setInteger: BoxedType;
|
|
5
19
|
type: Type;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
20
|
+
static widen(...types: ReadonlyArray<BoxedType | Type>): BoxedType;
|
|
21
|
+
static narrow(...types: ReadonlyArray<BoxedType | Type>): BoxedType;
|
|
22
|
+
constructor(type: Type | TypeString, typeResolver?: TypeResolver);
|
|
23
|
+
matches(other: Type | BoxedType): boolean;
|
|
24
|
+
is(other: Type): boolean;
|
|
9
25
|
get isUnknown(): boolean;
|
|
10
26
|
toString(): string;
|
|
11
27
|
toJSON(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare function parseType(s: undefined): undefined;
|
|
3
|
-
export declare function parseType(s:
|
|
4
|
-
export declare function parseType(s:
|
|
1
|
+
/* 0.30.1 */
|
|
2
|
+
export declare function parseType(s: undefined, typeResolver?: TypeResolver): undefined;
|
|
3
|
+
export declare function parseType(s: TypeString | Type, typeResolver?: TypeResolver): Type;
|
|
4
|
+
export declare function parseType(s: TypeString | Type | undefined, typeResolver?: TypeResolver): Type | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.30.1 */
|
|
2
2
|
/** All the types representing numeric values */
|
|
3
|
-
export declare const NUMERIC_TYPES:
|
|
3
|
+
export declare const NUMERIC_TYPES: NumericPrimitiveType[];
|
|
4
|
+
export declare const INDEXED_COLLECTION_TYPES: PrimitiveType[];
|
|
4
5
|
export declare const COLLECTION_TYPES: PrimitiveType[];
|
|
5
6
|
export declare const SCALAR_TYPES: PrimitiveType[];
|
|
6
7
|
export declare const VALUE_TYPES: PrimitiveType[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.30.1 */
|
|
2
2
|
export declare function typeToString(type: Type, precedence?: number): string;
|