@cortex-js/compute-engine 0.12.3 → 0.12.4

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.
Files changed (89) hide show
  1. package/dist/compute-engine.esm.js +24348 -28195
  2. package/dist/compute-engine.js +24523 -0
  3. package/dist/compute-engine.min.esm.js +24506 -2
  4. package/dist/compute-engine.min.js +24519 -2
  5. package/dist/math-json.esm.js +256 -185
  6. package/dist/math-json.js +283 -0
  7. package/dist/math-json.min.esm.js +258 -2
  8. package/dist/math-json.min.js +283 -2
  9. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  10. package/dist/types/common/signals.d.ts +1 -1
  11. package/dist/types/common/utils.d.ts +1 -1
  12. package/dist/types/compute-engine/assume.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -2
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +3 -2
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +2 -2
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  29. package/dist/types/compute-engine/compute-engine.d.ts +1 -2
  30. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  31. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +25 -16
  43. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +15 -0
  45. package/dist/types/compute-engine/latex-syntax/parse.d.ts +28 -33
  46. package/dist/types/compute-engine/latex-syntax/public.d.ts +62 -65
  47. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +10 -6
  50. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -1
  51. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  53. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +2 -2
  54. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  55. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  56. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  57. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  58. package/dist/types/compute-engine/library/core.d.ts +1 -1
  59. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  60. package/dist/types/compute-engine/library/library.d.ts +1 -1
  61. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  62. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  63. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  64. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  65. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  66. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  71. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  72. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  73. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  74. package/dist/types/compute-engine/public.d.ts +13 -6
  75. package/dist/types/compute-engine/rules.d.ts +1 -1
  76. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  77. package/dist/types/compute-engine/solve.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/expand.d.ts +18 -10
  79. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  82. package/dist/types/compute-engine/symbolic/product.d.ts +4 -1
  83. package/dist/types/compute-engine/symbolic/sum.d.ts +2 -1
  84. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  85. package/dist/types/compute-engine.d.ts +2 -2
  86. package/dist/types/math-json/math-json-format.d.ts +1 -1
  87. package/dist/types/math-json/utils.d.ts +4 -1
  88. package/dist/types/math-json.d.ts +2 -2
  89. package/package.json +5 -14
