@cortex-js/compute-engine 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compute-engine.esm.js +730 -131
- package/dist/compute-engine.js +730 -131
- package/dist/compute-engine.min.esm.js +730 -131
- package/dist/compute-engine.min.js +730 -131
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +4 -2
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.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-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +4 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +37 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +6 -2
- 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 +5 -2
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +2 -0
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -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/public.d.ts +1 -1
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +2 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +1 -1
package/dist/compute-engine.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** CortexJS Compute Engine 0.
|
|
1
|
+
/** CortexJS Compute Engine 0.15.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
var ComputeEngine = (() => {
|
|
4
4
|
var __create = Object.create;
|
|
@@ -3427,7 +3427,7 @@ var ComputeEngine = (() => {
|
|
|
3427
3427
|
var decimal_default = Decimal;
|
|
3428
3428
|
|
|
3429
3429
|
// src/compute-engine/compute-engine.ts
|
|
3430
|
-
var
|
|
3430
|
+
var import_complex20 = __toESM(require_complex());
|
|
3431
3431
|
|
|
3432
3432
|
// src/common/grapheme-splitter.ts
|
|
3433
3433
|
function stringToCodepoints(string) {
|
|
@@ -4291,7 +4291,7 @@ var ComputeEngine = (() => {
|
|
|
4291
4291
|
if (name === "Negate") {
|
|
4292
4292
|
result = "-" + serializer.wrap(arg, 276);
|
|
4293
4293
|
} else if (name === "Add") {
|
|
4294
|
-
if (nops(expr) === 2 && serializer.options.invisiblePlus !== "+") {
|
|
4294
|
+
if (serializer.canonical && nops(expr) === 2 && serializer.options.invisiblePlus !== "+") {
|
|
4295
4295
|
const [op12, op22] = [op(expr, 1), op(expr, 2)];
|
|
4296
4296
|
let [lhs, rhs] = [op12, op22];
|
|
4297
4297
|
let lhsValue = machineValue(lhs);
|
|
@@ -4352,21 +4352,23 @@ var ComputeEngine = (() => {
|
|
|
4352
4352
|
return "";
|
|
4353
4353
|
serializer.level -= 1;
|
|
4354
4354
|
let result = "";
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
if (denom.length
|
|
4358
|
-
if (
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4355
|
+
if (serializer.canonical === true) {
|
|
4356
|
+
const [numer, denom] = numeratorDenominator(expr);
|
|
4357
|
+
if (denom.length > 0) {
|
|
4358
|
+
if (denom.length === 1 && denom[0] === 1) {
|
|
4359
|
+
if (numer.length === 0)
|
|
4360
|
+
result = "1";
|
|
4361
|
+
else if (numer.length === 1)
|
|
4362
|
+
result = serializer.serialize(numer[0]);
|
|
4363
|
+
else
|
|
4364
|
+
result = serializeMultiply(serializer, ["Multiply", ...numer]);
|
|
4365
|
+
} else {
|
|
4366
|
+
result = serializer.serialize([
|
|
4367
|
+
"Divide",
|
|
4368
|
+
numer.length === 1 ? numer[0] : ["Multiply", ...numer],
|
|
4369
|
+
denom.length === 1 ? denom[0] : ["Multiply", ...denom]
|
|
4370
|
+
]);
|
|
4371
|
+
}
|
|
4370
4372
|
}
|
|
4371
4373
|
}
|
|
4372
4374
|
if (result) {
|
|
@@ -4487,7 +4489,7 @@ var ComputeEngine = (() => {
|
|
|
4487
4489
|
return "";
|
|
4488
4490
|
const numer = missingIfEmpty(op(expr, 1));
|
|
4489
4491
|
const denom = missingIfEmpty(op(expr, 2));
|
|
4490
|
-
const style = getFractionStyle(expr, serializer.level);
|
|
4492
|
+
const style = serializer.canonical ? getFractionStyle(expr, serializer.level) : "quotient";
|
|
4491
4493
|
if (style === "inline-solidus" || style === "nice-solidus") {
|
|
4492
4494
|
const numerStr = serializer.wrapShort(numer);
|
|
4493
4495
|
const denomStr = serializer.wrapShort(denom);
|
|
@@ -4526,25 +4528,27 @@ var ComputeEngine = (() => {
|
|
|
4526
4528
|
base,
|
|
4527
4529
|
exp2
|
|
4528
4530
|
);
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
if (
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
if (
|
|
4546
|
-
|
|
4547
|
-
|
|
4531
|
+
if (serializer.canonical) {
|
|
4532
|
+
const val2 = machineValue(exp2) ?? 1;
|
|
4533
|
+
if (val2 === -1) {
|
|
4534
|
+
return serializer.serialize(["Divide", "1", base]);
|
|
4535
|
+
} else if (val2 < 0) {
|
|
4536
|
+
return serializer.serialize(["Divide", "1", ["Power", base, -val2]]);
|
|
4537
|
+
} else if (head(exp2) === "Divide" || head(exp2) === "Rational") {
|
|
4538
|
+
if (machineValue(op(exp2, 1)) === 1) {
|
|
4539
|
+
const style = getRootStyle(expr, serializer.level);
|
|
4540
|
+
return serializeRoot(serializer, style, base, op(exp2, 2));
|
|
4541
|
+
}
|
|
4542
|
+
if (machineValue(op(exp2, 2)) === 2) {
|
|
4543
|
+
return `${serializer.serialize(["Sqrt", base])}^{${serializer.serialize(
|
|
4544
|
+
op(exp2, 1)
|
|
4545
|
+
)}}`;
|
|
4546
|
+
}
|
|
4547
|
+
} else if (head(exp2) === "Power") {
|
|
4548
|
+
if (machineValue(op(exp2, 2)) === -1) {
|
|
4549
|
+
const style = getRootStyle(expr, serializer.level);
|
|
4550
|
+
return serializeRoot(serializer, style, base, op(exp2, 1));
|
|
4551
|
+
}
|
|
4548
4552
|
}
|
|
4549
4553
|
}
|
|
4550
4554
|
return serializer.wrapShort(base) + "^{" + serializer.serialize(exp2) + "}";
|
|
@@ -5388,15 +5392,9 @@ var ComputeEngine = (() => {
|
|
|
5388
5392
|
{
|
|
5389
5393
|
name: "List",
|
|
5390
5394
|
kind: "matchfix",
|
|
5391
|
-
openTrigger: "
|
|
5392
|
-
closeTrigger: "
|
|
5393
|
-
parse:
|
|
5394
|
-
if (body === null || isEmptySequence(body))
|
|
5395
|
-
return ["List"];
|
|
5396
|
-
if (head(body) !== "Sequence" && head(body) !== "List")
|
|
5397
|
-
return ["List", body];
|
|
5398
|
-
return ["List", ...ops(body) ?? []];
|
|
5399
|
-
},
|
|
5395
|
+
openTrigger: "\\lbrack",
|
|
5396
|
+
closeTrigger: "\\rbrack",
|
|
5397
|
+
parse: parseList,
|
|
5400
5398
|
serialize: (serializer, expr) => {
|
|
5401
5399
|
return joinLatex([
|
|
5402
5400
|
"\\lbrack",
|
|
@@ -5405,20 +5403,31 @@ var ComputeEngine = (() => {
|
|
|
5405
5403
|
]);
|
|
5406
5404
|
}
|
|
5407
5405
|
},
|
|
5406
|
+
// Synonyms for List
|
|
5407
|
+
{
|
|
5408
|
+
kind: "matchfix",
|
|
5409
|
+
openTrigger: "[",
|
|
5410
|
+
closeTrigger: "]",
|
|
5411
|
+
parse: parseList
|
|
5412
|
+
},
|
|
5413
|
+
{
|
|
5414
|
+
kind: "matchfix",
|
|
5415
|
+
openTrigger: "\\[",
|
|
5416
|
+
closeTrigger: "\\]",
|
|
5417
|
+
parse: parseList
|
|
5418
|
+
},
|
|
5419
|
+
// Synonyms for Delimiter
|
|
5408
5420
|
{
|
|
5409
5421
|
kind: "matchfix",
|
|
5410
5422
|
openTrigger: "(",
|
|
5411
5423
|
closeTrigger: ")",
|
|
5412
|
-
parse:
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
}
|
|
5420
|
-
return ["Delimiter", body];
|
|
5421
|
-
}
|
|
5424
|
+
parse: parseDelimiter
|
|
5425
|
+
},
|
|
5426
|
+
{
|
|
5427
|
+
kind: "matchfix",
|
|
5428
|
+
openTrigger: "\\lparen",
|
|
5429
|
+
closeTrigger: "\\rparen",
|
|
5430
|
+
parse: parseDelimiter
|
|
5422
5431
|
},
|
|
5423
5432
|
{
|
|
5424
5433
|
latexTrigger: [","],
|
|
@@ -5491,9 +5500,7 @@ var ComputeEngine = (() => {
|
|
|
5491
5500
|
kind: "postfix",
|
|
5492
5501
|
parse: (_parser, lhs) => ["Superstar", lhs]
|
|
5493
5502
|
},
|
|
5494
|
-
//
|
|
5495
|
-
// { name: 'Conjugate', trigger: ['\\star'], kind: 'infix' },
|
|
5496
|
-
{ name: "Superstar", latexTrigger: ["^", "\\star"], kind: "postfix" },
|
|
5503
|
+
// { name: 'Superstar', latexTrigger: ['^', '\\star'], kind: 'postfix' },
|
|
5497
5504
|
{
|
|
5498
5505
|
latexTrigger: ["_", "*"],
|
|
5499
5506
|
kind: "postfix",
|
|
@@ -5775,6 +5782,23 @@ var ComputeEngine = (() => {
|
|
|
5775
5782
|
return ["Prime", missingIfEmpty(lhs)];
|
|
5776
5783
|
return ["Prime", missingIfEmpty(lhs), order2];
|
|
5777
5784
|
}
|
|
5785
|
+
function parseDelimiter(parser, body) {
|
|
5786
|
+
if (body === null || isEmptySequence(body))
|
|
5787
|
+
return ["Sequence"];
|
|
5788
|
+
if (head(body) === "Sequence") {
|
|
5789
|
+
if (nops(body) === 0)
|
|
5790
|
+
return ["Delimiter"];
|
|
5791
|
+
return ["Delimiter", ["Sequence", ...ops(body) ?? []]];
|
|
5792
|
+
}
|
|
5793
|
+
return ["Delimiter", body];
|
|
5794
|
+
}
|
|
5795
|
+
function parseList(_parser, body) {
|
|
5796
|
+
if (body === null || isEmptySequence(body))
|
|
5797
|
+
return ["List"];
|
|
5798
|
+
if (head(body) !== "Sequence" && head(body) !== "List")
|
|
5799
|
+
return ["List", body];
|
|
5800
|
+
return ["List", ...ops(body) ?? []];
|
|
5801
|
+
}
|
|
5778
5802
|
|
|
5779
5803
|
// src/compute-engine/latex-syntax/dictionary/definitions-inequalities.ts
|
|
5780
5804
|
var DEFINITIONS_INEQUALITIES = [
|
|
@@ -7703,6 +7727,59 @@ var ComputeEngine = (() => {
|
|
|
7703
7727
|
})
|
|
7704
7728
|
];
|
|
7705
7729
|
|
|
7730
|
+
// src/compute-engine/latex-syntax/dictionary/definitions-complex.ts
|
|
7731
|
+
var DEFINITIONS_COMPLEX = [
|
|
7732
|
+
{
|
|
7733
|
+
name: "Real",
|
|
7734
|
+
kind: "function",
|
|
7735
|
+
latexTrigger: ["\\Re"]
|
|
7736
|
+
},
|
|
7737
|
+
{
|
|
7738
|
+
name: "Imaginary",
|
|
7739
|
+
kind: "function",
|
|
7740
|
+
latexTrigger: ["\\Im"]
|
|
7741
|
+
},
|
|
7742
|
+
{
|
|
7743
|
+
name: "Argument",
|
|
7744
|
+
kind: "function",
|
|
7745
|
+
latexTrigger: ["\\arg"]
|
|
7746
|
+
},
|
|
7747
|
+
{
|
|
7748
|
+
name: "Conjugate",
|
|
7749
|
+
latexTrigger: ["^", "\\star"],
|
|
7750
|
+
kind: "postfix"
|
|
7751
|
+
}
|
|
7752
|
+
];
|
|
7753
|
+
|
|
7754
|
+
// src/compute-engine/latex-syntax/dictionary/definitions-statistics.ts
|
|
7755
|
+
var DEFINITIONS_STATISTICS = [
|
|
7756
|
+
{
|
|
7757
|
+
name: "Mean",
|
|
7758
|
+
kind: "function",
|
|
7759
|
+
identifierTrigger: "mean"
|
|
7760
|
+
},
|
|
7761
|
+
{
|
|
7762
|
+
name: "Median",
|
|
7763
|
+
kind: "function",
|
|
7764
|
+
identifierTrigger: "median"
|
|
7765
|
+
},
|
|
7766
|
+
{
|
|
7767
|
+
name: "StandarDeviation",
|
|
7768
|
+
kind: "function",
|
|
7769
|
+
identifierTrigger: "stddev"
|
|
7770
|
+
},
|
|
7771
|
+
{
|
|
7772
|
+
latexTrigger: ["\\bar"],
|
|
7773
|
+
kind: "expression",
|
|
7774
|
+
parse: (parser, _until) => {
|
|
7775
|
+
const expr = parser.parseGroup() ?? parser.parseToken();
|
|
7776
|
+
if (!expr || !symbol(expr))
|
|
7777
|
+
return null;
|
|
7778
|
+
return ["Mean", expr];
|
|
7779
|
+
}
|
|
7780
|
+
}
|
|
7781
|
+
];
|
|
7782
|
+
|
|
7706
7783
|
// src/compute-engine/latex-syntax/dictionary/definitions.ts
|
|
7707
7784
|
var DEFAULT_DELIMITER = {
|
|
7708
7785
|
"(": "(",
|
|
@@ -7892,7 +7969,7 @@ var ComputeEngine = (() => {
|
|
|
7892
7969
|
return entry.parse;
|
|
7893
7970
|
const kind = "kind" in entry ? entry.kind : "expression";
|
|
7894
7971
|
if (kind === "environment") {
|
|
7895
|
-
const envName = entry.parse ??
|
|
7972
|
+
const envName = entry.parse ?? entry.name ?? idTrigger;
|
|
7896
7973
|
if (envName)
|
|
7897
7974
|
return (parser, _until) => {
|
|
7898
7975
|
const array = parser.parseTabular();
|
|
@@ -7902,7 +7979,7 @@ var ComputeEngine = (() => {
|
|
|
7902
7979
|
};
|
|
7903
7980
|
}
|
|
7904
7981
|
if (kind === "function") {
|
|
7905
|
-
const fnName = entry.parse ??
|
|
7982
|
+
const fnName = entry.parse ?? entry.name ?? idTrigger;
|
|
7906
7983
|
if (fnName)
|
|
7907
7984
|
return (parser, until) => {
|
|
7908
7985
|
const args = parser.parseArguments("enclosure", until);
|
|
@@ -7910,12 +7987,12 @@ var ComputeEngine = (() => {
|
|
|
7910
7987
|
};
|
|
7911
7988
|
}
|
|
7912
7989
|
if (kind === "symbol") {
|
|
7913
|
-
const symName = entry.parse ??
|
|
7990
|
+
const symName = entry.parse ?? entry.name ?? idTrigger;
|
|
7914
7991
|
if (symName)
|
|
7915
7992
|
return (_parser, _terminator) => symName;
|
|
7916
7993
|
}
|
|
7917
7994
|
if (kind === "prefix") {
|
|
7918
|
-
const h = entry.parse ??
|
|
7995
|
+
const h = entry.parse ?? entry.name ?? idTrigger;
|
|
7919
7996
|
if (h) {
|
|
7920
7997
|
const prec = entry["precedence"] ?? 1e4;
|
|
7921
7998
|
return (parser, until) => {
|
|
@@ -7941,7 +8018,7 @@ var ComputeEngine = (() => {
|
|
|
7941
8018
|
missingIfEmpty(op(arg, 2))
|
|
7942
8019
|
];
|
|
7943
8020
|
}
|
|
7944
|
-
const h = entry.parse ??
|
|
8021
|
+
const h = entry.parse ?? entry.name ?? idTrigger;
|
|
7945
8022
|
const prec = entry["precedence"] ?? 1e4;
|
|
7946
8023
|
const associativity = entry["associativity"] ?? "non";
|
|
7947
8024
|
if (h)
|
|
@@ -7966,7 +8043,7 @@ var ComputeEngine = (() => {
|
|
|
7966
8043
|
};
|
|
7967
8044
|
}
|
|
7968
8045
|
if (kind === "expression") {
|
|
7969
|
-
const parseResult = entry.parse ??
|
|
8046
|
+
const parseResult = entry.parse ?? entry.name ?? idTrigger;
|
|
7970
8047
|
if (parseResult)
|
|
7971
8048
|
return () => parseResult;
|
|
7972
8049
|
}
|
|
@@ -7987,6 +8064,16 @@ var ComputeEngine = (() => {
|
|
|
7987
8064
|
}
|
|
7988
8065
|
if (Array.isArray(subject))
|
|
7989
8066
|
subject = tokensToString(subject);
|
|
8067
|
+
if ("trigger" in entry) {
|
|
8068
|
+
onError({
|
|
8069
|
+
severity: "warning",
|
|
8070
|
+
message: [
|
|
8071
|
+
"invalid-dictionary-entry",
|
|
8072
|
+
subject,
|
|
8073
|
+
`The 'trigger' property is deprecated. Use 'latexTrigger' or 'identifierTrigger' instead`
|
|
8074
|
+
]
|
|
8075
|
+
});
|
|
8076
|
+
}
|
|
7990
8077
|
if ("kind" in entry && ![
|
|
7991
8078
|
"expression",
|
|
7992
8079
|
"symbol",
|
|
@@ -8153,6 +8240,7 @@ var ComputeEngine = (() => {
|
|
|
8153
8240
|
algebra: DEFINITIONS_ALGEBRA,
|
|
8154
8241
|
arithmetic: DEFINITIONS_ARITHMETIC,
|
|
8155
8242
|
calculus: DEFINITIONS_CALCULUS,
|
|
8243
|
+
complex: DEFINITIONS_COMPLEX,
|
|
8156
8244
|
core: DEFINITIONS_CORE,
|
|
8157
8245
|
logic: DEFINITIONS_LOGIC,
|
|
8158
8246
|
relop: DEFINITIONS_INEQUALITIES,
|
|
@@ -8165,6 +8253,7 @@ var ComputeEngine = (() => {
|
|
|
8165
8253
|
}
|
|
8166
8254
|
],
|
|
8167
8255
|
sets: DEFINITIONS_SETS,
|
|
8256
|
+
statistics: DEFINITIONS_STATISTICS,
|
|
8168
8257
|
symbols: DEFINITIONS_SYMBOLS,
|
|
8169
8258
|
trigonometry: DEFINITIONS_TRIGONOMETRY
|
|
8170
8259
|
};
|
|
@@ -8688,7 +8777,7 @@ var ComputeEngine = (() => {
|
|
|
8688
8777
|
}
|
|
8689
8778
|
for (const def of defs) {
|
|
8690
8779
|
if (def.identifierTrigger) {
|
|
8691
|
-
const n =
|
|
8780
|
+
const n = parseComplexId(this, def.identifierTrigger);
|
|
8692
8781
|
if (n > 0)
|
|
8693
8782
|
result.push([def, n]);
|
|
8694
8783
|
}
|
|
@@ -8831,6 +8920,65 @@ var ComputeEngine = (() => {
|
|
|
8831
8920
|
this.index = index;
|
|
8832
8921
|
return null;
|
|
8833
8922
|
}
|
|
8923
|
+
/** If the next token matches the open delimiter, set a boundary with
|
|
8924
|
+
* the close token and return true.
|
|
8925
|
+
*
|
|
8926
|
+
* Note this method handles generic delimiters, i.e. '(' will math both
|
|
8927
|
+
* '(', '\left(', '\bigl(', etc...
|
|
8928
|
+
*
|
|
8929
|
+
* Note that the definitions for matchfix may need to include synonyms
|
|
8930
|
+
* for example:
|
|
8931
|
+
*
|
|
8932
|
+
* {
|
|
8933
|
+
* openDelimiter: '(',
|
|
8934
|
+
* closeDelimiter: ')'
|
|
8935
|
+
* }
|
|
8936
|
+
*
|
|
8937
|
+
* and
|
|
8938
|
+
*
|
|
8939
|
+
* {
|
|
8940
|
+
* openDelimiter: '\\lparen',
|
|
8941
|
+
* closeDelimiter: '\\rparen'
|
|
8942
|
+
* }
|
|
8943
|
+
*
|
|
8944
|
+
* For:
|
|
8945
|
+
* - '[': '\\lbrack' and '\\['
|
|
8946
|
+
* - ']': '\\rbrack' and '\\]'
|
|
8947
|
+
* - '{': '\\lbrace' and '\\}'
|
|
8948
|
+
* - '}': '\\rbrace' and '\\}'
|
|
8949
|
+
* - '<': '\\langle'
|
|
8950
|
+
* - '>': '\\rangle'
|
|
8951
|
+
* - '|': '\\vert'
|
|
8952
|
+
* - '||': '\\Vert'
|
|
8953
|
+
* - '|': '\\lvert' and '\\rvert'
|
|
8954
|
+
* - '||': '\\lVert' and '\\rVert'
|
|
8955
|
+
*/
|
|
8956
|
+
matchDelimiter(open, close) {
|
|
8957
|
+
if (this.peek === "[")
|
|
8958
|
+
return false;
|
|
8959
|
+
if (Array.isArray(open)) {
|
|
8960
|
+
console.assert(Array.isArray(close));
|
|
8961
|
+
if (this.matchAll(open)) {
|
|
8962
|
+
this.addBoundary(close);
|
|
8963
|
+
return true;
|
|
8964
|
+
}
|
|
8965
|
+
return false;
|
|
8966
|
+
}
|
|
8967
|
+
const start = this.index;
|
|
8968
|
+
const closePrefix = OPEN_DELIMITER_PREFIX[this.peek];
|
|
8969
|
+
if (closePrefix)
|
|
8970
|
+
this.nextToken();
|
|
8971
|
+
if (open === "||" && this.matchAll(["|", "|"])) {
|
|
8972
|
+
this.addBoundary(["|", "|"]);
|
|
8973
|
+
return true;
|
|
8974
|
+
}
|
|
8975
|
+
if (!this.match(open)) {
|
|
8976
|
+
this.index = start;
|
|
8977
|
+
return false;
|
|
8978
|
+
}
|
|
8979
|
+
this.addBoundary(closePrefix ? [closePrefix, close] : [close]);
|
|
8980
|
+
return true;
|
|
8981
|
+
}
|
|
8834
8982
|
parseGroup() {
|
|
8835
8983
|
const start = this.index;
|
|
8836
8984
|
this.skipSpaceTokens();
|
|
@@ -9287,6 +9435,8 @@ var ComputeEngine = (() => {
|
|
|
9287
9435
|
* return `['\right', '\rparen']`, which can be matched with `matchAll()`
|
|
9288
9436
|
*
|
|
9289
9437
|
* If you need to match several tokens, use `matchAll()`
|
|
9438
|
+
*
|
|
9439
|
+
* @internal
|
|
9290
9440
|
*/
|
|
9291
9441
|
matchOpenDelimiter(openDelim, closeDelim) {
|
|
9292
9442
|
const index = this.index;
|
|
@@ -9401,42 +9551,20 @@ var ComputeEngine = (() => {
|
|
|
9401
9551
|
const start = this.index;
|
|
9402
9552
|
for (const def of defs) {
|
|
9403
9553
|
this.index = start;
|
|
9404
|
-
if (
|
|
9405
|
-
if (!this.matchAll(def.openDelimiter))
|
|
9406
|
-
continue;
|
|
9407
|
-
this.addBoundary(def.closeDelimiter);
|
|
9408
|
-
const body2 = this.parseExpression();
|
|
9409
|
-
this.skipSpace();
|
|
9410
|
-
if (!this.matchBoundary()) {
|
|
9411
|
-
this.removeBoundary();
|
|
9412
|
-
continue;
|
|
9413
|
-
}
|
|
9414
|
-
const rhs = def.parse(this, body2 ?? ["Sequence"]);
|
|
9415
|
-
if (rhs === null)
|
|
9416
|
-
continue;
|
|
9417
|
-
return rhs;
|
|
9418
|
-
}
|
|
9419
|
-
const closeDelimiter = this.matchOpenDelimiter(
|
|
9420
|
-
def.openDelimiter,
|
|
9421
|
-
def.closeDelimiter
|
|
9422
|
-
);
|
|
9423
|
-
if (closeDelimiter === null)
|
|
9554
|
+
if (!this.matchDelimiter(def.openDelimiter, def.closeDelimiter))
|
|
9424
9555
|
continue;
|
|
9425
|
-
if (this.matchAll(closeDelimiter)) {
|
|
9426
|
-
const result2 = def.parse(this, ["Sequence"]);
|
|
9427
|
-
if (result2 === null)
|
|
9428
|
-
continue;
|
|
9429
|
-
return result2;
|
|
9430
|
-
}
|
|
9431
|
-
this.addBoundary(closeDelimiter);
|
|
9432
9556
|
const bodyStart = this.index;
|
|
9557
|
+
this.skipSpace();
|
|
9433
9558
|
let body = this.parseExpression();
|
|
9434
9559
|
this.skipSpace();
|
|
9435
9560
|
if (!this.matchBoundary()) {
|
|
9561
|
+
const boundary = this._boundaries[this._boundaries.length - 1].tokens;
|
|
9436
9562
|
this.removeBoundary();
|
|
9437
9563
|
this.index = bodyStart;
|
|
9564
|
+
this.skipSpace();
|
|
9438
9565
|
body = this.parseExpression();
|
|
9439
|
-
|
|
9566
|
+
this.skipSpace();
|
|
9567
|
+
if (!this.matchAll(boundary)) {
|
|
9440
9568
|
if (!this.atEnd)
|
|
9441
9569
|
continue;
|
|
9442
9570
|
this.index = start;
|
|
@@ -10023,7 +10151,7 @@ var ComputeEngine = (() => {
|
|
|
10023
10151
|
}
|
|
10024
10152
|
}
|
|
10025
10153
|
};
|
|
10026
|
-
function
|
|
10154
|
+
function parseComplexId(parser, id) {
|
|
10027
10155
|
const start = parser.index;
|
|
10028
10156
|
const candidate = parseIdentifier(parser)?.trim();
|
|
10029
10157
|
if (candidate === null)
|
|
@@ -10292,6 +10420,7 @@ var ComputeEngine = (() => {
|
|
|
10292
10420
|
}
|
|
10293
10421
|
this.onError = onError;
|
|
10294
10422
|
this.dictionary = dictionary2;
|
|
10423
|
+
this.canonical = void 0;
|
|
10295
10424
|
}
|
|
10296
10425
|
updateOptions(opt) {
|
|
10297
10426
|
for (const k of Object.keys(this.options))
|
|
@@ -10411,9 +10540,16 @@ var ComputeEngine = (() => {
|
|
|
10411
10540
|
return `\\textbf{${x}} & \\rightarrow & ${this.serialize(dict[x])}`;
|
|
10412
10541
|
}).join("\\\\")}\\end{array}\\right\\rbrack`;
|
|
10413
10542
|
}
|
|
10414
|
-
serialize(expr) {
|
|
10543
|
+
serialize(expr, options) {
|
|
10415
10544
|
if (expr === null || expr === void 0)
|
|
10416
10545
|
return "";
|
|
10546
|
+
options ?? (options = {});
|
|
10547
|
+
options = { ...options };
|
|
10548
|
+
if (!("canonical" in options))
|
|
10549
|
+
options.canonical = true;
|
|
10550
|
+
const savedCanonical = this.canonical;
|
|
10551
|
+
if (this.canonical === void 0)
|
|
10552
|
+
this.canonical = options.canonical;
|
|
10417
10553
|
this.level += 1;
|
|
10418
10554
|
try {
|
|
10419
10555
|
const result = (() => {
|
|
@@ -10450,10 +10586,12 @@ var ComputeEngine = (() => {
|
|
|
10450
10586
|
]);
|
|
10451
10587
|
})();
|
|
10452
10588
|
this.level -= 1;
|
|
10589
|
+
this.canonical = savedCanonical;
|
|
10453
10590
|
return result ?? "";
|
|
10454
10591
|
} catch (e) {
|
|
10455
10592
|
}
|
|
10456
10593
|
this.level -= 1;
|
|
10594
|
+
this.canonical = savedCanonical;
|
|
10457
10595
|
return "";
|
|
10458
10596
|
}
|
|
10459
10597
|
applyFunctionStyle(expr, level) {
|
|
@@ -10791,8 +10929,8 @@ var ComputeEngine = (() => {
|
|
|
10791
10929
|
}
|
|
10792
10930
|
return expr ?? ["Sequence"];
|
|
10793
10931
|
}
|
|
10794
|
-
serialize(expr) {
|
|
10795
|
-
return this.serializer.serialize(expr);
|
|
10932
|
+
serialize(expr, options) {
|
|
10933
|
+
return this.serializer.serialize(expr, options);
|
|
10796
10934
|
}
|
|
10797
10935
|
get serializer() {
|
|
10798
10936
|
if (this._serializer)
|
|
@@ -12125,6 +12263,19 @@ var ComputeEngine = (() => {
|
|
|
12125
12263
|
return 0;
|
|
12126
12264
|
return n;
|
|
12127
12265
|
}
|
|
12266
|
+
function erf(x) {
|
|
12267
|
+
const a1 = 0.254829592;
|
|
12268
|
+
const a2 = -0.284496736;
|
|
12269
|
+
const a3 = 1.421413741;
|
|
12270
|
+
const a4 = -1.453152027;
|
|
12271
|
+
const a5 = 1.061405429;
|
|
12272
|
+
const p = 0.3275911;
|
|
12273
|
+
const sign2 = x < 0 ? -1 : 1;
|
|
12274
|
+
x = Math.abs(x);
|
|
12275
|
+
const t = 1 / (1 + p * x);
|
|
12276
|
+
const y = ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t;
|
|
12277
|
+
return sign2 * (1 - y * Math.exp(-x * x));
|
|
12278
|
+
}
|
|
12128
12279
|
|
|
12129
12280
|
// src/compute-engine/numerics/numeric-bigint.ts
|
|
12130
12281
|
function bigint(a) {
|
|
@@ -18952,6 +19103,24 @@ ${js}`);
|
|
|
18952
19103
|
console.assert(op12.isCanonical);
|
|
18953
19104
|
console.assert(op22.isCanonical);
|
|
18954
19105
|
const ce = op12.engine;
|
|
19106
|
+
if (op12.symbol === "ImaginaryUnit") {
|
|
19107
|
+
const f = asFloat(op22);
|
|
19108
|
+
if (f !== null)
|
|
19109
|
+
return ce.number(ce.complex(0, f));
|
|
19110
|
+
}
|
|
19111
|
+
if (op22.symbol === "ImaginaryUnit") {
|
|
19112
|
+
const f = asFloat(op12);
|
|
19113
|
+
if (f !== null)
|
|
19114
|
+
return ce.number(ce.complex(0, f));
|
|
19115
|
+
}
|
|
19116
|
+
if (op12.numericValue !== null && op22.numericValue !== null) {
|
|
19117
|
+
const f1 = asFloat(op12);
|
|
19118
|
+
const f2 = asFloat(op22);
|
|
19119
|
+
if (f1 !== null && ce.isComplex(op22))
|
|
19120
|
+
return ce.number(ce.complex(f1 * op22.re, f1 * op22.im));
|
|
19121
|
+
if (f2 !== null && ce.isComplex(op12))
|
|
19122
|
+
return ce.number(ce.complex(f2 * op12.re, f2 * op12.im));
|
|
19123
|
+
}
|
|
18955
19124
|
if (op12.numericValue !== null && op22.numericValue !== null && op12.isInteger && op22.isInteger) {
|
|
18956
19125
|
return apply2N(
|
|
18957
19126
|
op12,
|
|
@@ -19367,14 +19536,6 @@ ${js}`);
|
|
|
19367
19536
|
}
|
|
19368
19537
|
}
|
|
19369
19538
|
},
|
|
19370
|
-
Erf: {
|
|
19371
|
-
description: "Error Function",
|
|
19372
|
-
complexity: 7500
|
|
19373
|
-
},
|
|
19374
|
-
Erfc: {
|
|
19375
|
-
description: "Complementary Error Function",
|
|
19376
|
-
complexity: 7500
|
|
19377
|
-
},
|
|
19378
19539
|
Factorial: {
|
|
19379
19540
|
description: "Factorial Function",
|
|
19380
19541
|
wikidata: "Q120976",
|
|
@@ -19519,7 +19680,7 @@ ${js}`);
|
|
|
19519
19680
|
description: "Maximum of two or more numbers",
|
|
19520
19681
|
complexity: 1200,
|
|
19521
19682
|
signature: {
|
|
19522
|
-
domain: ["Function", ["Sequence", "
|
|
19683
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
19523
19684
|
simplify: (ce, ops2) => {
|
|
19524
19685
|
if (ops2.length === 0)
|
|
19525
19686
|
return ce._NEGATIVE_INFINITY;
|
|
@@ -19548,7 +19709,7 @@ ${js}`);
|
|
|
19548
19709
|
description: "Minimum of two or more numbers",
|
|
19549
19710
|
complexity: 1200,
|
|
19550
19711
|
signature: {
|
|
19551
|
-
domain: ["Function", ["Sequence", "
|
|
19712
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
19552
19713
|
simplify: (ce, ops2) => {
|
|
19553
19714
|
if (ops2.length === 0)
|
|
19554
19715
|
return ce._NEGATIVE_INFINITY;
|
|
@@ -20106,6 +20267,125 @@ ${js}`);
|
|
|
20106
20267
|
}
|
|
20107
20268
|
};
|
|
20108
20269
|
|
|
20270
|
+
// src/compute-engine/library/complex.ts
|
|
20271
|
+
var COMPLEX_LIBRARY = [
|
|
20272
|
+
{
|
|
20273
|
+
Real: {
|
|
20274
|
+
threadable: true,
|
|
20275
|
+
complexity: 1200,
|
|
20276
|
+
signature: {
|
|
20277
|
+
domain: ["Function", "Number", "Number"],
|
|
20278
|
+
evaluate: (ce, ops2) => {
|
|
20279
|
+
const op3 = ops2[0].numericValue;
|
|
20280
|
+
if (op3 === null)
|
|
20281
|
+
return void 0;
|
|
20282
|
+
if (ce.isComplex(op3))
|
|
20283
|
+
return ce.number(op3.re);
|
|
20284
|
+
return ops2[0];
|
|
20285
|
+
}
|
|
20286
|
+
}
|
|
20287
|
+
},
|
|
20288
|
+
Imaginary: {
|
|
20289
|
+
threadable: true,
|
|
20290
|
+
complexity: 1200,
|
|
20291
|
+
signature: {
|
|
20292
|
+
domain: ["Function", "Number", "Number"],
|
|
20293
|
+
evaluate: (ce, ops2) => {
|
|
20294
|
+
const op3 = ops2[0].numericValue;
|
|
20295
|
+
if (op3 === null)
|
|
20296
|
+
return void 0;
|
|
20297
|
+
if (ce.isComplex(op3))
|
|
20298
|
+
return ce.number(op3.im);
|
|
20299
|
+
return ce._ZERO;
|
|
20300
|
+
}
|
|
20301
|
+
}
|
|
20302
|
+
},
|
|
20303
|
+
Argument: {
|
|
20304
|
+
threadable: true,
|
|
20305
|
+
complexity: 1200,
|
|
20306
|
+
signature: {
|
|
20307
|
+
domain: ["Function", "Number", "Number"],
|
|
20308
|
+
evaluate: (ce, ops2) => {
|
|
20309
|
+
const op3 = ops2[0].numericValue;
|
|
20310
|
+
if (op3 === null)
|
|
20311
|
+
return void 0;
|
|
20312
|
+
if (ce.isComplex(op3))
|
|
20313
|
+
return ce.number(op3.arg());
|
|
20314
|
+
const f = asFloat(ops2[0]);
|
|
20315
|
+
if (f === null)
|
|
20316
|
+
return void 0;
|
|
20317
|
+
if (f >= 0)
|
|
20318
|
+
return ce.number(0);
|
|
20319
|
+
return ce.number(Math.PI);
|
|
20320
|
+
}
|
|
20321
|
+
}
|
|
20322
|
+
},
|
|
20323
|
+
AbsArg: {
|
|
20324
|
+
threadable: true,
|
|
20325
|
+
complexity: 1200,
|
|
20326
|
+
signature: {
|
|
20327
|
+
domain: ["Function", "Number", "Tuple"],
|
|
20328
|
+
evaluate: (ce, ops2) => {
|
|
20329
|
+
const op3 = ops2[0].numericValue;
|
|
20330
|
+
if (op3 === null)
|
|
20331
|
+
return void 0;
|
|
20332
|
+
if (ce.isComplex(op3))
|
|
20333
|
+
return ce.tuple([ce.number(op3.abs()), ce.number(op3.arg())]);
|
|
20334
|
+
const f = asFloat(ops2[0]);
|
|
20335
|
+
if (f === null)
|
|
20336
|
+
return void 0;
|
|
20337
|
+
return ce.tuple([
|
|
20338
|
+
ce.number(Math.abs(f)),
|
|
20339
|
+
ce.number(f >= 0 ? 0 : Math.PI)
|
|
20340
|
+
]);
|
|
20341
|
+
}
|
|
20342
|
+
}
|
|
20343
|
+
},
|
|
20344
|
+
Conjugate: {
|
|
20345
|
+
threadable: true,
|
|
20346
|
+
complexity: 1200,
|
|
20347
|
+
signature: {
|
|
20348
|
+
domain: ["Function", "Number", "Number"],
|
|
20349
|
+
evaluate: (ce, ops2) => {
|
|
20350
|
+
const op3 = ops2[0].numericValue;
|
|
20351
|
+
if (op3 === null || !ce.isComplex(op3))
|
|
20352
|
+
return void 0;
|
|
20353
|
+
return ce.number(op3.conjugate());
|
|
20354
|
+
}
|
|
20355
|
+
}
|
|
20356
|
+
},
|
|
20357
|
+
ComplexRoots: {
|
|
20358
|
+
threadable: true,
|
|
20359
|
+
complexity: 1200,
|
|
20360
|
+
signature: {
|
|
20361
|
+
domain: ["Function", "Number", "Number", "List"],
|
|
20362
|
+
evaluate: (ce, ops2) => {
|
|
20363
|
+
const x = asFloat(ops2[0]);
|
|
20364
|
+
const n = asFloat(ops2[1]);
|
|
20365
|
+
if (x === null || n === null || !Number.isInteger(n) || n <= 0)
|
|
20366
|
+
return void 0;
|
|
20367
|
+
const roots = [];
|
|
20368
|
+
const [re, im] = ce.isComplex(x) ? [x.re, x.im] : [x, 0];
|
|
20369
|
+
const arg = Math.atan2(im, re);
|
|
20370
|
+
const mod2 = Math.sqrt(re * re + im * im);
|
|
20371
|
+
for (let k = 0; k < n; k++) {
|
|
20372
|
+
const theta = (arg + 2 * Math.PI * k) / n;
|
|
20373
|
+
const r = Math.pow(mod2, 1 / n);
|
|
20374
|
+
roots.push([r * Math.cos(theta), r * Math.sin(theta)]);
|
|
20375
|
+
}
|
|
20376
|
+
return ce.box([
|
|
20377
|
+
"List",
|
|
20378
|
+
...roots.map(
|
|
20379
|
+
(r) => ce.number(r[1] !== 0 ? ce.complex(r[0], r[1]) : r[0])
|
|
20380
|
+
)
|
|
20381
|
+
]);
|
|
20382
|
+
}
|
|
20383
|
+
}
|
|
20384
|
+
}
|
|
20385
|
+
// For Abs (magnitude) see src/compute-engine/library/processAbs
|
|
20386
|
+
}
|
|
20387
|
+
];
|
|
20388
|
+
|
|
20109
20389
|
// src/compute-engine/library/random-expression.ts
|
|
20110
20390
|
function oneOf(xs) {
|
|
20111
20391
|
return xs[Math.floor(Math.random() * xs.length)];
|
|
@@ -21604,6 +21884,328 @@ ${js}`);
|
|
|
21604
21884
|
return ce._fn("Element", [lhs, rhs]);
|
|
21605
21885
|
}
|
|
21606
21886
|
|
|
21887
|
+
// src/compute-engine/library/statistics.ts
|
|
21888
|
+
var STATISTICS_LIBRARY = [
|
|
21889
|
+
{
|
|
21890
|
+
Mean: {
|
|
21891
|
+
complexity: 1200,
|
|
21892
|
+
signature: {
|
|
21893
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
21894
|
+
evaluate: (ce, ops2) => {
|
|
21895
|
+
let sum2 = 0;
|
|
21896
|
+
let count = 0;
|
|
21897
|
+
for (const op3 of each(ops2)) {
|
|
21898
|
+
const v = asFloat(op3);
|
|
21899
|
+
if (v === null)
|
|
21900
|
+
return void 0;
|
|
21901
|
+
sum2 += v;
|
|
21902
|
+
count++;
|
|
21903
|
+
}
|
|
21904
|
+
if (count === 0)
|
|
21905
|
+
return ce._NAN;
|
|
21906
|
+
return ce.number(sum2 / count);
|
|
21907
|
+
}
|
|
21908
|
+
}
|
|
21909
|
+
},
|
|
21910
|
+
Median: {
|
|
21911
|
+
complexity: 1200,
|
|
21912
|
+
signature: {
|
|
21913
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
21914
|
+
evaluate: (ce, ops2) => {
|
|
21915
|
+
const values = [];
|
|
21916
|
+
for (const op3 of each(ops2)) {
|
|
21917
|
+
const v = asFloat(op3);
|
|
21918
|
+
if (v === null)
|
|
21919
|
+
return void 0;
|
|
21920
|
+
values.push(v);
|
|
21921
|
+
}
|
|
21922
|
+
if (values.length === 0)
|
|
21923
|
+
return ce._NAN;
|
|
21924
|
+
values.sort((a, b) => a - b);
|
|
21925
|
+
const mid = Math.floor(values.length / 2);
|
|
21926
|
+
if (values.length % 2 === 0)
|
|
21927
|
+
return ce.number((values[mid - 1] + values[mid]) / 2);
|
|
21928
|
+
return ce.number(values[mid]);
|
|
21929
|
+
}
|
|
21930
|
+
}
|
|
21931
|
+
},
|
|
21932
|
+
Variance: {
|
|
21933
|
+
complexity: 1200,
|
|
21934
|
+
signature: {
|
|
21935
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
21936
|
+
evaluate: (ce, ops2) => {
|
|
21937
|
+
let sum2 = 0;
|
|
21938
|
+
let sum22 = 0;
|
|
21939
|
+
let count = 0;
|
|
21940
|
+
for (const op3 of each(ops2)) {
|
|
21941
|
+
const v = asFloat(op3);
|
|
21942
|
+
if (v === null)
|
|
21943
|
+
return void 0;
|
|
21944
|
+
sum2 += v;
|
|
21945
|
+
sum22 += v * v;
|
|
21946
|
+
count++;
|
|
21947
|
+
}
|
|
21948
|
+
if (count === 0)
|
|
21949
|
+
return ce._NAN;
|
|
21950
|
+
return ce.number((sum22 - sum2 * sum2 / count) / (count - 1));
|
|
21951
|
+
}
|
|
21952
|
+
}
|
|
21953
|
+
},
|
|
21954
|
+
StandardDeviation: {
|
|
21955
|
+
complexity: 1200,
|
|
21956
|
+
signature: {
|
|
21957
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
21958
|
+
evaluate: (ce, ops2) => {
|
|
21959
|
+
let sum2 = 0;
|
|
21960
|
+
let sum22 = 0;
|
|
21961
|
+
let count = 0;
|
|
21962
|
+
for (const op3 of each(ops2)) {
|
|
21963
|
+
const v = asFloat(op3);
|
|
21964
|
+
if (v === null)
|
|
21965
|
+
return void 0;
|
|
21966
|
+
sum2 += v;
|
|
21967
|
+
sum22 += v * v;
|
|
21968
|
+
count++;
|
|
21969
|
+
}
|
|
21970
|
+
if (count === 0)
|
|
21971
|
+
return ce._NAN;
|
|
21972
|
+
return ce.number(
|
|
21973
|
+
Math.sqrt((sum22 - sum2 * sum2 / count) / (count - 1))
|
|
21974
|
+
);
|
|
21975
|
+
}
|
|
21976
|
+
}
|
|
21977
|
+
},
|
|
21978
|
+
Kurtosis: {
|
|
21979
|
+
complexity: 1200,
|
|
21980
|
+
signature: {
|
|
21981
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
21982
|
+
evaluate: (ce, ops2) => {
|
|
21983
|
+
let sum2 = 0;
|
|
21984
|
+
let sum22 = 0;
|
|
21985
|
+
let sum4 = 0;
|
|
21986
|
+
let count = 0;
|
|
21987
|
+
for (const op3 of each(ops2)) {
|
|
21988
|
+
const v = asFloat(op3);
|
|
21989
|
+
if (v === null)
|
|
21990
|
+
return void 0;
|
|
21991
|
+
sum2 += v;
|
|
21992
|
+
sum22 += v * v;
|
|
21993
|
+
sum4 += v * v * v * v;
|
|
21994
|
+
count++;
|
|
21995
|
+
}
|
|
21996
|
+
if (count === 0)
|
|
21997
|
+
return ce._NAN;
|
|
21998
|
+
const s2 = (sum22 - sum2 * sum2 / count) / (count - 1);
|
|
21999
|
+
const s4 = (sum4 - sum22 * sum22 / count) / (count - 1);
|
|
22000
|
+
return ce.number((s4 / (s2 * s2) - 3) * (count * (count + 1)) / 6);
|
|
22001
|
+
}
|
|
22002
|
+
}
|
|
22003
|
+
},
|
|
22004
|
+
Skewness: {
|
|
22005
|
+
complexity: 1200,
|
|
22006
|
+
signature: {
|
|
22007
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
22008
|
+
evaluate: (ce, ops2) => {
|
|
22009
|
+
let sum2 = 0;
|
|
22010
|
+
let sum22 = 0;
|
|
22011
|
+
let sum3 = 0;
|
|
22012
|
+
let count = 0;
|
|
22013
|
+
for (const op3 of each(ops2)) {
|
|
22014
|
+
const v = asFloat(op3);
|
|
22015
|
+
if (v === null)
|
|
22016
|
+
return void 0;
|
|
22017
|
+
sum2 += v;
|
|
22018
|
+
sum22 += v * v;
|
|
22019
|
+
sum3 += v * v * v;
|
|
22020
|
+
count++;
|
|
22021
|
+
}
|
|
22022
|
+
if (count === 0)
|
|
22023
|
+
return ce._NAN;
|
|
22024
|
+
const s2 = (sum22 - sum2 * sum2 / count) / (count - 1);
|
|
22025
|
+
const s3 = (sum3 - sum22 * sum2 / count) / (count - 1);
|
|
22026
|
+
return ce.number(s3 / Math.pow(s2, 3 / 2) * Math.sqrt(count * 1));
|
|
22027
|
+
}
|
|
22028
|
+
}
|
|
22029
|
+
},
|
|
22030
|
+
Mode: {
|
|
22031
|
+
complexity: 1200,
|
|
22032
|
+
signature: {
|
|
22033
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
22034
|
+
evaluate: (ce, ops2) => {
|
|
22035
|
+
const values = [];
|
|
22036
|
+
for (const op3 of each(ops2)) {
|
|
22037
|
+
const v = asFloat(op3);
|
|
22038
|
+
if (v === null)
|
|
22039
|
+
return void 0;
|
|
22040
|
+
values.push(v);
|
|
22041
|
+
}
|
|
22042
|
+
if (values.length === 0)
|
|
22043
|
+
return ce._NAN;
|
|
22044
|
+
values.sort((a, b) => a - b);
|
|
22045
|
+
const counts = {};
|
|
22046
|
+
for (const v of values) {
|
|
22047
|
+
counts[v] = (counts[v] ?? 0) + 1;
|
|
22048
|
+
}
|
|
22049
|
+
let max2 = 0;
|
|
22050
|
+
let mode = values[0];
|
|
22051
|
+
for (const v of values) {
|
|
22052
|
+
const c = counts[v];
|
|
22053
|
+
if (c > max2) {
|
|
22054
|
+
max2 = c;
|
|
22055
|
+
mode = v;
|
|
22056
|
+
}
|
|
22057
|
+
}
|
|
22058
|
+
return ce.number(mode);
|
|
22059
|
+
}
|
|
22060
|
+
}
|
|
22061
|
+
},
|
|
22062
|
+
Quartiles: {
|
|
22063
|
+
complexity: 1200,
|
|
22064
|
+
signature: {
|
|
22065
|
+
domain: ["Function", ["Sequence", "Value"], "List"],
|
|
22066
|
+
evaluate: (ce, ops2) => {
|
|
22067
|
+
const values = [];
|
|
22068
|
+
for (const op3 of each(ops2)) {
|
|
22069
|
+
const v = asFloat(op3);
|
|
22070
|
+
if (v === null)
|
|
22071
|
+
return void 0;
|
|
22072
|
+
values.push(v);
|
|
22073
|
+
}
|
|
22074
|
+
if (values.length === 0)
|
|
22075
|
+
return ce._NAN;
|
|
22076
|
+
values.sort((a, b) => a - b);
|
|
22077
|
+
const mid = Math.floor(values.length / 2);
|
|
22078
|
+
const lower = values.slice(0, mid);
|
|
22079
|
+
const upper = values.slice(mid + 1);
|
|
22080
|
+
return ce.box([
|
|
22081
|
+
"List",
|
|
22082
|
+
ce.number(values[mid]),
|
|
22083
|
+
ce.number(lower[Math.floor(lower.length / 2)]),
|
|
22084
|
+
ce.number(upper[Math.floor(upper.length / 2)])
|
|
22085
|
+
]);
|
|
22086
|
+
}
|
|
22087
|
+
}
|
|
22088
|
+
},
|
|
22089
|
+
InterquartileRange: {
|
|
22090
|
+
complexity: 1200,
|
|
22091
|
+
signature: {
|
|
22092
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
22093
|
+
evaluate: (ce, ops2) => {
|
|
22094
|
+
const values = [];
|
|
22095
|
+
for (const op3 of each(ops2)) {
|
|
22096
|
+
const v = asFloat(op3);
|
|
22097
|
+
if (v === null)
|
|
22098
|
+
return void 0;
|
|
22099
|
+
values.push(v);
|
|
22100
|
+
}
|
|
22101
|
+
if (values.length === 0)
|
|
22102
|
+
return ce._NAN;
|
|
22103
|
+
values.sort((a, b) => a - b);
|
|
22104
|
+
const mid = Math.floor(values.length / 2);
|
|
22105
|
+
const lower = values.slice(0, mid);
|
|
22106
|
+
const upper = values.slice(mid + 1);
|
|
22107
|
+
return ce.number(
|
|
22108
|
+
upper[Math.floor(upper.length / 2)] - lower[Math.floor(lower.length / 2)]
|
|
22109
|
+
);
|
|
22110
|
+
}
|
|
22111
|
+
}
|
|
22112
|
+
},
|
|
22113
|
+
Count: {
|
|
22114
|
+
threadable: true,
|
|
22115
|
+
complexity: 1200,
|
|
22116
|
+
signature: {
|
|
22117
|
+
domain: ["Function", ["Sequence", "Value"], "Number"],
|
|
22118
|
+
evaluate: (ce, ops2) => {
|
|
22119
|
+
let count = 0;
|
|
22120
|
+
for (const _op of each(ops2))
|
|
22121
|
+
count++;
|
|
22122
|
+
return ce.number(count);
|
|
22123
|
+
}
|
|
22124
|
+
}
|
|
22125
|
+
},
|
|
22126
|
+
Erf: {
|
|
22127
|
+
complexity: 7500,
|
|
22128
|
+
signature: {
|
|
22129
|
+
domain: ["Function", "Number", "Number"],
|
|
22130
|
+
evaluate: (ce, ops2) => {
|
|
22131
|
+
const x = asFloat(ops2[0]);
|
|
22132
|
+
if (x === null)
|
|
22133
|
+
return void 0;
|
|
22134
|
+
return ce.number(erf(x));
|
|
22135
|
+
}
|
|
22136
|
+
}
|
|
22137
|
+
},
|
|
22138
|
+
Erfc: {
|
|
22139
|
+
complexity: 7500,
|
|
22140
|
+
signature: {
|
|
22141
|
+
domain: ["Function", "Number", "Number"],
|
|
22142
|
+
evaluate: (ce, ops2) => {
|
|
22143
|
+
const x = asFloat(ops2[0]);
|
|
22144
|
+
if (x === null)
|
|
22145
|
+
return void 0;
|
|
22146
|
+
return ce.number(1 - erf(x));
|
|
22147
|
+
}
|
|
22148
|
+
}
|
|
22149
|
+
}
|
|
22150
|
+
}
|
|
22151
|
+
];
|
|
22152
|
+
function* each(ops2) {
|
|
22153
|
+
if (ops2.length === 0)
|
|
22154
|
+
return;
|
|
22155
|
+
const ce = ops2[0].engine;
|
|
22156
|
+
for (const op3 of ops2) {
|
|
22157
|
+
const h = op3.head;
|
|
22158
|
+
if (h === "Range") {
|
|
22159
|
+
let lower = asFloat(op3[1]);
|
|
22160
|
+
if (lower === null)
|
|
22161
|
+
return;
|
|
22162
|
+
let upper = asFloat(op3[2]);
|
|
22163
|
+
if (upper === null) {
|
|
22164
|
+
upper = lower;
|
|
22165
|
+
lower = 1;
|
|
22166
|
+
}
|
|
22167
|
+
if (lower > upper) {
|
|
22168
|
+
const step2 = asFloat(op3[3] ?? -1) ?? -1;
|
|
22169
|
+
if (step2 >= 0)
|
|
22170
|
+
return;
|
|
22171
|
+
for (let i = lower; i <= upper; i += step2)
|
|
22172
|
+
yield ce.number(i);
|
|
22173
|
+
return;
|
|
22174
|
+
}
|
|
22175
|
+
const step = asFloat(op3[3] ?? 1) ?? 1;
|
|
22176
|
+
if (step <= 0)
|
|
22177
|
+
return;
|
|
22178
|
+
for (let i = lower; i <= upper; i += step)
|
|
22179
|
+
yield ce.number(i);
|
|
22180
|
+
return;
|
|
22181
|
+
}
|
|
22182
|
+
if (h === "Linspace") {
|
|
22183
|
+
let start = asFloat(op3[1]);
|
|
22184
|
+
if (start === null)
|
|
22185
|
+
return;
|
|
22186
|
+
let stop = asFloat(op3[2]);
|
|
22187
|
+
if (stop === null) {
|
|
22188
|
+
stop = start;
|
|
22189
|
+
start = 0;
|
|
22190
|
+
}
|
|
22191
|
+
const num = asFloat(op3[3]) ?? 50;
|
|
22192
|
+
if (!Number.isInteger(num))
|
|
22193
|
+
return;
|
|
22194
|
+
if (num <= 0)
|
|
22195
|
+
return;
|
|
22196
|
+
const step = (stop - start) / (num - 1);
|
|
22197
|
+
for (let i = start; i <= stop; i += step)
|
|
22198
|
+
yield ce.number(i);
|
|
22199
|
+
return;
|
|
22200
|
+
}
|
|
22201
|
+
if (typeof h === "string" && /^(List|Sequence|Tuple|Single|Pair|Triple)$/.test(h)) {
|
|
22202
|
+
yield* each(op3.ops);
|
|
22203
|
+
return;
|
|
22204
|
+
}
|
|
22205
|
+
yield op3;
|
|
22206
|
+
}
|
|
22207
|
+
}
|
|
22208
|
+
|
|
21607
22209
|
// src/compute-engine/library/trigonometry.ts
|
|
21608
22210
|
var domainNumberToRealNumber = (_head) => {
|
|
21609
22211
|
return ["Function", "Number", "ExtendedRealNumber"];
|
|
@@ -23170,7 +23772,7 @@ ${js}`);
|
|
|
23170
23772
|
// // - factor
|
|
23171
23773
|
// // - simplify
|
|
23172
23774
|
// ],
|
|
23173
|
-
"arithmetic": ARITHMETIC_LIBRARY,
|
|
23775
|
+
"arithmetic": [...ARITHMETIC_LIBRARY, ...COMPLEX_LIBRARY],
|
|
23174
23776
|
"calculus": CALCULUS_LIBRARY,
|
|
23175
23777
|
"combinatorics": [],
|
|
23176
23778
|
// @todo fibonacci, binomial, etc...
|
|
@@ -23231,15 +23833,7 @@ ${js}`);
|
|
|
23231
23833
|
// unit: ['Divide', 'N', ['Square', 'A']],
|
|
23232
23834
|
}
|
|
23233
23835
|
},
|
|
23234
|
-
"statistics":
|
|
23235
|
-
// @todo statistics: [
|
|
23236
|
-
// // average
|
|
23237
|
-
// // mean
|
|
23238
|
-
// // variance = size(l) * stddev(l)^2 / (size(l) - 1)
|
|
23239
|
-
// // stddev
|
|
23240
|
-
// // median
|
|
23241
|
-
// // quantile
|
|
23242
|
-
// ],
|
|
23836
|
+
"statistics": STATISTICS_LIBRARY,
|
|
23243
23837
|
"trigonometry": TRIGONOMETRY_LIBRARY,
|
|
23244
23838
|
"units": []
|
|
23245
23839
|
};
|
|
@@ -23295,7 +23889,7 @@ ${JSON.stringify(entry)}`
|
|
|
23295
23889
|
}
|
|
23296
23890
|
|
|
23297
23891
|
// src/compute-engine/cost-function.ts
|
|
23298
|
-
var
|
|
23892
|
+
var import_complex19 = __toESM(require_complex());
|
|
23299
23893
|
function numericCostFunction(n) {
|
|
23300
23894
|
if (Number.isInteger(n) && n !== 0) {
|
|
23301
23895
|
return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
|
|
@@ -23317,7 +23911,7 @@ ${JSON.stringify(entry)}`
|
|
|
23317
23911
|
else
|
|
23318
23912
|
return numericCostFunction(Number(num[0])) + numericCostFunction(Number(num[1])) + 1;
|
|
23319
23913
|
}
|
|
23320
|
-
if (num instanceof
|
|
23914
|
+
if (num instanceof import_complex19.default)
|
|
23321
23915
|
return numericCostFunction(num.re) + numericCostFunction(num.im) + 1;
|
|
23322
23916
|
if (expr.isNumber)
|
|
23323
23917
|
return 2;
|
|
@@ -24259,11 +24853,11 @@ ${JSON.stringify(entry)}`
|
|
|
24259
24853
|
this._ONE = new BoxedNumber(this, 1);
|
|
24260
24854
|
this._HALF = new BoxedNumber(this, [1, 2]);
|
|
24261
24855
|
this._NEGATIVE_ONE = new BoxedNumber(this, -1);
|
|
24262
|
-
this._I = new BoxedNumber(this,
|
|
24856
|
+
this._I = new BoxedNumber(this, import_complex20.Complex.I);
|
|
24263
24857
|
this._NAN = new BoxedNumber(this, Number.NaN);
|
|
24264
24858
|
this._POSITIVE_INFINITY = new BoxedNumber(this, Number.POSITIVE_INFINITY);
|
|
24265
24859
|
this._NEGATIVE_INFINITY = new BoxedNumber(this, Number.NEGATIVE_INFINITY);
|
|
24266
|
-
this._COMPLEX_INFINITY = new BoxedNumber(this,
|
|
24860
|
+
this._COMPLEX_INFINITY = new BoxedNumber(this, import_complex20.Complex.INFINITY);
|
|
24267
24861
|
this.reset();
|
|
24268
24862
|
this.context = {
|
|
24269
24863
|
assumptions: new ExpressionMap(),
|
|
@@ -24501,7 +25095,7 @@ ${JSON.stringify(entry)}`
|
|
|
24501
25095
|
return 0;
|
|
24502
25096
|
if (n instanceof Decimal && n.abs().lte(this._bignumTolerance))
|
|
24503
25097
|
return 0;
|
|
24504
|
-
if (n instanceof
|
|
25098
|
+
if (n instanceof import_complex20.Complex && Math.abs(n.re) <= this._tolerance && Math.abs(n.im) <= this._tolerance)
|
|
24505
25099
|
return 0;
|
|
24506
25100
|
return n;
|
|
24507
25101
|
}
|
|
@@ -24515,13 +25109,13 @@ ${JSON.stringify(entry)}`
|
|
|
24515
25109
|
a = a.toNumber();
|
|
24516
25110
|
if (b instanceof Decimal)
|
|
24517
25111
|
b = b.toNumber();
|
|
24518
|
-
return new
|
|
25112
|
+
return new import_complex20.Complex(a, b);
|
|
24519
25113
|
}
|
|
24520
25114
|
isBignum(a) {
|
|
24521
25115
|
return a instanceof Decimal;
|
|
24522
25116
|
}
|
|
24523
25117
|
isComplex(a) {
|
|
24524
|
-
return a instanceof
|
|
25118
|
+
return a instanceof import_complex20.Complex;
|
|
24525
25119
|
}
|
|
24526
25120
|
get latexSyntax() {
|
|
24527
25121
|
if (!this._latexSyntax)
|
|
@@ -24881,6 +25475,10 @@ ${JSON.stringify(entry)}`
|
|
|
24881
25475
|
return canonicalPower(this, base, this._HALF, metadata);
|
|
24882
25476
|
}
|
|
24883
25477
|
pow(base, exponent, metadata) {
|
|
25478
|
+
if (base.symbol === "ExponentialE" && exponent instanceof import_complex20.Complex && exponent.re === 0) {
|
|
25479
|
+
const im = exponent.im;
|
|
25480
|
+
return this.number(this.complex(Math.cos(im), Math.sin(im)));
|
|
25481
|
+
}
|
|
24884
25482
|
if (exponent instanceof AbstractBoxedExpression) {
|
|
24885
25483
|
const num = exponent.numericValue;
|
|
24886
25484
|
if (num !== null) {
|
|
@@ -25062,14 +25660,15 @@ ${JSON.stringify(entry)}`
|
|
|
25062
25660
|
const result = this.latexSyntax.parse(latexString(latex) ?? latex);
|
|
25063
25661
|
return this.box(result, options);
|
|
25064
25662
|
}
|
|
25065
|
-
serialize(x) {
|
|
25663
|
+
serialize(x, options) {
|
|
25066
25664
|
if (typeof x === "object" && "json" in x) {
|
|
25067
25665
|
const ce = "engine" in x ? x.engine : this;
|
|
25068
25666
|
return this.latexSyntax.serialize(
|
|
25069
|
-
this.rawJson(ce.box(x, { canonical: false }))
|
|
25667
|
+
this.rawJson(ce.box(x, { canonical: false })),
|
|
25668
|
+
options
|
|
25070
25669
|
);
|
|
25071
25670
|
}
|
|
25072
|
-
return this.latexSyntax.serialize(x);
|
|
25671
|
+
return this.latexSyntax.serialize(x, options);
|
|
25073
25672
|
}
|
|
25074
25673
|
get latexOptions() {
|
|
25075
25674
|
const latexSyntax = this.latexSyntax;
|
|
@@ -25230,10 +25829,10 @@ ${JSON.stringify(entry)}`
|
|
|
25230
25829
|
};
|
|
25231
25830
|
|
|
25232
25831
|
// src/compute-engine.ts
|
|
25233
|
-
var version = "0.
|
|
25832
|
+
var version = "0.15.0";
|
|
25234
25833
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
25235
25834
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
25236
|
-
version: "0.
|
|
25835
|
+
version: "0.15.0"
|
|
25237
25836
|
};
|
|
25238
25837
|
return __toCommonJS(compute_engine_exports);
|
|
25239
25838
|
})();
|