@pie-framework/math-validation 1.4.3 → 2.0.0-next.20261110063142
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/LICENSE +233 -0
- package/README.md +41 -110
- package/dist/conversion/ast-to-mathjs.d.ts +3 -0
- package/dist/conversion/error.d.ts +4 -0
- package/dist/conversion/flatten.d.ts +1 -0
- package/{lib → dist}/conversion/latex-to-ast.d.ts +13 -12
- package/{lib → dist}/conversion/lexer.d.ts +5 -5
- package/dist/difference.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1594 -0
- package/dist/latex-equal.d.ts +2 -0
- package/dist/literal/index.d.ts +3 -0
- package/dist/log.d.ts +1 -0
- package/dist/mathjs.d.ts +11 -0
- package/{lib → dist}/node-sort.d.ts +1 -1
- package/dist/options.d.ts +13 -0
- package/{lib → dist}/symbolic/compare-compound-inequations.d.ts +2 -2
- package/{lib → dist}/symbolic/compare-equations.d.ts +1 -1
- package/dist/symbolic/index.d.ts +1 -0
- package/dist/symbolic/simplify.d.ts +2 -0
- package/{lib → dist}/symbolic/utils.d.ts +3 -3
- package/dist/value.d.ts +6 -0
- package/package.json +28 -56
- package/lib/conversion/ast-to-mathjs.d.ts +0 -12
- package/lib/conversion/ast-to-mathjs.js +0 -329
- package/lib/conversion/ast-to-mathjs.js.map +0 -1
- package/lib/conversion/error.d.ts +0 -5
- package/lib/conversion/error.js +0 -13
- package/lib/conversion/error.js.map +0 -1
- package/lib/conversion/flatten.d.ts +0 -12
- package/lib/conversion/flatten.js +0 -103
- package/lib/conversion/flatten.js.map +0 -1
- package/lib/conversion/latex-to-ast.js +0 -1479
- package/lib/conversion/latex-to-ast.js.map +0 -1
- package/lib/conversion/lexer.js +0 -135
- package/lib/conversion/lexer.js.map +0 -1
- package/lib/conversion/util.d.ts +0 -3
- package/lib/conversion/util.js +0 -36
- package/lib/conversion/util.js.map +0 -1
- package/lib/demo.d.ts +0 -4
- package/lib/demo.js +0 -173
- package/lib/demo.js.map +0 -1
- package/lib/difference.d.ts +0 -2
- package/lib/difference.js +0 -24
- package/lib/difference.js.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -9
- package/lib/index.js.map +0 -1
- package/lib/latex-equal.d.ts +0 -10
- package/lib/latex-equal.js +0 -41
- package/lib/latex-equal.js.map +0 -1
- package/lib/literal/index.d.ts +0 -10
- package/lib/literal/index.js +0 -22
- package/lib/literal/index.js.map +0 -1
- package/lib/log.d.ts +0 -1
- package/lib/log.js +0 -14
- package/lib/log.js.map +0 -1
- package/lib/mathjs.d.ts +0 -3
- package/lib/mathjs.js +0 -9
- package/lib/mathjs.js.map +0 -1
- package/lib/node-sort.js +0 -236
- package/lib/node-sort.js.map +0 -1
- package/lib/symbolic/compare-compound-inequations.js +0 -68
- package/lib/symbolic/compare-compound-inequations.js.map +0 -1
- package/lib/symbolic/compare-equations.js +0 -106
- package/lib/symbolic/compare-equations.js.map +0 -1
- package/lib/symbolic/index.d.ts +0 -4
- package/lib/symbolic/index.js +0 -340
- package/lib/symbolic/index.js.map +0 -1
- package/lib/symbolic/utils.js +0 -323
- package/lib/symbolic/utils.js.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,1594 @@
|
|
|
1
|
+
import e from "debug";
|
|
2
|
+
import { all as t, create as n } from "mathjs";
|
|
3
|
+
// src/conversion/error.ts
|
|
4
|
+
var r = class extends Error {
|
|
5
|
+
location;
|
|
6
|
+
constructor(e, t) {
|
|
7
|
+
super(e || "Error parsing input"), this.name = "ParseError", this.location = t;
|
|
8
|
+
}
|
|
9
|
+
}, i = () => {}, a = (t) => typeof process < "u" && process.env.NODE_ENV === "test" ? e(t) : i, o = a("mv:lexer"), s = class {
|
|
10
|
+
input;
|
|
11
|
+
location;
|
|
12
|
+
rules;
|
|
13
|
+
whitespace;
|
|
14
|
+
constructor(e, t = "\\s") {
|
|
15
|
+
this.input = "", this.location = 0, this.whitespace = RegExp(`^(${t})+`), this.rules = e.map((e) => {
|
|
16
|
+
let [t, n, r] = e, i = [RegExp(`^${t}`), n];
|
|
17
|
+
return r && i.push(r), i;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
set_input(e) {
|
|
21
|
+
if (typeof e != "string") throw Error("Input must be a string");
|
|
22
|
+
this.input = e, this.location = 0;
|
|
23
|
+
}
|
|
24
|
+
return_state() {
|
|
25
|
+
return {
|
|
26
|
+
input: this.input,
|
|
27
|
+
location: this.location
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
set_state({ input: e = null, location: t = 0 } = {}) {
|
|
31
|
+
e !== null && (this.input = e, this.location = t);
|
|
32
|
+
}
|
|
33
|
+
advance({ remove_initial_space: e = !0 } = {}) {
|
|
34
|
+
o("[advance] input: ", this.input);
|
|
35
|
+
let t = this.whitespace.exec(this.input), n = this.input.match(this.whitespace);
|
|
36
|
+
if (o("input:", this.input, "result:", t, n), o("ws result:", t), t) {
|
|
37
|
+
let n = t[0].length;
|
|
38
|
+
if (this.input = this.input.slice(n), this.location += n, o("location:", this.location, "input now:", this.input), !e) return {
|
|
39
|
+
token_type: "SPACE",
|
|
40
|
+
token_text: t[0],
|
|
41
|
+
original_text: t[0]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (this.input.length === 0) return {
|
|
45
|
+
token_type: "EOF",
|
|
46
|
+
token_text: "",
|
|
47
|
+
original_text: ""
|
|
48
|
+
};
|
|
49
|
+
t = null;
|
|
50
|
+
for (var r of this.rules) if (t = r[0].exec(this.input), t) {
|
|
51
|
+
let e = t[0].length;
|
|
52
|
+
this.input = this.input.slice(e), this.location += e;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return t === null ? {
|
|
56
|
+
token_type: "INVALID",
|
|
57
|
+
token_text: this.input[0],
|
|
58
|
+
original_text: this.input[0]
|
|
59
|
+
} : r.length > 2 ? {
|
|
60
|
+
token_type: r[1],
|
|
61
|
+
token_text: r[2],
|
|
62
|
+
original_text: t[0]
|
|
63
|
+
} : {
|
|
64
|
+
token_type: r[1],
|
|
65
|
+
token_text: t[0],
|
|
66
|
+
original_text: t[0]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
unput(e) {
|
|
70
|
+
if (typeof e != "string") throw Error("Input must be a string");
|
|
71
|
+
this.location -= e.length, this.input = e + this.input;
|
|
72
|
+
}
|
|
73
|
+
}, c = (e) => {
|
|
74
|
+
if (e != null) return e.tree === void 0 ? e : e.tree;
|
|
75
|
+
}, l = {
|
|
76
|
+
"+": !0,
|
|
77
|
+
"*": !0,
|
|
78
|
+
and: !0,
|
|
79
|
+
or: !0,
|
|
80
|
+
union: !0,
|
|
81
|
+
intersect: !0
|
|
82
|
+
};
|
|
83
|
+
function u(e) {
|
|
84
|
+
var t = c(e);
|
|
85
|
+
if (!Array.isArray(t)) return t;
|
|
86
|
+
var n = t[0], r = t.slice(1);
|
|
87
|
+
if (r = r.map((e) => u(e)), l[n]) {
|
|
88
|
+
let e = [];
|
|
89
|
+
for (let t = 0; t < r.length; t++) Array.isArray(r[t]) && r[t][0] === n ? e = e.concat(r[t].slice(1)) : e.push(r[t]);
|
|
90
|
+
r = e;
|
|
91
|
+
}
|
|
92
|
+
return [n].concat(r);
|
|
93
|
+
}
|
|
94
|
+
// src/conversion/latex-to-ast.ts
|
|
95
|
+
var d = "\\s|\\\\,|\\\\!|\\\\ |\\\\>|\\\\;|\\\\:|\\\\quad\\b|\\\\qquad\\b", f = "(E[+\\-]?[0-9]+\\s*($|(?=\\,|&|\\||\\\\\\||\\)|\\}|\\\\}|\\]|\\\\\\\\|\\\\end)))?", p = [
|
|
96
|
+
["(mm|cm|km|ft|yd|mi|mmi|li|rd|angstrom|mil|mL|ml|L|m3|in3|ft3|pt|qt|gal|bbl){1}", "UNIT"],
|
|
97
|
+
["\\$", "TEXT"],
|
|
98
|
+
["\\\\\\$", "TEXT"],
|
|
99
|
+
["\\\\text{[a-zA-Z0-9\\s\\\\,\\\\.]+?}", "TEXT"],
|
|
100
|
+
["[0-9]+\\s*\\\\frac(?![a-zA-Z])", "MIXED_NUMBER"],
|
|
101
|
+
["[0-9]{1,3}(\\,[0-9]{3})+(\\.[0-9]+)*" + f, "NUMBER"],
|
|
102
|
+
["[0-9]+(\\.[0-9]*)?" + f, "NUMBER"],
|
|
103
|
+
["\\.[0-9]+" + f, "NUMBER"],
|
|
104
|
+
[",", ","],
|
|
105
|
+
["\\*", "*"],
|
|
106
|
+
["\\×", "*"],
|
|
107
|
+
["\\•", "*"],
|
|
108
|
+
["\\·", "*"],
|
|
109
|
+
["\\/", "/"],
|
|
110
|
+
["\\÷", "/"],
|
|
111
|
+
["%", "PERCENT"],
|
|
112
|
+
["\\\\%", "PERCENT"],
|
|
113
|
+
["−", "-"],
|
|
114
|
+
["-", "-"],
|
|
115
|
+
["\\+", "+"],
|
|
116
|
+
["\\^", "^"],
|
|
117
|
+
["\\(", "("],
|
|
118
|
+
["\\\\left\\s*\\(", "("],
|
|
119
|
+
["\\\\bigl\\s*\\(", "("],
|
|
120
|
+
["\\\\Bigl\\s*\\(", "("],
|
|
121
|
+
["\\\\biggl\\s*\\(", "("],
|
|
122
|
+
["\\\\Biggl\\s*\\(", "("],
|
|
123
|
+
["\\)", ")"],
|
|
124
|
+
["\\\\right\\s*\\)", ")"],
|
|
125
|
+
["\\\\bigr\\s*\\)", ")"],
|
|
126
|
+
["\\\\Bigr\\s*\\)", ")"],
|
|
127
|
+
["\\\\biggr\\s*\\)", ")"],
|
|
128
|
+
["\\\\Biggr\\s*\\)", ")"],
|
|
129
|
+
["\\[", "["],
|
|
130
|
+
["\\\\left\\s*\\[", "["],
|
|
131
|
+
["\\\\bigl\\s*\\[", "["],
|
|
132
|
+
["\\\\Bigl\\s*\\[", "["],
|
|
133
|
+
["\\\\biggl\\s*\\[", "["],
|
|
134
|
+
["\\\\Biggl\\s*\\[", "["],
|
|
135
|
+
["\\]", "]"],
|
|
136
|
+
["\\\\right\\s*\\]", "]"],
|
|
137
|
+
["\\\\bigr\\s*\\]", "]"],
|
|
138
|
+
["\\\\Bigr\\s*\\]", "]"],
|
|
139
|
+
["\\\\biggr\\s*\\]", "]"],
|
|
140
|
+
["\\\\Biggr\\s*\\]", "]"],
|
|
141
|
+
["\\|", "|"],
|
|
142
|
+
["\\\\left\\s*\\|", "|L"],
|
|
143
|
+
["\\\\bigl\\s*\\|", "|L"],
|
|
144
|
+
["\\\\Bigl\\s*\\|", "|L"],
|
|
145
|
+
["\\\\biggl\\s*\\|", "|L"],
|
|
146
|
+
["\\\\Biggl\\s*\\|", "|L"],
|
|
147
|
+
["\\\\right\\s*\\|", "|"],
|
|
148
|
+
["\\\\bigr\\s*\\|", "|"],
|
|
149
|
+
["\\\\Bigr\\s*\\|", "|"],
|
|
150
|
+
["\\\\biggr\\s*\\|", "|"],
|
|
151
|
+
["\\\\Biggr\\s*\\|", "|"],
|
|
152
|
+
["\\\\big\\s*\\|", "|"],
|
|
153
|
+
["\\\\Big\\s*\\|", "|"],
|
|
154
|
+
["\\\\bigg\\s*\\|", "|"],
|
|
155
|
+
["\\\\Bigg\\s*\\|", "|"],
|
|
156
|
+
["{", "{"],
|
|
157
|
+
["}", "}"],
|
|
158
|
+
["\\\\{", "LBRACE"],
|
|
159
|
+
["\\\\left\\s*\\\\{", "LBRACE"],
|
|
160
|
+
["\\\\bigl\\s*\\\\{", "LBRACE"],
|
|
161
|
+
["\\\\Bigl\\s*\\\\{", "LBRACE"],
|
|
162
|
+
["\\\\biggl\\s*\\\\{", "LBRACE"],
|
|
163
|
+
["\\\\Biggl\\s*\\\\{", "LBRACE"],
|
|
164
|
+
["\\\\}", "RBRACE"],
|
|
165
|
+
["\\\\right\\s*\\\\}", "RBRACE"],
|
|
166
|
+
["\\\\bigr\\s*\\\\}", "RBRACE"],
|
|
167
|
+
["\\\\Bigr\\s*\\\\}", "RBRACE"],
|
|
168
|
+
["\\\\biggr\\s*\\\\}", "RBRACE"],
|
|
169
|
+
["\\\\Biggr\\s*\\\\}", "RBRACE"],
|
|
170
|
+
["\\\\cdot(?![a-zA-Z])", "*"],
|
|
171
|
+
["\\\\div(?![a-zA-Z])", "/"],
|
|
172
|
+
["\\\\times(?![a-zA-Z])", "*"],
|
|
173
|
+
["\\\\frac(?![a-zA-Z])", "FRAC"],
|
|
174
|
+
["°", "deg"],
|
|
175
|
+
["°", "deg"],
|
|
176
|
+
["\\\\degree", "deg"],
|
|
177
|
+
["\\\\deg", "deg"],
|
|
178
|
+
["\\\\grade", "grad"],
|
|
179
|
+
["\\\\gon", "grad"],
|
|
180
|
+
["\\\\grad", "grad"],
|
|
181
|
+
[":", ":"],
|
|
182
|
+
["\\\\mid", "MID"],
|
|
183
|
+
[
|
|
184
|
+
"\\\\vartheta(?![a-zA-Z])",
|
|
185
|
+
"LATEXCOMMAND",
|
|
186
|
+
"\\theta"
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
"\\\\π",
|
|
190
|
+
"LATEXCOMMAND",
|
|
191
|
+
"\\pi"
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
"\\\\varepsilon(?![a-zA-Z])",
|
|
195
|
+
"LATEXCOMMAND",
|
|
196
|
+
"\\epsilon"
|
|
197
|
+
],
|
|
198
|
+
[
|
|
199
|
+
"\\\\varrho(?![a-zA-Z])",
|
|
200
|
+
"LATEXCOMMAND",
|
|
201
|
+
"\\rho"
|
|
202
|
+
],
|
|
203
|
+
[
|
|
204
|
+
"\\\\varphi(?![a-zA-Z])",
|
|
205
|
+
"LATEXCOMMAND",
|
|
206
|
+
"\\phi"
|
|
207
|
+
],
|
|
208
|
+
["\\\\infty(?![a-zA-Z])", "INFINITY"],
|
|
209
|
+
["\\\\Infinity(?![a-zA-Z])", "INFINITY"],
|
|
210
|
+
["\\\\sqrt(?![a-zA-Z])", "SQRT"],
|
|
211
|
+
["\\\\log(?![a-zA-Z])", "LOG"],
|
|
212
|
+
["\\\\ln(?![a-zA-Z])", "LN"],
|
|
213
|
+
[
|
|
214
|
+
"\\\\cosec",
|
|
215
|
+
"LATEXCOMMAND",
|
|
216
|
+
"\\csc"
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
"\\\\sin\\^\\{-1}(?![a-zA-Z])",
|
|
220
|
+
"LATEXCOMMAND",
|
|
221
|
+
"\\asin"
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
"\\\\cos\\^\\{-1}(?![a-zA-Z])",
|
|
225
|
+
"LATEXCOMMAND",
|
|
226
|
+
"\\acos"
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
"\\\\tan\\^\\{-1}(?![a-zA-Z])",
|
|
230
|
+
"LATEXCOMMAND",
|
|
231
|
+
"\\atan"
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
"\\\\cot\\^\\{-1}(?![a-zA-Z])",
|
|
235
|
+
"LATEXCOMMAND",
|
|
236
|
+
"\\acot"
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
"\\\\sec\\^\\{-1}(?![a-zA-Z])",
|
|
240
|
+
"LATEXCOMMAND",
|
|
241
|
+
"\\asec"
|
|
242
|
+
],
|
|
243
|
+
[
|
|
244
|
+
"\\\\csc\\^\\{-1}(?![a-zA-Z])",
|
|
245
|
+
"LATEXCOMMAND",
|
|
246
|
+
"\\acsc"
|
|
247
|
+
],
|
|
248
|
+
[
|
|
249
|
+
"\\\\arsin(?![a-zA-Z])",
|
|
250
|
+
"LATEXCOMMAND",
|
|
251
|
+
"\\asin"
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
"\\\\arcsin(?![a-zA-Z])",
|
|
255
|
+
"LATEXCOMMAND",
|
|
256
|
+
"\\asin"
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
"\\\\arcos(?![a-zA-Z])",
|
|
260
|
+
"LATEXCOMMAND",
|
|
261
|
+
"\\acos"
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
"\\\\arccos(?![a-zA-Z])",
|
|
265
|
+
"LATEXCOMMAND",
|
|
266
|
+
"\\acos"
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
"\\\\artan(?![a-zA-Z])",
|
|
270
|
+
"LATEXCOMMAND",
|
|
271
|
+
"\\atan"
|
|
272
|
+
],
|
|
273
|
+
[
|
|
274
|
+
"\\\\arctan(?![a-zA-Z])",
|
|
275
|
+
"LATEXCOMMAND",
|
|
276
|
+
"\\atan"
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
"\\\\arcot(?![a-zA-Z])",
|
|
280
|
+
"LATEXCOMMAND",
|
|
281
|
+
"\\acot"
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
"\\\\arccot(?![a-zA-Z])",
|
|
285
|
+
"LATEXCOMMAND",
|
|
286
|
+
"\\acot"
|
|
287
|
+
],
|
|
288
|
+
[
|
|
289
|
+
"\\\\arsec(?![a-zA-Z])",
|
|
290
|
+
"LATEXCOMMAND",
|
|
291
|
+
"\\asec"
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
"\\\\arcsec(?![a-zA-Z])",
|
|
295
|
+
"LATEXCOMMAND",
|
|
296
|
+
"\\asec"
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
"\\\\arcsc(?![a-zA-Z])",
|
|
300
|
+
"LATEXCOMMAND",
|
|
301
|
+
"\\acsc"
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
"\\\\arccsc(?![a-zA-Z])",
|
|
305
|
+
"LATEXCOMMAND",
|
|
306
|
+
"\\acsc"
|
|
307
|
+
],
|
|
308
|
+
["\\\\land(?![a-zA-Z])", "AND"],
|
|
309
|
+
["\\\\wedge(?![a-zA-Z])", "AND"],
|
|
310
|
+
["\\\\lor(?![a-zA-Z])", "OR"],
|
|
311
|
+
["\\\\vee(?![a-zA-Z])", "OR"],
|
|
312
|
+
["\\\\lnot(?![a-zA-Z])", "NOT"],
|
|
313
|
+
["=", "="],
|
|
314
|
+
["≠", "NE"],
|
|
315
|
+
["\\\\neq(?![a-zA-Z])", "NE"],
|
|
316
|
+
["\\\\ne(?![a-zA-Z])", "NE"],
|
|
317
|
+
["\\\\not\\s*=", "NE"],
|
|
318
|
+
["\\\\leq(?![a-zA-Z])", "LE"],
|
|
319
|
+
["\\\\le(?![a-zA-Z])", "LE"],
|
|
320
|
+
["\\\\geq(?![a-zA-Z])", "GE"],
|
|
321
|
+
["\\\\ge(?![a-zA-Z])", "GE"],
|
|
322
|
+
["<", "<"],
|
|
323
|
+
["≤", "LE"],
|
|
324
|
+
["\\\\lt(?![a-zA-Z])", "<"],
|
|
325
|
+
[">", ">"],
|
|
326
|
+
["≥", "GE"],
|
|
327
|
+
["\\\\gt(?![a-zA-Z])", ">"],
|
|
328
|
+
["\\\\approx", "≈"],
|
|
329
|
+
["≈", "≈"],
|
|
330
|
+
["\\\\napprox", "≉"],
|
|
331
|
+
["≉", "≉"],
|
|
332
|
+
["\\\\simeq", "≃"],
|
|
333
|
+
["≃", "≃"],
|
|
334
|
+
["\\\\sim", "~"],
|
|
335
|
+
["~", "~"],
|
|
336
|
+
["\\\\nsim", "≁"],
|
|
337
|
+
["≁", "≁"],
|
|
338
|
+
["\\\\cong", "≅"],
|
|
339
|
+
["≅", "≅"],
|
|
340
|
+
["\\\\ncong", "≆"],
|
|
341
|
+
["≆", "≆"],
|
|
342
|
+
["f\\^\\{-1}", "TEXT"],
|
|
343
|
+
["g\\^\\{-1}", "TEXT"],
|
|
344
|
+
["\\\\in(?![a-zA-Z])", "IN"],
|
|
345
|
+
["\\\\notin(?![a-zA-Z])", "NOTIN"],
|
|
346
|
+
["\\\\not\\s*\\\\in(?![a-zA-Z])", "NOTIN"],
|
|
347
|
+
["\\\\ni(?![a-zA-Z])", "NI"],
|
|
348
|
+
["\\\\not\\s*\\\\ni(?![a-zA-Z])", "NOTNI"],
|
|
349
|
+
["\\\\subset(?![a-zA-Z])", "SUBSET"],
|
|
350
|
+
["\\\\not\\s*\\\\subset(?![a-zA-Z])", "NOTSUBSET"],
|
|
351
|
+
["\\\\supset(?![a-zA-Z])", "SUPERSET"],
|
|
352
|
+
["\\\\not\\s*\\\\supset(?![a-zA-Z])", "NOTSUPERSET"],
|
|
353
|
+
["\\\\cup(?![a-zA-Z])", "UNION"],
|
|
354
|
+
["\\\\cap(?![a-zA-Z])", "INTERSECT"],
|
|
355
|
+
["!", "!"],
|
|
356
|
+
["'", "'"],
|
|
357
|
+
["_", "_"],
|
|
358
|
+
["&", "&"],
|
|
359
|
+
["\\\\ldots", "LDOTS"],
|
|
360
|
+
["\\\\\\\\", "LINEBREAK"],
|
|
361
|
+
["\\\\begin\\s*{\\s*[a-zA-Z0-9]+\\s*}", "BEGINENVIRONMENT"],
|
|
362
|
+
["\\\\end\\s*{\\s*[a-zA-Z0-9]+\\s*}", "ENDENVIRONMENT"],
|
|
363
|
+
["\\\\var\\s*{\\s*[a-zA-Z0-9]+\\s*}", "VARMULTICHAR"],
|
|
364
|
+
["\\\\[a-zA-Z]+(?![a-zA-Z])", "LATEXCOMMAND"],
|
|
365
|
+
["[a-zA-Z]", "VAR"]
|
|
366
|
+
], ee = {
|
|
367
|
+
allowSimplifiedFunctionApplication: !0,
|
|
368
|
+
allowedLatexSymbols: /* @__PURE__ */ "alpha.beta.gamma.Gamma.delta.Delta.epsilon.zeta.eta.theta.Theta.iota.kappa.lambda.Lambda.mu.nu.xi.Xi.pi.Pi.rho.sigma.Sigma.tau.Tau.upsilon.Upsilon.phi.Phi.chi.psi.Psi.omega.Omega.partial".split("."),
|
|
369
|
+
appliedFunctionSymbols: /* @__PURE__ */ "abs.exp.log.ln.log10.sign.sqrt.erf.acos.acosh.acot.acoth.acsc.acsch.asec.asech.asin.asinh.atan.atanh.cos.cosh.cot.coth.csc.csch.sec.sech.sin.sinh.tan.tanh.arg".split("."),
|
|
370
|
+
functionSymbols: ["f", "g"],
|
|
371
|
+
parseLeibnizNotation: !0,
|
|
372
|
+
missingFactor: (e, t) => {
|
|
373
|
+
throw t;
|
|
374
|
+
},
|
|
375
|
+
unknownCommandBehavior: "passthrough",
|
|
376
|
+
keepMixedNumbers: !1
|
|
377
|
+
}, m = class {
|
|
378
|
+
lexer;
|
|
379
|
+
token;
|
|
380
|
+
opts;
|
|
381
|
+
constructor(e) {
|
|
382
|
+
if (this.opts = {
|
|
383
|
+
...ee,
|
|
384
|
+
...e
|
|
385
|
+
}, this.opts.unknownCommandBehavior !== "error" && this.opts.unknownCommandBehavior !== "passthrough") throw Error("Unknown behavior for unknown command: " + this.opts.unknownCommandBehavior);
|
|
386
|
+
this.lexer = new s(p, d);
|
|
387
|
+
}
|
|
388
|
+
advance(e) {
|
|
389
|
+
if (this.token = this.lexer.advance(e), this.token.token_type === "INVALID") throw new r("Invalid symbol '" + this.token.original_text + "'", this.lexer.location);
|
|
390
|
+
}
|
|
391
|
+
return_state() {
|
|
392
|
+
return {
|
|
393
|
+
lexer_state: this.lexer.return_state(),
|
|
394
|
+
token: Object.assign({}, this.token)
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
set_state(e) {
|
|
398
|
+
this.lexer.set_state(e.lexer_state), this.token = Object.assign({}, e.token);
|
|
399
|
+
}
|
|
400
|
+
convert(e, t) {
|
|
401
|
+
this.lexer.set_input(e), this.advance();
|
|
402
|
+
var n = this.statement_list(t);
|
|
403
|
+
if (this.token.token_type !== "EOF") throw new r("Invalid location of '" + this.token.original_text + "'", this.lexer.location);
|
|
404
|
+
return u(n);
|
|
405
|
+
}
|
|
406
|
+
statement_list(e) {
|
|
407
|
+
for (var t = [this.statement(e)]; this.token.token_type === ",";) this.advance(), t.push(this.statement(e));
|
|
408
|
+
return t = t.length > 1 ? ["list"].concat(t) : t[0], t;
|
|
409
|
+
}
|
|
410
|
+
statement(e = {}) {
|
|
411
|
+
let { inside_absolute_value: t = 0, unknownCommands: n = "error" } = e;
|
|
412
|
+
if (this.token.token_type === "LDOTS") return this.advance(), ["ldots"];
|
|
413
|
+
var r;
|
|
414
|
+
try {
|
|
415
|
+
r = this.return_state();
|
|
416
|
+
let e = this.statement_a({
|
|
417
|
+
inside_absolute_value: t,
|
|
418
|
+
unknownCommands: n
|
|
419
|
+
});
|
|
420
|
+
if (this.token.token_type !== ":" && this.token.token_type !== "MID") return e;
|
|
421
|
+
let i = this.token.token_type === ":" ? ":" : "|";
|
|
422
|
+
return this.advance(), [
|
|
423
|
+
i,
|
|
424
|
+
e,
|
|
425
|
+
this.statement_a({ unknownCommands: n })
|
|
426
|
+
];
|
|
427
|
+
} catch (e) {
|
|
428
|
+
try {
|
|
429
|
+
this.set_state(r);
|
|
430
|
+
let t = this.statement_a({ parse_absolute_value: !1 });
|
|
431
|
+
if (this.token.token_type[0] !== "|") throw e;
|
|
432
|
+
return this.advance(), [
|
|
433
|
+
"|",
|
|
434
|
+
t,
|
|
435
|
+
this.statement_a({ parse_absolute_value: !1 })
|
|
436
|
+
];
|
|
437
|
+
} catch {
|
|
438
|
+
throw e;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
statement_a(e = {}) {
|
|
443
|
+
let { inside_absolute_value: t = 0, parse_absolute_value: n = !0, unknownCommands: r } = e;
|
|
444
|
+
for (var i = this.statement_b({
|
|
445
|
+
inside_absolute_value: t,
|
|
446
|
+
parse_absolute_value: n,
|
|
447
|
+
unknownCommands: r
|
|
448
|
+
}); this.token.token_type === "OR";) {
|
|
449
|
+
let e = this.token.token_type.toLowerCase();
|
|
450
|
+
this.advance();
|
|
451
|
+
let a = this.statement_b({
|
|
452
|
+
inside_absolute_value: t,
|
|
453
|
+
parse_absolute_value: n,
|
|
454
|
+
unknownCommands: r
|
|
455
|
+
});
|
|
456
|
+
i = [
|
|
457
|
+
e,
|
|
458
|
+
i,
|
|
459
|
+
a
|
|
460
|
+
];
|
|
461
|
+
}
|
|
462
|
+
return i;
|
|
463
|
+
}
|
|
464
|
+
statement_b(e) {
|
|
465
|
+
for (var t = this.relation(e); this.token.token_type === "AND";) {
|
|
466
|
+
let n = this.token.token_type.toLowerCase();
|
|
467
|
+
this.advance();
|
|
468
|
+
let r = this.relation(e);
|
|
469
|
+
t = [
|
|
470
|
+
n,
|
|
471
|
+
t,
|
|
472
|
+
r
|
|
473
|
+
];
|
|
474
|
+
}
|
|
475
|
+
return t;
|
|
476
|
+
}
|
|
477
|
+
relation(e) {
|
|
478
|
+
if (this.token.token_type === "NOT" || this.token.token_type === "!") return this.advance(), ["not", this.relation(e)];
|
|
479
|
+
var t = this.expression(e);
|
|
480
|
+
let n = (e) => e === "<" || e === "LE" || e === ">" || e === "GE" || e === "NE";
|
|
481
|
+
for (; this.token.token_type === "=" || this.token.token_type === "NE" || this.token.token_type === "<" || this.token.token_type === ">" || this.token.token_type === "LE" || this.token.token_type === "GE" || this.token.token_type === "IN" || this.token.token_type === "NOTIN" || this.token.token_type === "NI" || this.token.token_type === "NOTNI" || this.token.token_type === "SUBSET" || this.token.token_type === "NOTSUBSET" || this.token.token_type === "SUPERSET" || this.token.token_type === "NOTSUPERSET" || this.token.token_type === "≈" || this.token.token_type === "≉" || this.token.token_type === "~" || this.token.token_type === "≃" || this.token.token_type === "≁" || this.token.token_type === "≅" || this.token.token_type === "≆";) {
|
|
482
|
+
let r = this.token.token_type.toLowerCase(), i = n(this.token.token_type);
|
|
483
|
+
this.advance();
|
|
484
|
+
let a = this.expression(e), o = (e) => {
|
|
485
|
+
switch (e) {
|
|
486
|
+
case "<": return "smaller";
|
|
487
|
+
case "LE":
|
|
488
|
+
case "le": return "smallerEq";
|
|
489
|
+
case ">": return "larger";
|
|
490
|
+
case "GE":
|
|
491
|
+
case "ge": return "largerEq";
|
|
492
|
+
case "NE":
|
|
493
|
+
case "ne": return "unequal";
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
if (i && n(this.token.token_type)) {
|
|
497
|
+
let i = ["tuple"];
|
|
498
|
+
i.push(o(r));
|
|
499
|
+
let s = [
|
|
500
|
+
"tuple",
|
|
501
|
+
t,
|
|
502
|
+
a
|
|
503
|
+
];
|
|
504
|
+
for (; n(this.token.token_type);) i.push(o(this.token.token_type)), this.advance(), s.push(this.expression(e));
|
|
505
|
+
t = [
|
|
506
|
+
"relational",
|
|
507
|
+
s,
|
|
508
|
+
i
|
|
509
|
+
];
|
|
510
|
+
} else if (r === "=") for (t = [
|
|
511
|
+
r,
|
|
512
|
+
t,
|
|
513
|
+
a
|
|
514
|
+
]; this.token.token_type === "=";) this.advance(), t.push(this.expression(e));
|
|
515
|
+
else t = [
|
|
516
|
+
r,
|
|
517
|
+
t,
|
|
518
|
+
a
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
return t;
|
|
522
|
+
}
|
|
523
|
+
expression(e) {
|
|
524
|
+
this.token.token_type === "+" && this.advance();
|
|
525
|
+
let t = !1;
|
|
526
|
+
this.token.token_type === "-" && (t = !0, this.advance());
|
|
527
|
+
var n = this.term(e);
|
|
528
|
+
for (t && (n = ["-", n]); this.token.token_type === "+" || this.token.token_type === "-" || this.token.token_type === "UNION" || this.token.token_type === "INTERSECT";) {
|
|
529
|
+
let t = this.token.token_type.toLowerCase(), r = !1;
|
|
530
|
+
this.token.token_type === "-" ? (t = "+", r = !0, this.advance()) : (this.advance(), t === "+" && this.token.token_type === "-" && (r = !0, this.advance()));
|
|
531
|
+
let i = this.term(e);
|
|
532
|
+
r && (i = ["-", i]), n = [
|
|
533
|
+
t,
|
|
534
|
+
n,
|
|
535
|
+
i
|
|
536
|
+
];
|
|
537
|
+
}
|
|
538
|
+
return n;
|
|
539
|
+
}
|
|
540
|
+
term(e) {
|
|
541
|
+
var t;
|
|
542
|
+
try {
|
|
543
|
+
t = this.factor(e);
|
|
544
|
+
} catch (e) {
|
|
545
|
+
t = this.opts.missingFactor(this.token, e), t = Number.isFinite(t) ? t : 0;
|
|
546
|
+
}
|
|
547
|
+
var n = !1;
|
|
548
|
+
do
|
|
549
|
+
if (n = !1, this.token.token_type === "PERCENT") this.advance(), t = ["%", t], n = !0;
|
|
550
|
+
else if (this.token.token_type === "*") this.advance(), t = [
|
|
551
|
+
"*",
|
|
552
|
+
t,
|
|
553
|
+
this.factor(e)
|
|
554
|
+
], n = !0;
|
|
555
|
+
else if (this.token.token_type === "/") this.advance(), t = [
|
|
556
|
+
"/",
|
|
557
|
+
t,
|
|
558
|
+
this.factor(e)
|
|
559
|
+
], n = !0;
|
|
560
|
+
else {
|
|
561
|
+
let r = Object.assign({}, e);
|
|
562
|
+
r.allow_absolute_value_closing = !0;
|
|
563
|
+
let i = this.nonMinusFactor(r);
|
|
564
|
+
i !== !1 && (t = [
|
|
565
|
+
"*",
|
|
566
|
+
t,
|
|
567
|
+
i
|
|
568
|
+
], n = !0);
|
|
569
|
+
}
|
|
570
|
+
while (n);
|
|
571
|
+
return t;
|
|
572
|
+
}
|
|
573
|
+
factor(e) {
|
|
574
|
+
if (this.token.token_type === "-") return this.advance(), ["-", this.factor(e)];
|
|
575
|
+
var t = this.nonMinusFactor(e);
|
|
576
|
+
if (t === !1) throw this.token.token_type === "EOF" ? new r("Unexpected end of input", this.lexer.location) : new r("Invalid location of '" + this.token.original_text + "'", this.lexer.location);
|
|
577
|
+
return t;
|
|
578
|
+
}
|
|
579
|
+
nonMinusFactor(e) {
|
|
580
|
+
let t = this.baseFactor(e);
|
|
581
|
+
if (this.token.token_type === "!" || this.token.token_type === "'") {
|
|
582
|
+
if (t === !1) throw new r("Invalid location of " + this.token.token_type, this.lexer.location);
|
|
583
|
+
for (; this.token.token_type === "!" || this.token.token_type === "'";) t = this.token.token_type === "!" ? [
|
|
584
|
+
"apply",
|
|
585
|
+
"factorial",
|
|
586
|
+
t
|
|
587
|
+
] : ["prime", t], this.advance();
|
|
588
|
+
}
|
|
589
|
+
if (this.token.token_type === "^") {
|
|
590
|
+
if (t === !1) throw new r("Invalid location of ^", this.lexer.location);
|
|
591
|
+
this.advance();
|
|
592
|
+
let n = Object.assign({}, e);
|
|
593
|
+
return delete n.allow_absolute_value_closing, delete n.inside_absolute_value, [
|
|
594
|
+
"^",
|
|
595
|
+
t,
|
|
596
|
+
this.factor(n)
|
|
597
|
+
];
|
|
598
|
+
}
|
|
599
|
+
return t;
|
|
600
|
+
}
|
|
601
|
+
fraction({ parse_absolute_value: e = !0, unknownCommands: t = "error" }) {
|
|
602
|
+
if (this.advance(), this.token.token_type !== "{") throw new r("Expecting {", this.lexer.location);
|
|
603
|
+
if (this.advance(), this.opts.parseLeibnizNotation) {
|
|
604
|
+
let e = this.return_state(), t = this.leibniz_notation();
|
|
605
|
+
if (t) return t;
|
|
606
|
+
this.set_state(e);
|
|
607
|
+
}
|
|
608
|
+
let n = this.statement({
|
|
609
|
+
parse_absolute_value: e,
|
|
610
|
+
unknownCommands: t
|
|
611
|
+
});
|
|
612
|
+
if (this.token.token_type !== "}") throw new r("Expecting }", this.lexer.location);
|
|
613
|
+
if (this.advance(), this.token.token_type !== "{") throw new r("Expecting {", this.lexer.location);
|
|
614
|
+
this.advance();
|
|
615
|
+
let i = this.statement({
|
|
616
|
+
parse_absolute_value: e,
|
|
617
|
+
unknownCommands: t
|
|
618
|
+
});
|
|
619
|
+
if (this.token.token_type !== "}") throw new r("Expecting }", this.lexer.location);
|
|
620
|
+
return this.advance(), [
|
|
621
|
+
"/",
|
|
622
|
+
n,
|
|
623
|
+
i
|
|
624
|
+
];
|
|
625
|
+
}
|
|
626
|
+
baseFactor({ inside_absolute_value: e = 0, parse_absolute_value: t = !0, allow_absolute_value_closing: n = !1, unknownCommands: i = "error" } = {}) {
|
|
627
|
+
var a = !1;
|
|
628
|
+
if (this.token.token_type === "MIXED_NUMBER") try {
|
|
629
|
+
let e = this.token.token_text.split("\\\\frac")[0].trim(), t = parseInt(e, 10), n = this.fraction({});
|
|
630
|
+
return this.opts.keepMixedNumbers ? [
|
|
631
|
+
"mixed",
|
|
632
|
+
t,
|
|
633
|
+
n
|
|
634
|
+
] : [
|
|
635
|
+
"+",
|
|
636
|
+
t,
|
|
637
|
+
n
|
|
638
|
+
];
|
|
639
|
+
} catch (e) {
|
|
640
|
+
throw new r(`Mixed number parsing failed: ${e.message}`);
|
|
641
|
+
}
|
|
642
|
+
if (this.token.token_type === "FRAC") return this.fraction({});
|
|
643
|
+
if (this.token.token_type === "TEXT") {
|
|
644
|
+
let e = this.token.original_text.replace(/[[\]\\]/g, "");
|
|
645
|
+
return this.advance(), e.toString();
|
|
646
|
+
}
|
|
647
|
+
if (this.token.token_type === "BEGINENVIRONMENT") {
|
|
648
|
+
let e = /\\begin\s*{\s*([a-zA-Z0-9]+)\s*}/.exec(this.token.token_text)[1];
|
|
649
|
+
if ([
|
|
650
|
+
"matrix",
|
|
651
|
+
"pmatrix",
|
|
652
|
+
"bmatrix"
|
|
653
|
+
].includes(e)) {
|
|
654
|
+
let n = 0, o = 0, s = [], c = [], l = 0, u = this.token.token_type;
|
|
655
|
+
for (this.advance(); this.token.token_type !== "ENDENVIRONMENT";) this.token.token_type === "&" ? ((u === "&" || u === "LINEBREAK") && (c.push(0), l += 1), u = this.token.token_type, this.advance()) : this.token.token_type === "LINEBREAK" ? ((u === "&" || u === "LINEBREAK") && (c.push(0), l += 1), s.push(c), l > o && (o = l), n += 1, l = 0, c = [], u = this.token.token_type, this.advance()) : (c.push(this.statement({
|
|
656
|
+
parse_absolute_value: t,
|
|
657
|
+
unknownCommands: i
|
|
658
|
+
})), l += 1, u = " ");
|
|
659
|
+
if (/\\end\s*{\s*([a-zA-Z0-9]+)\s*}/.exec(this.token.token_text)[1] !== e) throw new r("Expecting \\end{" + e + "}", this.lexer.location);
|
|
660
|
+
u === "&" && (c.push(0), l += 1), s.push(c), l > o && (o = l), n += 1, this.advance(), a = ["matrix", [
|
|
661
|
+
"tuple",
|
|
662
|
+
n,
|
|
663
|
+
o
|
|
664
|
+
]];
|
|
665
|
+
let d = ["tuple"];
|
|
666
|
+
for (let e of s) {
|
|
667
|
+
let t = ["tuple"].concat(e);
|
|
668
|
+
for (let n = e.length; n < o; n += 1) t.push(0);
|
|
669
|
+
d.push(t);
|
|
670
|
+
}
|
|
671
|
+
return a.push(d), a;
|
|
672
|
+
}
|
|
673
|
+
throw new r("Unrecognized environment " + e, this.lexer.location);
|
|
674
|
+
}
|
|
675
|
+
if (this.token.token_type === "NUMBER") {
|
|
676
|
+
a = this.token.token_text.replace(/,/g, "");
|
|
677
|
+
let e = a === "0" ? a : ((e) => e.indexOf(".") >= 0 ? e.replace(/^[0]*([0-9])(.*)/, "$1$2") : e.replace(/0*([1-9]*)/, "$1"))(a);
|
|
678
|
+
e.startsWith(".") && (e = "0" + e);
|
|
679
|
+
let t = parseFloat(e);
|
|
680
|
+
if (e !== t.toString()) {
|
|
681
|
+
let n = t.toString();
|
|
682
|
+
a = [
|
|
683
|
+
"tzn",
|
|
684
|
+
t,
|
|
685
|
+
e.substring(n.length).split("").filter((e) => e === "0").length
|
|
686
|
+
];
|
|
687
|
+
} else a = t;
|
|
688
|
+
this.advance();
|
|
689
|
+
} else if (this.token.token_type === "INFINITY") a = Infinity, this.advance();
|
|
690
|
+
else if (this.token.token_type === "deg") a = ["*", Math.PI / 180], this.advance();
|
|
691
|
+
else if (this.token.token_type === "grad") a = ["*", Math.PI / 200], this.advance();
|
|
692
|
+
else if (this.token.token_type === "UNIT") a = ["unit", this.token.token_text], this.advance();
|
|
693
|
+
else if (this.token.token_type === "SQRT") {
|
|
694
|
+
this.advance();
|
|
695
|
+
let e = 2, n;
|
|
696
|
+
if (this.token.token_type === "[") {
|
|
697
|
+
if (this.advance(), n = this.statement({
|
|
698
|
+
parse_absolute_value: t,
|
|
699
|
+
unknownCommands: i
|
|
700
|
+
}), this.token.token_type !== "]") throw new r("Expecting ]", this.lexer.location);
|
|
701
|
+
this.advance(), e = n;
|
|
702
|
+
}
|
|
703
|
+
if (this.token.token_type === "{") {
|
|
704
|
+
if (this.advance(), n = this.statement({
|
|
705
|
+
parse_absolute_value: t,
|
|
706
|
+
unknownCommands: i
|
|
707
|
+
}), this.token.token_type !== "}") throw new r("Expecting }", this.lexer.location);
|
|
708
|
+
this.advance();
|
|
709
|
+
} else n = this.statement({
|
|
710
|
+
parse_absolute_value: t,
|
|
711
|
+
unknownCommands: i
|
|
712
|
+
});
|
|
713
|
+
a = e === 2 ? [
|
|
714
|
+
"apply",
|
|
715
|
+
"sqrt",
|
|
716
|
+
n
|
|
717
|
+
] : [
|
|
718
|
+
"^",
|
|
719
|
+
n,
|
|
720
|
+
[
|
|
721
|
+
"/",
|
|
722
|
+
1,
|
|
723
|
+
e
|
|
724
|
+
]
|
|
725
|
+
];
|
|
726
|
+
} else if (this.token.token_type === "LOG" || this.token.token_type === "LN") {
|
|
727
|
+
let e = this.token.token_type === "LOG" ? 10 : "e", n;
|
|
728
|
+
if (this.advance(), this.token.token_type === "_" && (this.advance(), this.token.token_type === "{")) {
|
|
729
|
+
if (this.advance(), n = this.statement({
|
|
730
|
+
parse_absolute_value: t,
|
|
731
|
+
unknownCommands: i
|
|
732
|
+
}), this.token.token_type !== "}") throw new r("Expecting }", this.lexer.location);
|
|
733
|
+
this.advance(), e = n;
|
|
734
|
+
}
|
|
735
|
+
if (this.token.token_type === "(") {
|
|
736
|
+
if (this.advance(), n = this.statement({
|
|
737
|
+
parse_absolute_value: t,
|
|
738
|
+
unknownCommands: i
|
|
739
|
+
}), this.token.token_type !== ")") throw new r("Expecting )", this.lexer.location);
|
|
740
|
+
this.advance();
|
|
741
|
+
} else n = this.token.token_text, this.advance();
|
|
742
|
+
a = e === 10 ? [
|
|
743
|
+
"apply",
|
|
744
|
+
"log",
|
|
745
|
+
[
|
|
746
|
+
"tuple",
|
|
747
|
+
n,
|
|
748
|
+
e
|
|
749
|
+
]
|
|
750
|
+
] : e === "e" ? [
|
|
751
|
+
"apply",
|
|
752
|
+
"log",
|
|
753
|
+
n
|
|
754
|
+
] : [
|
|
755
|
+
"apply",
|
|
756
|
+
"log",
|
|
757
|
+
[
|
|
758
|
+
"tuple",
|
|
759
|
+
n,
|
|
760
|
+
e
|
|
761
|
+
]
|
|
762
|
+
];
|
|
763
|
+
} else if (this.token.token_type === "VAR" || this.token.token_type === "LATEXCOMMAND" || this.token.token_type === "VARMULTICHAR") {
|
|
764
|
+
if (a = this.token.token_text, this.token.token_type === "LATEXCOMMAND") {
|
|
765
|
+
if (a = a.slice(1), !(this.opts.appliedFunctionSymbols.includes(a) || this.opts.functionSymbols.includes(a) || this.opts.allowedLatexSymbols.includes(a)) && this.opts.unknownCommandBehavior === "error") throw new r("Unrecognized latex command " + this.token.original_text, this.lexer.location);
|
|
766
|
+
} else this.token.token_type === "VARMULTICHAR" && (a = /\\var\s*\{\s*([a-zA-Z0-9]+)\s*\}/.exec(a)[1]);
|
|
767
|
+
if (this.opts.appliedFunctionSymbols.includes(a) || this.opts.functionSymbols.includes(a)) {
|
|
768
|
+
let e = !1;
|
|
769
|
+
if (this.opts.appliedFunctionSymbols.includes(a) && (e = !0), this.advance(), this.token.token_type === "_") {
|
|
770
|
+
this.advance();
|
|
771
|
+
let e = this.baseFactor({ parse_absolute_value: t });
|
|
772
|
+
if (e === !1) throw this.token.token_type === "EOF" ? new r("Unexpected end of input", this.lexer.location) : new r("Invalid location of '" + this.token.original_text + "'", this.lexer.location);
|
|
773
|
+
a = [
|
|
774
|
+
"_",
|
|
775
|
+
a,
|
|
776
|
+
e
|
|
777
|
+
];
|
|
778
|
+
}
|
|
779
|
+
for (; this.token.token_type === "'";) a = ["prime", a], this.advance();
|
|
780
|
+
if (this.token.token_type === "^" && (this.advance(), a = [
|
|
781
|
+
"^",
|
|
782
|
+
a,
|
|
783
|
+
this.factor({ parse_absolute_value: t })
|
|
784
|
+
]), this.token.token_type === "{" || this.token.token_type === "(") {
|
|
785
|
+
let e;
|
|
786
|
+
e = this.token.token_type === "{" ? "}" : ")", this.advance();
|
|
787
|
+
let t = this.statement_list();
|
|
788
|
+
if (this.token.token_type !== e) throw new r("Expecting " + e, this.lexer.location);
|
|
789
|
+
this.advance(), a = [
|
|
790
|
+
"apply",
|
|
791
|
+
a,
|
|
792
|
+
t
|
|
793
|
+
];
|
|
794
|
+
} else if (e) {
|
|
795
|
+
if (!this.opts.allowSimplifiedFunctionApplication) throw new r("Expecting ( after function", this.lexer.location);
|
|
796
|
+
a = [
|
|
797
|
+
"apply",
|
|
798
|
+
a,
|
|
799
|
+
this.factor({ parse_absolute_value: t })
|
|
800
|
+
];
|
|
801
|
+
}
|
|
802
|
+
} else this.advance();
|
|
803
|
+
} else if (this.token.token_type === "(" || this.token.token_type === "[" || this.token.token_type === "{" || this.token.token_type === "LBRACE") {
|
|
804
|
+
let e = this.token.token_type, t, n;
|
|
805
|
+
this.token.token_type === "(" ? (t = ")", n = "]") : this.token.token_type === "[" ? (t = "]", n = ")") : this.token.token_type === "{" ? (t = "}", n = null) : (t = "RBRACE", n = null), this.advance(), a = this.statement_list();
|
|
806
|
+
let i = 1;
|
|
807
|
+
if (a[0] === "list" && (i = a.length - 1), this.token.token_type !== t) {
|
|
808
|
+
if (i !== 2 || n === null) throw new r("Expecting " + t, this.lexer.location);
|
|
809
|
+
if (this.token.token_type !== n) throw new r("Expecting ) or ]", this.lexer.location);
|
|
810
|
+
a[0] = "list", a = ["interval", a];
|
|
811
|
+
let o;
|
|
812
|
+
o = e === "(" ? [
|
|
813
|
+
"list",
|
|
814
|
+
!1,
|
|
815
|
+
!0
|
|
816
|
+
] : [
|
|
817
|
+
"list",
|
|
818
|
+
!0,
|
|
819
|
+
!1
|
|
820
|
+
], a.push(o);
|
|
821
|
+
} else i >= 2 ? e === "(" || e === "{" || e === "[" ? a[0] = "list" : a[0] = "set" : e === "LBRACE" && (a = (a[0] === "|" || a[0], ["set", a]));
|
|
822
|
+
this.advance();
|
|
823
|
+
} else if (this.token.token_type[0] === "|" && t && (e === 0 || !n || this.token.token_type[1] === "L")) {
|
|
824
|
+
if (e += 1, this.advance(), a = this.statement({
|
|
825
|
+
inside_absolute_value: e,
|
|
826
|
+
unknownCommands: i
|
|
827
|
+
}), a = [
|
|
828
|
+
"apply",
|
|
829
|
+
"abs",
|
|
830
|
+
a
|
|
831
|
+
], this.token.token_type !== "|") throw new r("Expecting |", this.lexer.location);
|
|
832
|
+
this.advance();
|
|
833
|
+
}
|
|
834
|
+
if (this.token.token_type === "_") {
|
|
835
|
+
if (a === !1) throw new r("Invalid location of _", this.lexer.location);
|
|
836
|
+
this.advance();
|
|
837
|
+
let e = this.baseFactor({ parse_absolute_value: t });
|
|
838
|
+
if (e === !1) throw this.token.token_type === "EOF" ? new r("Unexpected end of input", this.lexer.location) : new r("Invalid location of '" + this.token.original_text + "'", this.lexer.location);
|
|
839
|
+
return [
|
|
840
|
+
"_",
|
|
841
|
+
a,
|
|
842
|
+
e
|
|
843
|
+
];
|
|
844
|
+
}
|
|
845
|
+
return a;
|
|
846
|
+
}
|
|
847
|
+
leibniz_notation() {
|
|
848
|
+
var e = this.token.token_text;
|
|
849
|
+
let t = "", n = 1, r = "", i = [], a = [];
|
|
850
|
+
if (this.token.token_type === "LATEXCOMMAND" && e.slice(1) === "partial") t = "∂";
|
|
851
|
+
else if (this.token.token_type === "VAR" && e === "d") t = "d";
|
|
852
|
+
else return !1;
|
|
853
|
+
if (this.advance(), this.token.token_type === "^") {
|
|
854
|
+
this.advance();
|
|
855
|
+
let e = !1;
|
|
856
|
+
if (this.token.token_type === "{" && (e = !0, this.advance()), this.token.token_type !== "NUMBER" || (n = parseFloat(this.token.token_text), !Number.isInteger(n)) || e && (this.advance(), this.token.token_type !== "}")) return !1;
|
|
857
|
+
this.advance();
|
|
858
|
+
}
|
|
859
|
+
if (this.token.token_type === "VAR") r = this.token.token_text;
|
|
860
|
+
else if (this.token.token_type === "VARMULTICHAR") r = /\\var\s*\{\s*([a-zA-Z0-9]+)\s*\}/.exec(this.token.token_text)[1];
|
|
861
|
+
else if (this.token.token_type === "LATEXCOMMAND") {
|
|
862
|
+
if (e = this.token.token_text.slice(1), this.opts.allowedLatexSymbols.includes(e)) r = e;
|
|
863
|
+
else return !1;
|
|
864
|
+
}
|
|
865
|
+
if (this.advance(), this.token.token_type !== "}" || (this.advance(), this.token.token_type !== "{")) return !1;
|
|
866
|
+
this.advance();
|
|
867
|
+
let o = 0;
|
|
868
|
+
for (;;) {
|
|
869
|
+
if (!(t === "d" && this.token.token_type === "VAR" && this.token.token_text === "d" || t === "∂" && this.token.token_type === "LATEXCOMMAND" && this.token.token_text.slice(1) === "partial")) return !1;
|
|
870
|
+
if (this.advance(), this.token.token_type === "VAR") i.push(this.token.token_text);
|
|
871
|
+
else if (this.token.token_type === "VARMULTICHAR") i.push(/\\var\s*\{\s*([a-zA-Z0-9]+)\s*\}/.exec(this.token.token_text)[1]);
|
|
872
|
+
else if (this.token.token_type === "LATEXCOMMAND") {
|
|
873
|
+
let e = this.token.token_text.slice(1);
|
|
874
|
+
if (this.allowedLatexSymbols.includes(e)) i.push(e);
|
|
875
|
+
else return !1;
|
|
876
|
+
} else return !1;
|
|
877
|
+
let s = 1;
|
|
878
|
+
if (this.advance(), this.token.token_type === "^") {
|
|
879
|
+
this.advance();
|
|
880
|
+
let e = !1;
|
|
881
|
+
if (this.token.token_type === "{" && (e = !0, this.advance()), this.token.token_type !== "NUMBER" || (s = parseFloat(this.token.token_text), !Number.isInteger(s)) || e && (this.advance(), this.token.token_type !== "}")) return !1;
|
|
882
|
+
this.advance();
|
|
883
|
+
}
|
|
884
|
+
if (a.push(s), o += s, o > n) return !1;
|
|
885
|
+
if (o === n) {
|
|
886
|
+
if (this.token.token_type !== "}") return !1;
|
|
887
|
+
this.advance();
|
|
888
|
+
let o = "derivative_leibniz";
|
|
889
|
+
t === "∂" && (o = "partial_" + o), e = [o], n === 1 ? e.push(r) : e.push([
|
|
890
|
+
"tuple",
|
|
891
|
+
r,
|
|
892
|
+
n
|
|
893
|
+
]);
|
|
894
|
+
let s = [];
|
|
895
|
+
for (let e = 0; e < i.length; e += 1) a[e] === 1 ? s.push(i[e]) : s.push([
|
|
896
|
+
"tuple",
|
|
897
|
+
i[e],
|
|
898
|
+
a[e]
|
|
899
|
+
]);
|
|
900
|
+
return s = ["tuple"].concat(s), e.push(s), e;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}, h = n(t, { number: "Fraction" }), { parse: te } = h;
|
|
905
|
+
h.replacer;
|
|
906
|
+
var g = n(t), _ = Object.freeze({
|
|
907
|
+
l: "tzn(n1, n2)",
|
|
908
|
+
r: "n1"
|
|
909
|
+
}), v = a("mv:ast-to-math"), y = h, b = {
|
|
910
|
+
"+": (e) => new y.OperatorNode("+", "add", e),
|
|
911
|
+
"*": (e) => {
|
|
912
|
+
let [t, n] = e;
|
|
913
|
+
if (t?.type === "ConstantNode" && n?.isUnit && typeof t.value == "object") {
|
|
914
|
+
let e = t.value.valueOf();
|
|
915
|
+
return y.multiply(e, n);
|
|
916
|
+
}
|
|
917
|
+
return new y.OperatorNode("*", "multiply", e);
|
|
918
|
+
},
|
|
919
|
+
"/": (e) => new y.OperatorNode("/", "divide", e),
|
|
920
|
+
"-": (e) => new y.OperatorNode("-", "unaryMinus", [e[0]]),
|
|
921
|
+
"^": (e) => new y.OperatorNode("^", "pow", e),
|
|
922
|
+
list: (e) => new y.ArrayNode(e),
|
|
923
|
+
vector: (e) => new y.ArrayNode(e),
|
|
924
|
+
and: (e) => new y.OperatorNode("and", "and", e),
|
|
925
|
+
or: (e) => new y.OperatorNode("or", "or", e),
|
|
926
|
+
not: (e) => new y.OperatorNode("not", "not", [e[0]]),
|
|
927
|
+
"<": (e) => new y.OperatorNode("<", "smaller", e),
|
|
928
|
+
">": (e) => new y.OperatorNode(">", "larger", e),
|
|
929
|
+
le: (e) => new y.OperatorNode("<=", "smallerEq", e),
|
|
930
|
+
ge: (e) => new y.OperatorNode(">=", "largerEq", e),
|
|
931
|
+
_: (e) => {
|
|
932
|
+
let [t, ...n] = e;
|
|
933
|
+
return new y.SymbolNode(`${t}[${n}]`);
|
|
934
|
+
},
|
|
935
|
+
ne: (e) => new y.OperatorNode("!=", "unequal", e),
|
|
936
|
+
tzn: (e) => new y.FunctionNode("tzn", e),
|
|
937
|
+
"≈": (e) => new y.FunctionNode("≈", e),
|
|
938
|
+
"≉": (e) => new y.FunctionNode("≉", e),
|
|
939
|
+
"~": (e) => new y.FunctionNode("~", e),
|
|
940
|
+
"≃": (e) => new y.FunctionNode("≃", e),
|
|
941
|
+
"≁": (e) => new y.FunctionNode("≁", e),
|
|
942
|
+
"≅": (e) => new y.FunctionNode("≅", e),
|
|
943
|
+
"≆": (e) => new y.FunctionNode("≆", e)
|
|
944
|
+
}, ne = class {
|
|
945
|
+
convert(e) {
|
|
946
|
+
if (typeof e == "number") {
|
|
947
|
+
if (Number.isFinite(e)) {
|
|
948
|
+
let t = new y.Fraction([new y.ConstantNode(e), new y.ConstantNode(1)]);
|
|
949
|
+
return new y.ConstantNode(t);
|
|
950
|
+
}
|
|
951
|
+
return Number.isNaN(e) ? new y.SymbolNode("NaN") : e < 0 ? b["-"]([new y.SymbolNode("Infinity")]) : new y.SymbolNode("Infinity");
|
|
952
|
+
}
|
|
953
|
+
if (typeof e == "string") return new y.SymbolNode(e);
|
|
954
|
+
if (typeof e == "boolean") throw Error("no support for boolean");
|
|
955
|
+
if (!Array.isArray(e)) throw Error("Invalid ast");
|
|
956
|
+
let t = e[0], n = e.slice(1);
|
|
957
|
+
if (t === "apply") {
|
|
958
|
+
if (v("operands:", n), v("0", n[0]), typeof n[0] != "string") throw Error("Non string functions not implemented for conversion to mathjs");
|
|
959
|
+
if (n[0] === "factorial") return new y.OperatorNode("!", "factorial", [this.convert(n[1])]);
|
|
960
|
+
let e = n[0], t = n[1], r;
|
|
961
|
+
return r = t[0] === "tuple" ? t.slice(1).map(function(e) {
|
|
962
|
+
return this.convert(e);
|
|
963
|
+
}.bind(this)) : [this.convert(t)], new y.FunctionNode(e, r);
|
|
964
|
+
}
|
|
965
|
+
if (t === "unit") return new y.Unit(1, n[0]);
|
|
966
|
+
if (t === "relational") {
|
|
967
|
+
let e = n[0], t = n[1];
|
|
968
|
+
if (e[0] !== "tuple" || t[0] !== "tuple") throw Error("Badly formed ast");
|
|
969
|
+
e.splice(0, 1), t.splice(0, 1);
|
|
970
|
+
let r = e.map(function(e) {
|
|
971
|
+
return this.convert(e);
|
|
972
|
+
}.bind(this)), i = [];
|
|
973
|
+
for (let n = 0; n < e.length - 1; n++) i.push(t[n]);
|
|
974
|
+
return new y.RelationalNode(i, r);
|
|
975
|
+
}
|
|
976
|
+
if (t === "=") {
|
|
977
|
+
let e = n.map(function(e) {
|
|
978
|
+
return this.convert(e);
|
|
979
|
+
}.bind(this)), t = [];
|
|
980
|
+
for (let n = 0; n < e.length - 1; n++) t.push("equal");
|
|
981
|
+
return t.length === 1 ? new y.OperatorNode("==", "equal", e) : new y.RelationalNode(t, e);
|
|
982
|
+
}
|
|
983
|
+
if (t === "in" || t === "notin" || t === "ni" || t === "notni") {
|
|
984
|
+
let e, r;
|
|
985
|
+
if (t === "in" || t === "notin" ? (e = n[0], r = n[1]) : (e = n[1], r = n[0]), typeof e != "number" && typeof e != "string") throw Error("Set membership non-string variables not implemented for conversion to mathjs");
|
|
986
|
+
if (e = this.convert(e), r[0] !== "interval") throw Error("Set membership in non-intervals not implemented for conversion to mathjs");
|
|
987
|
+
let i = r[1], a = r[2];
|
|
988
|
+
if (i[0] !== "tuple" || a[0] !== "tuple") throw Error("Badly formed ast");
|
|
989
|
+
let o = this.convert(i[1]), s = this.convert(i[2]), c = [];
|
|
990
|
+
a[1] ? c.push(new y.OperatorNode(">=", "largerEq", [e, o])) : c.push(new y.OperatorNode(">", "larger", [e, o])), a[2] ? c.push(new y.OperatorNode("<=", "smallerEq", [e, s])) : c.push(new y.OperatorNode("<", "smaller", [e, s]));
|
|
991
|
+
let l = new y.OperatorNode("and", "and", c);
|
|
992
|
+
return (t === "notin" || t === "notni") && (l = new y.OperatorNode("not", "not", [l])), l;
|
|
993
|
+
}
|
|
994
|
+
if (t === "subset" || t === "notsubset" || t === "superset" || t === "notsuperset") {
|
|
995
|
+
let e, r;
|
|
996
|
+
if (t === "subset" || t === "notsubset" ? (r = n[0], e = n[1]) : (r = n[1], e = n[0]), r[0] !== "interval" || e[0] !== "interval") throw Error("Set containment of non-intervals not implemented for conversion to mathjs");
|
|
997
|
+
let i = r[1], a = r[2], o = e[1], s = e[2];
|
|
998
|
+
if (i[0] !== "tuple" || a[0] !== "tuple" || o[0] !== "tuple" || s[0] !== "tuple") throw Error("Badly formed ast");
|
|
999
|
+
let c = this.convert(i[1]), l = this.convert(i[2]), u = this.convert(o[1]), d = this.convert(o[2]), f = [];
|
|
1000
|
+
a[1] && !s[1] ? f.push(new y.OperatorNode(">", "larger", [c, u])) : f.push(new y.OperatorNode(">=", "largerEq", [c, u])), a[2] && !s[2] ? f.push(new y.OperatorNode("<", "smaller", [l, d])) : f.push(new y.OperatorNode("<=", "smallerEq", [l, d]));
|
|
1001
|
+
let p = new y.OperatorNode("and", "and", f);
|
|
1002
|
+
return (t === "notsubset" || t === "notsuperset") && (p = new y.OperatorNode("not", "not", [p])), p;
|
|
1003
|
+
}
|
|
1004
|
+
if (t === "matrix") {
|
|
1005
|
+
let e = n[0], t = e[1], r = e[2], i = n[1];
|
|
1006
|
+
if (!Number.isInteger(t) || !Number.isInteger(r)) throw Error("Matrix must have integer dimensions");
|
|
1007
|
+
let a = [];
|
|
1008
|
+
for (let e = 1; e <= t; e++) {
|
|
1009
|
+
let t = [];
|
|
1010
|
+
for (let n = 1; n <= r; n++) t.push(this.convert(i[e][n]));
|
|
1011
|
+
a.push(new y.ArrayNode(t));
|
|
1012
|
+
}
|
|
1013
|
+
return new y.ArrayNode(a);
|
|
1014
|
+
}
|
|
1015
|
+
if (t === "%") {
|
|
1016
|
+
let e = this.convert(n[0]), t = new y.ConstantNode(100);
|
|
1017
|
+
return new y.OperatorNode("/", "divide", [e, t]);
|
|
1018
|
+
}
|
|
1019
|
+
if (t in b) return b[t](n.map(function(e) {
|
|
1020
|
+
return this.convert(e);
|
|
1021
|
+
}.bind(this)));
|
|
1022
|
+
throw Error("Operator " + t + " not implemented for conversion to mathjs");
|
|
1023
|
+
}
|
|
1024
|
+
}, re = h, x = a("mv:node-sort"), S = (e, t) => (x("[compareNodes]: a:", e.toString(), e.type), x("[compareNodes]: b:", t.toString(), t.type), e.isSymbolNode && t.isSymbolNode ? e.name.localeCompare(t.name) : e.isConstantNode && t.isConstantNode ? (x("a.value", e.value), x("b.value", t.value), e.value - t.value) : e.isConstantNode && !t.isConstantNode ? -1 : t.isConstantNode && !e.isConstantNode ? 1 : e.isSymbolNode && (t.isOperatorNode || t.isFunctionNode) ? -1 : t.isSymbolNode && (e.isOperatorNode || t.isFunctionNode) ? 1 : e.isOperatorNode && t.isOperatorNode ? -e.args.toString().localeCompare(t.args.toString()) : !e.isFunctionNode && t.isFunctionNode ? -1 : NaN), C = (e) => ((e.fn === "add" || e.fn === "multiply") && (e.args = e.args.sort(S), e.args = e.args.map(C)), e), w = (e, t) => {
|
|
1025
|
+
let n = !1;
|
|
1026
|
+
return e.forEach((e) => {
|
|
1027
|
+
e.fn === t && (n = !0);
|
|
1028
|
+
}), n;
|
|
1029
|
+
}, ie = (e) => {
|
|
1030
|
+
for (; e.isParenthesisNode && e.content;) e = e.content;
|
|
1031
|
+
e = e.transform((e, t, n) => {
|
|
1032
|
+
if (e.isParenthesisNode && (n?.op !== "*" || n?.op === "*" && e.content.op !== "+")) for (; e.isParenthesisNode;) e = e.content;
|
|
1033
|
+
return e;
|
|
1034
|
+
}), e.fn === "multiply" && e.implicit && (e.implicit = !1);
|
|
1035
|
+
let t = e;
|
|
1036
|
+
return t = t.transform((e) => {
|
|
1037
|
+
for (; w(e, e.fn) && !e.isArrayNode;) e.traverse((e, t, n) => {
|
|
1038
|
+
if (n?.fn === e.fn) {
|
|
1039
|
+
let r = t.replace(/[^0-9]/g, "");
|
|
1040
|
+
n.args.splice(+r, 1);
|
|
1041
|
+
let i = n.args;
|
|
1042
|
+
e.args.forEach((e) => {
|
|
1043
|
+
i.push(e);
|
|
1044
|
+
}), e = new re.OperatorNode(e.op, e.fn, i), e.fn === "multiply" && e.implicit && (e.implicit = !1);
|
|
1045
|
+
}
|
|
1046
|
+
return e;
|
|
1047
|
+
});
|
|
1048
|
+
return e;
|
|
1049
|
+
}), t = t.transform((e) => {
|
|
1050
|
+
if (e.fn === "multiply" && w(e.args, "divide")) {
|
|
1051
|
+
let t = e;
|
|
1052
|
+
if (t.fn === "multiply" && w(t, "divide")) {
|
|
1053
|
+
let e;
|
|
1054
|
+
return t = t.traverse((t, n, r) => {
|
|
1055
|
+
if (r && r.fn === "multiply" && t.fn === "divide") {
|
|
1056
|
+
if (t.args[0].isOperatorNode) r.args.forEach((e) => {
|
|
1057
|
+
e.isOperatorNode || t.args[0].args.push(e);
|
|
1058
|
+
});
|
|
1059
|
+
else {
|
|
1060
|
+
let e = [];
|
|
1061
|
+
e.push(t.args[0]), r.args.forEach((t) => {
|
|
1062
|
+
t.isOperatorNode || e.push(t);
|
|
1063
|
+
}), t.args[0] = new re.OperatorNode("*", "multiply", e);
|
|
1064
|
+
}
|
|
1065
|
+
e = t;
|
|
1066
|
+
}
|
|
1067
|
+
}), e;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return e;
|
|
1071
|
+
}), t;
|
|
1072
|
+
}, ae = (e) => {
|
|
1073
|
+
x("THIS IS THE START ++++", JSON.stringify(e));
|
|
1074
|
+
let t = ["smaller", "smallerEq"], n = ["larger", "largerEq"];
|
|
1075
|
+
return e.transform((e, r, i) => {
|
|
1076
|
+
let a = !1;
|
|
1077
|
+
if (e.conditionals) {
|
|
1078
|
+
let r = t.some((t) => e.conditionals.includes(t)) && n.some((t) => e.conditionals.includes(t));
|
|
1079
|
+
e.conditionals.includes("equal") ? e.params.sort(S) : r && e.params ? S(e.params[0], e.params[e.params.length - 1]) > -1 && e.params.reverse() : e.conditionals = e.conditionals.map((e) => (e === "smaller" ? (a = !0, e = "larger") : e === "smallerEq" && (a = !0, e = "largerEq"), e));
|
|
1080
|
+
}
|
|
1081
|
+
return e.params && a && (e.conditionals.reverse(), e.params.reverse()), i && i.type === "RelationalNode" && e.args && (e = T(e)), e;
|
|
1082
|
+
});
|
|
1083
|
+
}, T = (e) => {
|
|
1084
|
+
let t = e;
|
|
1085
|
+
return e.type === "RelationalNode" ? ae(e) : (e.isOperatorNode && e.fn === "smaller" && (e.op = ">", e.fn = "larger", e.args = e.args.reverse()), e.isOperatorNode && e.fn === "smallerEq" && (e.op = ">=", e.fn = "largerEq", e.args = e.args.reverse()), e.isFunctionNode && e.fn.name.match("=|NE|≃|≈|≈|≉|~|≃|≁|≅|≆") && (e.args = e.args.sort(S)), e.isOperatorNode && (e.fn === "larger" || e.fn === "largerEq" || e.fn === "equal" || e.fn === "unequal") && (e.args = e.args.map(T), (e.fn === "equal" || e.fn === "unequal") && (e.args = e.args.sort(S))), e.isArrayNode ? (e.items = e.items.sort(S), e) : (t = ie(e).transform(C), t));
|
|
1086
|
+
}, oe = [...Object.freeze([
|
|
1087
|
+
{
|
|
1088
|
+
l: "n1^(1/n2)",
|
|
1089
|
+
r: "nthRoot(n1, n2)"
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
l: "sqrt(n1)",
|
|
1093
|
+
r: "nthRoot(n1, 2)"
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
l: "nthRoot(-1, 2)",
|
|
1097
|
+
r: "i"
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
l: "(v1-v2)/n",
|
|
1101
|
+
r: "v1/n-v2/n"
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
l: "(v1-n)/n",
|
|
1105
|
+
r: "v1/n-1"
|
|
1106
|
+
},
|
|
1107
|
+
{
|
|
1108
|
+
l: "n/n1-c1",
|
|
1109
|
+
r: "(n-c1*n1)/n1"
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
l: "i^2",
|
|
1113
|
+
r: "-1"
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
l: "pi",
|
|
1117
|
+
r: "3.141592653589793"
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
l: "n/(n*n1)",
|
|
1121
|
+
r: "1/n1"
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
l: "c1/(c2*(n3))",
|
|
1125
|
+
r: "(c1/c2)*(1/n3)"
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
l: "n1/(n(n+1)+1(n+1))",
|
|
1129
|
+
r: "n1/((n+1)^2)"
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
l: "(n1 + n2) ^ 2",
|
|
1133
|
+
r: "(n1 ^ 2) + 2*n1*n2 + (n2 ^ 2)"
|
|
1134
|
+
},
|
|
1135
|
+
_,
|
|
1136
|
+
{
|
|
1137
|
+
l: "n1/(-n2)",
|
|
1138
|
+
r: "-(n1/n2)"
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
l: "sin(n*pi)",
|
|
1142
|
+
r: "0"
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
l: "log(n1*n2, n3)",
|
|
1146
|
+
r: "log(n1, n3)+log(n2,n3)"
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
l: "log(n1/n2, n3)",
|
|
1150
|
+
r: "log(n1, n3)-log(n2,n3)"
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
l: "log(n1^n2, n3)",
|
|
1154
|
+
r: "n2*log(n1,n3)"
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
l: "sin(n)/cos(n)",
|
|
1158
|
+
r: "tan(n)"
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
l: "csc(n)",
|
|
1162
|
+
r: "1/sin(n)"
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
l: "sec(n)",
|
|
1166
|
+
r: "1/cos(n)"
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
l: "cot(n)",
|
|
1170
|
+
r: "1/tan(n)",
|
|
1171
|
+
r1: "cos(n)/sin(n)"
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
l: "1/tan(n)",
|
|
1175
|
+
r: "cos(n)/sin(n)"
|
|
1176
|
+
},
|
|
1177
|
+
{
|
|
1178
|
+
l: "n1 == asin(n)",
|
|
1179
|
+
r: "n == sin(n1)"
|
|
1180
|
+
},
|
|
1181
|
+
{
|
|
1182
|
+
l: "n1 == acos(n)",
|
|
1183
|
+
r: "n == cos(n1)"
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
l: "n1 == atan(n)",
|
|
1187
|
+
r: "n == tan(n1)"
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
l: "n1 == acot(n)",
|
|
1191
|
+
r: "n == cot(n1)"
|
|
1192
|
+
},
|
|
1193
|
+
{
|
|
1194
|
+
l: "n1 == asec(n)",
|
|
1195
|
+
r: "n == sec(n1)"
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
l: "n1 == acsc(n)",
|
|
1199
|
+
r: "n == csc(n1)"
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
l: "sin(asin(n))",
|
|
1203
|
+
r: "n"
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
l: "cos(acos(n))",
|
|
1207
|
+
r: "n"
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
l: "tan(atan(n))",
|
|
1211
|
+
r: "n"
|
|
1212
|
+
},
|
|
1213
|
+
{
|
|
1214
|
+
l: "sin(acsc(n))",
|
|
1215
|
+
r: "1/n"
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
l: "cos(asec(n))",
|
|
1219
|
+
r: "1/n"
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
l: "tan(acot(n))",
|
|
1223
|
+
r: "1/n"
|
|
1224
|
+
}
|
|
1225
|
+
]), ...h.simplify.rules], E = (e) => h.simplify(e, oe), D = h, se = Object.freeze([
|
|
1226
|
+
{
|
|
1227
|
+
l: "-((n1)*(n2))",
|
|
1228
|
+
r: "(n1)*(n2)"
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
l: "(n1-n2)/n3",
|
|
1232
|
+
r: "n1/n3-n2/n3"
|
|
1233
|
+
},
|
|
1234
|
+
{
|
|
1235
|
+
l: "(n1+n2)/n3",
|
|
1236
|
+
r: "n1/n3+n2/n3"
|
|
1237
|
+
},
|
|
1238
|
+
{
|
|
1239
|
+
l: "(n1-n2)*n3/n4",
|
|
1240
|
+
r: "(n1*n3)/n4-(n2*n3)/n4"
|
|
1241
|
+
},
|
|
1242
|
+
{
|
|
1243
|
+
l: "(n1+n2)*n3/n4",
|
|
1244
|
+
r: "(n1*n3)/n4+(n2*n3)/n4"
|
|
1245
|
+
}
|
|
1246
|
+
]), ce = Object.freeze([...se, {
|
|
1247
|
+
l: "-(n)",
|
|
1248
|
+
r: "n"
|
|
1249
|
+
}]), O = (e) => Math.round(e * 0x9184e72a000) / 0x9184e72a000, le = (e, t) => {
|
|
1250
|
+
let n = !0, r = !1, i = !1, a = !1;
|
|
1251
|
+
return e.traverse((e) => {
|
|
1252
|
+
e.isSymbolNode && (r = !0, a ||= e.name.includes("[")), n = n || !!e.isFunctionNode || !!e.isArrayNode;
|
|
1253
|
+
}), t.traverse((e) => {
|
|
1254
|
+
(e.isFunctionNode || e.isArrayNode) && (n = !1), e.isSymbolNode && r && (i = !0);
|
|
1255
|
+
}), n && i && !a;
|
|
1256
|
+
}, ue = (e) => {
|
|
1257
|
+
let t = !1;
|
|
1258
|
+
return e.traverse((e) => {
|
|
1259
|
+
e.isOperatorNode && e.op === "^" && !e.args[1]?.isConstantNode && (t = !0);
|
|
1260
|
+
}), t;
|
|
1261
|
+
}, de = (e) => () => {
|
|
1262
|
+
e = e + 1831565813 | 0;
|
|
1263
|
+
let t = Math.imul(e ^ e >>> 15, 1 | e);
|
|
1264
|
+
return t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t, ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
1265
|
+
}, fe = (e, t = 12) => {
|
|
1266
|
+
let n = de(443);
|
|
1267
|
+
return Array.from({ length: t }, () => e.reduce((e, t) => {
|
|
1268
|
+
let r = .5 + 4 * n();
|
|
1269
|
+
return e[t] = n() < .5 ? -r : r, e;
|
|
1270
|
+
}, {}));
|
|
1271
|
+
}, k = (e, t) => {
|
|
1272
|
+
let n;
|
|
1273
|
+
try {
|
|
1274
|
+
n = g.compile(e.toString());
|
|
1275
|
+
} catch {
|
|
1276
|
+
return t.map(() => NaN);
|
|
1277
|
+
}
|
|
1278
|
+
return t.map((e) => {
|
|
1279
|
+
try {
|
|
1280
|
+
let t = n.evaluate({ ...e });
|
|
1281
|
+
return typeof t == "number" ? t : NaN;
|
|
1282
|
+
} catch {
|
|
1283
|
+
return NaN;
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
}, A = (e, t, n) => Math.abs(e - t) <= n * Math.max(1, Math.abs(e), Math.abs(t)), pe = (e, t, n, r = 1e-10) => {
|
|
1287
|
+
let i = fe(n), a = k(e, i), o = k(t, i);
|
|
1288
|
+
return a.filter((e, t) => Number.isFinite(e) && Number.isFinite(o[t])).length >= 3 && a.every((e, t) => !Number.isFinite(e) || !Number.isFinite(o[t]) || A(e, o[t], r));
|
|
1289
|
+
}, me = (e, t) => e.reduce((e, n) => e.reduce((e, r) => e.concat(Array.from({ length: 2 * t + 1 }, (e, i) => ({
|
|
1290
|
+
...r,
|
|
1291
|
+
[n]: i - t
|
|
1292
|
+
}))), []), [{}]), j = (e, t, n, { allowVariableFactor: r = !1, positiveOnly: i = !1 } = {}) => {
|
|
1293
|
+
let a = 1e-9, o = fe(n), s = k(e, o), c = k(t, o), l = [];
|
|
1294
|
+
for (let e = 0; e < o.length; e++) {
|
|
1295
|
+
let t = s[e], n = c[e];
|
|
1296
|
+
if (!Number.isFinite(t) || !Number.isFinite(n)) continue;
|
|
1297
|
+
let r = Math.abs(t) < a, i = Math.abs(n) < a;
|
|
1298
|
+
if (!(r && i)) {
|
|
1299
|
+
if (r || i) return !1;
|
|
1300
|
+
l.push({
|
|
1301
|
+
point: o[e],
|
|
1302
|
+
ratio: t / n
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
return l.length < 3 ? !1 : (r ? me(n, 2).filter((e) => !i || Object.values(e).every((e) => e % 2 == 0)) : [{}]).some((e) => {
|
|
1307
|
+
let t = l.map(({ point: t, ratio: n }) => Object.keys(e).reduce((n, r) => n / t[r] ** e[r], n));
|
|
1308
|
+
return (!i || t[0] > 0) && t.every((e) => A(e, t[0], a));
|
|
1309
|
+
});
|
|
1310
|
+
}, he = 4, ge = 60, _e = (e) => {
|
|
1311
|
+
let t = 0, n = !1;
|
|
1312
|
+
return e.traverse((e) => {
|
|
1313
|
+
t++, n ||= e.isOperatorNode && e.op === "^" && e.args[1]?.isConstantNode && Math.abs(Number(e.args[1].value)) > he;
|
|
1314
|
+
}), n || t > ge;
|
|
1315
|
+
}, M = (e) => {
|
|
1316
|
+
if (!_e(e)) try {
|
|
1317
|
+
let { numerator: t, denominator: n } = g.rationalize(e.toString(), {}, !0);
|
|
1318
|
+
return n ? t : void 0;
|
|
1319
|
+
} catch {
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
}, N = (e, t, n, r = {}) => {
|
|
1323
|
+
if (j(e, t, n, r)) return !0;
|
|
1324
|
+
if (r.positiveOnly) return !1;
|
|
1325
|
+
let i = M(e), a = M(t);
|
|
1326
|
+
return (i !== void 0 || a !== void 0) && j(i || e, a || t, n, r);
|
|
1327
|
+
}, P = (e) => E(new D.OperatorNode("-", "subtract", e.args)), F = (e) => {
|
|
1328
|
+
let t = [];
|
|
1329
|
+
return e.traverse((e) => {
|
|
1330
|
+
e.isSymbolNode && e.name.length === 1 && !t.includes(e.name) && t.push(e.name);
|
|
1331
|
+
}), t.sort();
|
|
1332
|
+
}, I = (e, t) => {
|
|
1333
|
+
try {
|
|
1334
|
+
let t = D.rationalize(e, {}, !0).coefficients;
|
|
1335
|
+
return t.every((e) => e < 0) ? t.map((e) => Math.abs(e)) : t;
|
|
1336
|
+
} catch {
|
|
1337
|
+
e = D.simplify(e, t ? [...se] : [...ce]);
|
|
1338
|
+
try {
|
|
1339
|
+
return D.rationalize(e, {}, !0).coefficients;
|
|
1340
|
+
} catch {}
|
|
1341
|
+
}
|
|
1342
|
+
return [1, 0];
|
|
1343
|
+
}, L = (e) => {
|
|
1344
|
+
let [t, n, r] = e, i = n * n - 4 * r * t, a, o;
|
|
1345
|
+
try {
|
|
1346
|
+
a = D.compile(D.fraction(-n + D.sqrt(i)) / (2 * r));
|
|
1347
|
+
} catch {
|
|
1348
|
+
a = D.compile("(-b+sqrt(discriminant))/(2*a)");
|
|
1349
|
+
}
|
|
1350
|
+
try {
|
|
1351
|
+
o = D.compile(D.fraction(-n - D.sqrt(i)) / (2 * r));
|
|
1352
|
+
} catch {
|
|
1353
|
+
o = D.compile("(-b-sqrt(discriminant))/(2*a)");
|
|
1354
|
+
}
|
|
1355
|
+
let s = a.evaluate({
|
|
1356
|
+
discriminant: i,
|
|
1357
|
+
a: r,
|
|
1358
|
+
b: n
|
|
1359
|
+
}), c = o.evaluate({
|
|
1360
|
+
discriminant: i,
|
|
1361
|
+
a: r,
|
|
1362
|
+
b: n
|
|
1363
|
+
});
|
|
1364
|
+
return s.im ? [{
|
|
1365
|
+
re: O(s.re),
|
|
1366
|
+
im: O(s.im)
|
|
1367
|
+
}, {
|
|
1368
|
+
re: O(c.re),
|
|
1369
|
+
im: O(c.im)
|
|
1370
|
+
}] : (s = O(s), c = O(c), [{
|
|
1371
|
+
re: s,
|
|
1372
|
+
im: 0
|
|
1373
|
+
}, {
|
|
1374
|
+
re: c,
|
|
1375
|
+
im: 0
|
|
1376
|
+
}]);
|
|
1377
|
+
}, R = (e) => {
|
|
1378
|
+
let t;
|
|
1379
|
+
if (e) {
|
|
1380
|
+
if (e.length === 3 && e[0] === 0 && (e = e.splice(1, 2)), e.length === 2) {
|
|
1381
|
+
if (e[0] === 0 && e[1] === 0) return Infinity;
|
|
1382
|
+
if (e[0] === 0) return 0;
|
|
1383
|
+
t = O(D.divide(e[0], -1 * e[1]));
|
|
1384
|
+
}
|
|
1385
|
+
return t;
|
|
1386
|
+
}
|
|
1387
|
+
}, z = (e, t) => Array.isArray(e) && Array.isArray(t) && e.length === t.length && e.every((e, n) => e === t[n]), B = h, V = (e, t, n) => {
|
|
1388
|
+
let r = !1;
|
|
1389
|
+
if (le(e, t)) {
|
|
1390
|
+
let i = P(e), a = P(t);
|
|
1391
|
+
if (i.equals(a)) return !0;
|
|
1392
|
+
let o = F(i);
|
|
1393
|
+
if (!z(o, F(a))) return !1;
|
|
1394
|
+
let s, c;
|
|
1395
|
+
if (ue(i) || ue(a)) return pe(i, a, o);
|
|
1396
|
+
if (o.length === 1) {
|
|
1397
|
+
if (s = I(i, n), c = I(a, n), z(s, c)) return !0;
|
|
1398
|
+
if (s.length === 3 && c.length === 3 && !n && s[0] !== 0 || s.length === 4 && s[0] === 0 && c[0] === 0) {
|
|
1399
|
+
s[0] === 0 && (s = s.splice(1, 3), c = c.splice(1, 3));
|
|
1400
|
+
let e = L(s), t = L(c), n = B.complex(e), r = B.complex(t);
|
|
1401
|
+
return e[0].im === 0 && e[1].im === 0 ? n[0].equals(r[0]) && n[1].equals(r[1]) || n[0].equals(r[1]) && n[1].equals(r[0]) : e[0].re === t[0].re && e[1].re === t[1].re && e[0].im.toFixed(13) === t[0].im.toFixed(13) && e[1].im.toFixed(13) === t[1].im.toFixed(13);
|
|
1402
|
+
}
|
|
1403
|
+
let e = R(s), t = R(c);
|
|
1404
|
+
if (r = e === t && e !== void 0, !n && (e === void 0 || t === void 0)) return N(i, a, o);
|
|
1405
|
+
}
|
|
1406
|
+
if (o.length === 2) return N(i, a, o, {
|
|
1407
|
+
allowVariableFactor: !0,
|
|
1408
|
+
positiveOnly: n
|
|
1409
|
+
});
|
|
1410
|
+
if (r && n) return !(B.isPositive(s[0]) && B.isNegative(s[1]) && B.isNegative(c[0]) && B.isPositive(c[1]) || B.isNegative(s[0]) && B.isPositive(s[1]) && B.isPositive(c[0]) && B.isNegative(c[1]));
|
|
1411
|
+
}
|
|
1412
|
+
return r;
|
|
1413
|
+
}, H = h, U = (e) => {
|
|
1414
|
+
switch (e) {
|
|
1415
|
+
case "smaller": return "<";
|
|
1416
|
+
case "smallerEq": return "<=";
|
|
1417
|
+
case "larger": return ">";
|
|
1418
|
+
case "largerEq": return ">=";
|
|
1419
|
+
case "equal": return "==";
|
|
1420
|
+
case "unequal": return "!=";
|
|
1421
|
+
}
|
|
1422
|
+
}, W = (e) => ({
|
|
1423
|
+
left: new H.OperatorNode(U(e.conditionals[0]), e.conditionals[0], [e.params[0], e.params[1]]),
|
|
1424
|
+
right: new H.OperatorNode(U(e.conditionals[1]), e.conditionals[1], [e.params[1], e.params[2]])
|
|
1425
|
+
}), G = (e) => R(I(P(e), !0)), ve = ({ left: e, right: t }) => {
|
|
1426
|
+
let n = G(t), r = G(e);
|
|
1427
|
+
return {
|
|
1428
|
+
min: Math.min(n, r),
|
|
1429
|
+
max: Math.max(n, r)
|
|
1430
|
+
};
|
|
1431
|
+
}, ye = (e, t) => {
|
|
1432
|
+
if (!le(e, t)) return !1;
|
|
1433
|
+
let n = F(e);
|
|
1434
|
+
if (!z(n, F(t)) && n?.length === 1) return !1;
|
|
1435
|
+
let r = W(e), i = W(t), a = ve(r), o = ve(i);
|
|
1436
|
+
return a.min === o.min && a.max === o.max;
|
|
1437
|
+
}, K = h, q = a("mv:symbolic"), { rationalize: be } = h, xe = 1e-9, Se = 1e-13, Ce = 1e-14, we = (e, t) => {
|
|
1438
|
+
let n = !1;
|
|
1439
|
+
return e.traverse((e, r) => {
|
|
1440
|
+
n ||= e.isSymbolNode && r !== "fn" && t(e.name);
|
|
1441
|
+
}), n;
|
|
1442
|
+
}, Te = (e) => {
|
|
1443
|
+
if (!we(e, (e) => e !== "pi" && e !== "Infinity")) try {
|
|
1444
|
+
let t = g.evaluate(e.toString());
|
|
1445
|
+
return typeof t == "number" ? t : void 0;
|
|
1446
|
+
} catch {
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
}, Ee = (e) => {
|
|
1450
|
+
let t = Te(e);
|
|
1451
|
+
if (t === void 0 || !isFinite(t)) return;
|
|
1452
|
+
let n = t / (Math.PI / 2), r = Math.round(n);
|
|
1453
|
+
return Math.abs(n - r) <= xe * Math.max(1, Math.abs(r)) ? r : void 0;
|
|
1454
|
+
}, De = (e) => {
|
|
1455
|
+
let t = !1, n = e.transform((e) => {
|
|
1456
|
+
if (!e.isFunctionNode || e.args?.length !== 1) return e;
|
|
1457
|
+
let n = Ee(e.args[0]);
|
|
1458
|
+
if (n === void 0) return e;
|
|
1459
|
+
let r = Math.abs(n) % 2 == 1, i = e;
|
|
1460
|
+
switch (e.fn.name) {
|
|
1461
|
+
case "sin":
|
|
1462
|
+
i = r ? e : new K.ConstantNode(0);
|
|
1463
|
+
break;
|
|
1464
|
+
case "cos":
|
|
1465
|
+
i = r ? new K.ConstantNode(0) : e;
|
|
1466
|
+
break;
|
|
1467
|
+
case "tan":
|
|
1468
|
+
i = r ? new K.SymbolNode("Infinity") : new K.ConstantNode(0);
|
|
1469
|
+
break;
|
|
1470
|
+
case "cot":
|
|
1471
|
+
i = r ? new K.ConstantNode(0) : new K.SymbolNode("Infinity");
|
|
1472
|
+
break;
|
|
1473
|
+
case "sec":
|
|
1474
|
+
i = r ? new K.SymbolNode("Infinity") : e;
|
|
1475
|
+
break;
|
|
1476
|
+
case "csc": i = r ? e : new K.SymbolNode("Infinity");
|
|
1477
|
+
}
|
|
1478
|
+
return t ||= i !== e, i;
|
|
1479
|
+
});
|
|
1480
|
+
return {
|
|
1481
|
+
r: t ? n : e,
|
|
1482
|
+
changed: t
|
|
1483
|
+
};
|
|
1484
|
+
}, J = (e) => {
|
|
1485
|
+
let t = De(e), n = t.r, r = t.changed ? Te(n) : void 0, i = r !== void 0 && (!isFinite(r) || we(n, (e) => e === "Infinity")) ? r : void 0, a = !0, o = !1, s = !1, c = !1, l = !1;
|
|
1486
|
+
if (n.traverse((e) => {
|
|
1487
|
+
e.isArrayNode && (s = !0, e.items = e.items.map((e) => E(e))), e.isSymbolNode && (c ||= e.name === "pi", l ||= e.name === "f^{-1}");
|
|
1488
|
+
}), n.args && (n.args = n.args.map((e) => {
|
|
1489
|
+
if (!e.isFunctionNode && !e.isArrayNode && !l && !c) try {
|
|
1490
|
+
e = E(e);
|
|
1491
|
+
} catch {}
|
|
1492
|
+
return o ||= e.isFunctionNode, a &&= !!e.isConstantNode, e;
|
|
1493
|
+
}), (o || l) && (n.args = n.args.map((e) => {
|
|
1494
|
+
if (!e.isFunctionNode && !e.isArrayNode) try {
|
|
1495
|
+
e = be(E(e), {}, !0).expression;
|
|
1496
|
+
} catch {}
|
|
1497
|
+
return e;
|
|
1498
|
+
}))), n.fn !== "equal") try {
|
|
1499
|
+
a = !1, n = be(n, {}, !0).expression;
|
|
1500
|
+
} catch {}
|
|
1501
|
+
if (n.conditionals && n.params && (n.params = n.params.map((e) => T(E(e)))), !s && !a) try {
|
|
1502
|
+
n = E(n);
|
|
1503
|
+
} catch {}
|
|
1504
|
+
return q("[normalize] input: ", e.toString(), "output: ", n.toString()), i !== void 0 && (n = isNaN(i) ? new K.SymbolNode("NaN") : isFinite(i) ? new K.ConstantNode(i) : new K.SymbolNode("Infinity")), n.toString() === "Infinity" && (n = new K.SymbolNode("Infinity")), n;
|
|
1505
|
+
}, Oe = (e) => {
|
|
1506
|
+
if (!(e.filter((e) => e.isSymbolNode).length > 0)) try {
|
|
1507
|
+
let t = e.evaluate();
|
|
1508
|
+
if (typeof t == "boolean") return;
|
|
1509
|
+
let n = +t;
|
|
1510
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1511
|
+
} catch {
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
}, ke = (e, t) => Math.abs(e - t) < Ce + Se * Math.max(Math.abs(e), Math.abs(t)), Ae = (e) => e?.isSymbolNode && e.name === "NaN", je = (e, t) => {
|
|
1515
|
+
let n, r;
|
|
1516
|
+
if (e?.isUnit && t?.isUnit) try {
|
|
1517
|
+
return K.equal(e, t);
|
|
1518
|
+
} catch (n) {
|
|
1519
|
+
return q("[isMathEqual] Error comparing units:", e?.toString?.(), t?.toString?.(), n), !1;
|
|
1520
|
+
}
|
|
1521
|
+
if (e?.isUnit || t?.isUnit) return q("[isMathEqual] Mismatched unit comparison:", e?.toString?.(), t?.toString?.()), !1;
|
|
1522
|
+
if (n = e.conditionals ? J(e) : T(J(e)), r = t.conditionals ? J(t) : T(J(t)), q("[isMathEqual]", n.toString(), "==?", r.toString()), Ae(n) || Ae(r)) return !1;
|
|
1523
|
+
let i = T(e).equals(T(t)), a = n.toTex().trim() === r.toTex().trim() || n.equals(r) || i;
|
|
1524
|
+
if (a) return !0;
|
|
1525
|
+
let o = Oe(n), s = Oe(r);
|
|
1526
|
+
if (o !== void 0 && s !== void 0) return ke(o, s);
|
|
1527
|
+
if (n.fn === "equal" && r.fn === "equal") return V(n, r, !1);
|
|
1528
|
+
if (n.fn === "larger" && r.fn === "larger" || n.fn === "largerEq" && r.fn === "largerEq") return n.fn = "equal", r.fn = "equal", n.op = "=", r.op = "=", V(n, r, !0);
|
|
1529
|
+
if (n?.conditionals?.length === r?.conditionals?.length && n?.conditionals?.length === 2 && n?.conditionals?.toString() === r?.conditionals?.toString()) {
|
|
1530
|
+
let e = [
|
|
1531
|
+
"smaller",
|
|
1532
|
+
"smallerEq",
|
|
1533
|
+
"larger",
|
|
1534
|
+
"largerEq",
|
|
1535
|
+
"equal",
|
|
1536
|
+
"unequal"
|
|
1537
|
+
], t = e.some((e) => n.conditionals.includes(e)), i = e.some((e) => r.conditionals.includes(e));
|
|
1538
|
+
if (t && i) return ye(n, r);
|
|
1539
|
+
}
|
|
1540
|
+
return a;
|
|
1541
|
+
}, { simplify: Me } = h, Ne = (e, t, n) => (n && n.allowTrailingZeros && (e = Me(e, [_]), t = Me(t, [_])), n && n.ignoreOrder && (e = T(e), t = T(t)), e.equals(t)), Pe = a("mv:difference"), Fe = (e, t) => {
|
|
1542
|
+
let n = Math.min(e.toString().length, t.toString().length), r = Math.max(e.toString().length, t.toString().length), i = 1 / n * 100 + 10 + 17, a = r - n;
|
|
1543
|
+
return Pe("a:", e.toString(), "b:", t.toString(), "limit:", i, "diff:", a), a > i;
|
|
1544
|
+
}, Ie = new m({ keepMixedNumbers: !0 }), Le = (e, t) => t === 0 ? Math.abs(e) : Le(t, e % t), Y = (e, t) => {
|
|
1545
|
+
if (!Number.isFinite(e) || !Number.isFinite(t) || t === 0) return;
|
|
1546
|
+
let n = Le(e, t) || 1, r = t < 0 ? -1 : 1;
|
|
1547
|
+
return {
|
|
1548
|
+
n: r * e / n,
|
|
1549
|
+
d: r * t / n
|
|
1550
|
+
};
|
|
1551
|
+
}, X = (e) => e && {
|
|
1552
|
+
n: -e.n,
|
|
1553
|
+
d: e.d
|
|
1554
|
+
}, Re = (e, t) => e && t && t.n !== 0 ? Y(e.n * t.d, e.d * t.n) : void 0, Z = (e, t, n) => Array.isArray(e) && e[0] === t && e.length === n + 1, Q = (e) => {
|
|
1555
|
+
let t = Z(e, "tzn", 2) ? e[1] : e;
|
|
1556
|
+
if (typeof t != "number" || !Number.isFinite(t) || t < 0) return;
|
|
1557
|
+
let n = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(t));
|
|
1558
|
+
if (!n) return;
|
|
1559
|
+
let [, r, i = "", a = "0"] = n, o = Number(r + i), s = Number(a) - i.length;
|
|
1560
|
+
return s >= 0 ? Y(o * 10 ** s, 1) : Y(o, 10 ** -s);
|
|
1561
|
+
}, $ = (e) => typeof e == "number" && Number.isInteger(e) ? Q(e) : void 0, ze = (e) => Z(e, "-", 1) ? X(Q(e[1])) : Q(e), Be = (e) => {
|
|
1562
|
+
if (Z(e, "/", 2)) return Re(ze(e[1]), ze(e[2]));
|
|
1563
|
+
if (Z(e, "mixed", 2) && Z(e[2], "/", 2)) {
|
|
1564
|
+
let t = $(e[1]), n = Re($(e[2][1]), $(e[2][2]));
|
|
1565
|
+
return t && n && Y(t.n * n.d + n.n, n.d);
|
|
1566
|
+
}
|
|
1567
|
+
return Q(e);
|
|
1568
|
+
}, Ve = (e) => {
|
|
1569
|
+
if (typeof e != "string" || !e.trim()) return;
|
|
1570
|
+
let t;
|
|
1571
|
+
try {
|
|
1572
|
+
t = Ie.convert(e);
|
|
1573
|
+
} catch {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
return Z(t, "-", 1) ? X(Be(t[1])) : Be(t);
|
|
1577
|
+
}, He = (e, t) => {
|
|
1578
|
+
let n = Ve(e), r = Ve(t);
|
|
1579
|
+
if (n || r) return !!n && !!r && n.n === r.n && n.d === r.d;
|
|
1580
|
+
}, Ue = new m(), We = new ne(), Ge = (e, t, n) => {
|
|
1581
|
+
let r = (e) => /^\s*-?\d+(\.\d+)?\s*$/.test(e);
|
|
1582
|
+
if (!e || !t) return !1;
|
|
1583
|
+
if (e === t) return !0;
|
|
1584
|
+
if (n.mode === "literal" && n.literal?.compareNumbersByValue) {
|
|
1585
|
+
let n = He(e, t);
|
|
1586
|
+
if (n !== void 0) return n;
|
|
1587
|
+
}
|
|
1588
|
+
if (n.mode === "symbolic" && r(e) && r(t) && parseFloat(e) === parseFloat(t)) return !0;
|
|
1589
|
+
let i = Ue.convert(e), a = Ue.convert(t);
|
|
1590
|
+
if (Fe(i, a)) return !1;
|
|
1591
|
+
let o = We.convert(i), s = We.convert(a);
|
|
1592
|
+
return n.mode === "literal" ? Ne(o, s, n.literal) : je(o, s);
|
|
1593
|
+
};
|
|
1594
|
+
export { Ge as latexEqual };
|