@@ -1,187 +1,258 @@
1
- /** MathJSON 0.12.3 */
2
- function isSymbolObject(expr) {
3
- return expr !== null && typeof expr === 'object' && 'sym' in expr;
4
- }
5
- function isStringObject(expr) {
6
- return expr !== null && typeof expr === 'object' && 'str' in expr;
7
- }
8
- function isFunctionObject(expr) {
9
- return expr !== null && typeof expr === 'object' && 'fn' in expr;
10
- }
11
- function isDictionaryObject(expr) {
12
- return expr !== null && typeof expr === 'object' && 'dict' in expr;
13
- }
14
- function isValidIdentifier(s) {
15
- // An identifier must not contain any of these characters
16
- if (/[\u0000-\u0020\u0022\u0060\ufffe\uffff]/.test(s))
17
- return false;
18
- // A symbol name must not start with one these characters
19
- return !/^[\u0021\u0022\u0024-\u0029\u002e\u003a\u003f\u0040\u005b\u005d\u005e\u007b\u007d\u007e\+\-[0-9]]/.test(s);
20
- }
21
- /** If expr is a string literal, return it.
22
- *
23
- * A string literal is a JSON string that begins and ends with
24
- * **U+0027 APOSTROPHE** : **`'`** or an object literal with a `str` key.
25
- */
26
- function stringValue(expr) {
27
- if (expr === null || expr === undefined)
28
- return null;
29
- if (typeof expr === 'object' && 'str' in expr)
30
- return expr.str;
31
- if (typeof expr !== 'string')
32
- return null;
33
- if (expr.length < 2)
34
- return null;
35
- if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
36
- return null;
37
- return expr.substring(1, expr.length - 1);
38
- }
39
- /**
40
- * The head of a function can be an identifier or an expression.
41
- *
42
- * Return `null` if the expression is not a function.
43
- *
44
- * Examples:
45
- * * `["Negate", 5]` -> `"Negate"`
46
- * * `[["Prime", "f"], "x"]` -> `["Prime", "f"]`
47
- */
48
- function head(expr) {
49
- if (expr === null || expr === undefined)
50
- return null;
51
- if (Array.isArray(expr)) {
52
- console.assert(expr.length > 0 &&
53
- (typeof expr[0] !== 'string' || isValidIdentifier(expr[0])));
54
- return expr[0];
55
- }
56
- if (isFunctionObject(expr))
57
- return expr.fn[0];
58
- return null;
59
- }
60
- /** Return the head of an expression, only if it's a string */
61
- function headName(expr) {
62
- const h = head(expr);
63
- return typeof h === 'string' ? h : '';
64
- }
65
- /**
66
- * Return all the elements but the first one, i.e. the arguments of a
67
- * function.
68
- */
69
- function ops(expr) {
70
- if (expr === null || expr === undefined)
71
- return null;
72
- if (Array.isArray(expr))
73
- return expr.slice(1);
74
- if (isFunctionObject(expr))
75
- return expr.fn.slice(1);
76
- return null;
77
- }
78
- /** Return the nth argument of a function expression */
79
- function op(expr, n) {
80
- if (expr === null || expr === undefined)
81
- return null;
82
- if (Array.isArray(expr))
83
- return expr[n] ?? null;
84
- if (isFunctionObject(expr))
85
- return expr.fn[n] ?? null;
86
- return null;
87
- }
88
- function op1(expr) {
89
- return op(expr, 1);
90
- }
91
- function op2(expr) {
92
- return op(expr, 2);
93
- }
94
- function nops(expr) {
95
- if (expr === null || expr === undefined)
96
- return 0;
97
- if (Array.isArray(expr))
98
- return Math.max(0, expr.length - 1);
99
- if (isFunctionObject(expr))
100
- return Math.max(0, expr.fn.length - 1);
101
- return 0;
102
- }
103
- function symbol(expr) {
104
- if (expr === null || expr === undefined)
105
- return null;
106
- if (typeof expr === 'string') {
107
- // Is it a number?
108
- if (/^[+\-\.0-9]/.test(expr))
109
- return null;
110
- // Is it a string literal?
111
- if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
112
- return null;
113
- }
114
- const s = isSymbolObject(expr) ? expr.sym : expr;
115
- if (typeof s !== 'string')
116
- return null;
117
- return s;
118
- }
119
- function keyValuePair(expr) {
120
- const h = head(expr);
121
- if (h === 'KeyValuePair' || h === 'Tuple' || h === 'Pair') {
122
- const key = stringValue(op1(expr));
123
- if (!key)
124
- return null;
125
- return [key, op2(expr) ?? 'Nothing'];
126
- }
127
- return null;
128
- }
129
- function dictionary(expr) {
130
- if (expr === null)
131
- return null;
132
- if (typeof expr === 'object' && 'dict' in expr)
133
- return expr.dict;
134
- const kv = keyValuePair(expr);
135
- if (kv)
136
- return { [kv[0]]: kv[1] };
137
- const h = head(expr);
138
- if (h === 'Dictionary') {
139
- const result = {};
140
- for (let i = 1; i < nops(expr); i++) {
141
- const kv = keyValuePair(op(expr, i));
142
- if (kv)
143
- result[kv[0]] = kv[1];
144
- }
145
- return result;
146
- }
147
- return null;
148
- }
149
- function applyRecursively(expr, fn) {
150
- const h = head(expr);
151
- if (h !== null) {
152
- return [fn(h), ...(ops(expr) ?? []).map(fn)];
153
- }
154
- const dict = dictionary(expr);
155
- if (dict !== null) {
156
- const keys = Object.keys(dict);
157
- const result = {};
158
- for (const key of keys)
159
- result[key] = fn(dict[key]);
160
- return { dict: result };
161
- }
162
- return fn(expr);
163
- }
164
- /**
165
- * Apply a function to the arguments of a function and return an array of T
166
- */
167
- function mapArgs(expr, fn) {
168
- let args = null;
169
- if (Array.isArray(expr))
170
- args = expr;
171
- if (isFunctionObject(expr))
172
- args = expr.fn;
173
- if (args === null)
174
- return [];
175
- let i = 1;
176
- const result = [];
177
- while (i < args.length) {
178
- result.push(fn(args[i]));
179
- i += 1;
180
- }
181
- return result;
182
- }
1
+ /** CortexJS Compute Engine 0.12.4 */
183
2
 
184
- // This is the root of the `math-json` package (i.e. `math-json.js` and
185
- const version = '0.12.3';
3
+ // src/math-json/utils.ts
4
+ function isSymbolObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "sym" in expr;
6
+ }
7
+ function isStringObject(expr) {
8
+ return expr !== null && typeof expr === "object" && "str" in expr;
9
+ }
10
+ function isFunctionObject(expr) {
11
+ return expr !== null && typeof expr === "object" && "fn" in expr;
12
+ }
13
+ function isDictionaryObject(expr) {
14
+ return expr !== null && typeof expr === "object" && "dict" in expr;
15
+ }
16
+ var recommendedScriptsRegex;
17
+ function isRecommendedScripts(text) {
18
+ if (!recommendedScriptsRegex) {
19
+ const recommendedScripts = [
20
+ "Zyyy",
21
+ "Zinh",
22
+ "Arab",
23
+ "Armn",
24
+ "Beng",
25
+ "Bopo",
26
+ "Cyrl",
27
+ "Deva",
28
+ "Ethi",
29
+ "Geor",
30
+ "Grek",
31
+ "Gujr",
32
+ "Guru",
33
+ "Hang",
34
+ "Hani",
35
+ "Hebr",
36
+ "Hira",
37
+ "Kana",
38
+ "Knda",
39
+ "Khmr",
40
+ "Laoo",
41
+ "Latn",
42
+ "Mlym",
43
+ "Mymr",
44
+ "Orya",
45
+ "Sinh",
46
+ "Taml",
47
+ "Telu",
48
+ "Thaa",
49
+ "Thai",
50
+ "Tibt"
51
+ ];
52
+ const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
53
+ recommendedScriptsRegex = new RegExp(regexPattern, "u");
54
+ }
55
+ return recommendedScriptsRegex.test(text);
56
+ }
57
+ function isValidIdentifier(s) {
58
+ if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))
59
+ return true;
60
+ if (ONLY_EMOJIS.test(s))
61
+ return true;
62
+ if (!isRecommendedScripts(s))
63
+ return false;
64
+ return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
65
+ }
66
+ var VS16 = "\\u{FE0F}";
67
+ var KEYCAP = "\\u{20E3}";
68
+ var ZWJ = "\\u{200D}";
69
+ var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
70
+ var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
71
+ var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
72
+ var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
73
+ var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
74
+ var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
75
+ var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
76
+ var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
77
+ function validateIdentifier(s) {
78
+ if (typeof s !== "string")
79
+ return "not-a-string";
80
+ if (s === "")
81
+ return "empty-string";
82
+ if (s.normalize() !== s)
83
+ return "expected-nfc";
84
+ if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
85
+ return "unexpected-bidi-marker";
86
+ if (ONLY_EMOJIS.test(s))
87
+ return "valid";
88
+ if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
89
+ return "unexpected-mixed-emoji";
90
+ if (!isRecommendedScripts(s))
91
+ return "unexpected-script";
92
+ if (!isValidIdentifier(s)) {
93
+ if (!isValidIdentifier(s[0]))
94
+ return "invalid-first-char";
95
+ return "invalid-char";
96
+ }
97
+ return "valid";
98
+ }
99
+ function stringValue(expr) {
100
+ if (expr === null || expr === void 0)
101
+ return null;
102
+ if (typeof expr === "object" && "str" in expr)
103
+ return expr.str;
104
+ if (typeof expr !== "string")
105
+ return null;
106
+ if (expr.length < 2)
107
+ return null;
108
+ if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
109
+ return null;
110
+ return expr.substring(1, expr.length - 1);
111
+ }
112
+ function head(expr) {
113
+ if (expr === null || expr === void 0)
114
+ return null;
115
+ if (Array.isArray(expr)) {
116
+ if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
117
+ console.error(
118
+ `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
119
+ );
120
+ return null;
121
+ }
122
+ return expr[0];
123
+ }
124
+ if (isFunctionObject(expr))
125
+ return expr.fn[0];
126
+ return null;
127
+ }
128
+ function headName(expr) {
129
+ const h = head(expr);
130
+ return typeof h === "string" ? h : "";
131
+ }
132
+ function ops(expr) {
133
+ if (expr === null || expr === void 0)
134
+ return null;
135
+ if (Array.isArray(expr))
136
+ return expr.slice(1);
137
+ if (isFunctionObject(expr))
138
+ return expr.fn.slice(1);
139
+ return null;
140
+ }
141
+ function op(expr, n) {
142
+ if (expr === null || expr === void 0)
143
+ return null;
144
+ if (Array.isArray(expr))
145
+ return expr[n] ?? null;
146
+ if (isFunctionObject(expr))
147
+ return expr.fn[n] ?? null;
148
+ return null;
149
+ }
150
+ function op1(expr) {
151
+ return op(expr, 1);
152
+ }
153
+ function op2(expr) {
154
+ return op(expr, 2);
155
+ }
156
+ function nops(expr) {
157
+ if (expr === null || expr === void 0)
158
+ return 0;
159
+ if (Array.isArray(expr))
160
+ return Math.max(0, expr.length - 1);
161
+ if (isFunctionObject(expr))
162
+ return Math.max(0, expr.fn.length - 1);
163
+ return 0;
164
+ }
165
+ function symbol(expr) {
166
+ if (expr === null || expr === void 0)
167
+ return null;
168
+ if (typeof expr === "string") {
169
+ if (/^[+\-\.0-9]/.test(expr))
170
+ return null;
171
+ if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
172
+ return null;
173
+ }
174
+ const s = isSymbolObject(expr) ? expr.sym : expr;
175
+ if (typeof s !== "string")
176
+ return null;
177
+ return s;
178
+ }
179
+ function keyValuePair(expr) {
180
+ const h = head(expr);
181
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
182
+ const key = stringValue(op1(expr));
183
+ if (!key)
184
+ return null;
185
+ return [key, op2(expr) ?? "Nothing"];
186
+ }
187
+ return null;
188
+ }
189
+ function dictionary(expr) {
190
+ if (expr === null)
191
+ return null;
192
+ if (typeof expr === "object" && "dict" in expr)
193
+ return expr.dict;
194
+ const kv = keyValuePair(expr);
195
+ if (kv)
196
+ return { [kv[0]]: kv[1] };
197
+ const h = head(expr);
198
+ if (h === "Dictionary") {
199
+ const result = {};
200
+ for (let i = 1; i < nops(expr); i++) {
201
+ const kv2 = keyValuePair(op(expr, i));
202
+ if (kv2)
203
+ result[kv2[0]] = kv2[1];
204
+ }
205
+ return result;
206
+ }
207
+ return null;
208
+ }
209
+ function applyRecursively(expr, fn) {
210
+ const h = head(expr);
211
+ if (h !== null) {
212
+ return [fn(h), ...(ops(expr) ?? []).map(fn)];
213
+ }
214
+ const dict = dictionary(expr);
215
+ if (dict !== null) {
216
+ const keys = Object.keys(dict);
217
+ const result = {};
218
+ for (const key of keys)
219
+ result[key] = fn(dict[key]);
220
+ return { dict: result };
221
+ }
222
+ return fn(expr);
223
+ }
224
+ function mapArgs(expr, fn) {
225
+ let args = null;
226
+ if (Array.isArray(expr))
227
+ args = expr;
228
+ if (isFunctionObject(expr))
229
+ args = expr.fn;
230
+ if (args === null)
231
+ return [];
232
+ let i = 1;
233
+ const result = [];
234
+ while (i < args.length) {
235
+ result.push(fn(args[i]));
236
+ i += 1;
237
+ }
238
+ return result;
239
+ }
186
240
 
187
- export { applyRecursively, dictionary as getDictionary, stringValue as getStringValue, head, headName, isDictionaryObject, isFunctionObject, isStringObject, isSymbolObject, mapArgs, nops, op, symbol, version };
241
+ // src/math-json.ts
242
+ var version = "0.12.4";
243
+ export {
244
+ applyRecursively,
245
+ dictionary as getDictionary,
246
+ stringValue as getStringValue,
247
+ head,
248
+ headName,
249
+ isDictionaryObject,
250
+ isFunctionObject,
251
+ isStringObject,
252
+ isSymbolObject,
253
+ mapArgs,
254
+ nops,
255
+ op,
256
+ symbol,
257
+ version
258
+ };