@cortex-js/compute-engine 0.20.2 → 0.21.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 +585 -153
- package/dist/compute-engine.js +585 -153
- package/dist/compute-engine.min.esm.js +10 -10
- package/dist/compute-engine.min.js +10 -10
- 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/ansi-codes.d.ts +1 -1
- 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 +8 -2
- 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/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +265 -29
- 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/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/public.d.ts +5 -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 +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +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 +3 -3
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +8 -260
- 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/derivative.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 +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** CortexJS Compute Engine 0.
|
|
1
|
+
/** CortexJS Compute Engine 0.21.0 */
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -1063,7 +1063,7 @@ function isEnvironmentEntry(entry) {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
|
|
1065
1065
|
// src/compute-engine/compute-engine.ts
|
|
1066
|
-
var import_complex20 = __toESM(require_complex());
|
|
1066
|
+
var import_complex20 = __toESM(require_complex(), 1);
|
|
1067
1067
|
|
|
1068
1068
|
// node_modules/decimal.js/decimal.mjs
|
|
1069
1069
|
var EXP_LIMIT = 9e15;
|
|
@@ -5935,23 +5935,7 @@ var DEFINITIONS_CORE = [
|
|
|
5935
5935
|
kind: "environment",
|
|
5936
5936
|
name: "Which",
|
|
5937
5937
|
identifierTrigger: "cases",
|
|
5938
|
-
parse:
|
|
5939
|
-
const tabular = parser.parseTabular();
|
|
5940
|
-
if (!tabular)
|
|
5941
|
-
return ["Which"];
|
|
5942
|
-
const result = ["Which"];
|
|
5943
|
-
for (const row of tabular) {
|
|
5944
|
-
if (row.length === 1) {
|
|
5945
|
-
result.push("True");
|
|
5946
|
-
result.push(row[0]);
|
|
5947
|
-
} else if (row.length === 2) {
|
|
5948
|
-
const s = stringValue(row[1]);
|
|
5949
|
-
result.push(s ? "True" : stripText(row[1]) ?? "True");
|
|
5950
|
-
result.push(row[0]);
|
|
5951
|
-
}
|
|
5952
|
-
}
|
|
5953
|
-
return result;
|
|
5954
|
-
},
|
|
5938
|
+
parse: parseWhich,
|
|
5955
5939
|
serialize: (serialize, expr) => {
|
|
5956
5940
|
const rows = [];
|
|
5957
5941
|
const args = ops(expr);
|
|
@@ -5965,6 +5949,16 @@ var DEFINITIONS_CORE = [
|
|
|
5965
5949
|
}
|
|
5966
5950
|
return joinLatex(["\\begin{cases}", rows.join("\\\\"), "\\end{cases}"]);
|
|
5967
5951
|
}
|
|
5952
|
+
},
|
|
5953
|
+
{
|
|
5954
|
+
kind: "environment",
|
|
5955
|
+
identifierTrigger: "dcases",
|
|
5956
|
+
parse: parseWhich
|
|
5957
|
+
},
|
|
5958
|
+
{
|
|
5959
|
+
kind: "environment",
|
|
5960
|
+
identifierTrigger: "rcases",
|
|
5961
|
+
parse: parseWhich
|
|
5968
5962
|
}
|
|
5969
5963
|
];
|
|
5970
5964
|
function parseTextRun(parser, style) {
|
|
@@ -6285,6 +6279,23 @@ function parseAssign(parser, lhs) {
|
|
|
6285
6279
|
}
|
|
6286
6280
|
return ["Assign", lhs, rhs];
|
|
6287
6281
|
}
|
|
6282
|
+
function parseWhich(parser) {
|
|
6283
|
+
const tabular = parser.parseTabular();
|
|
6284
|
+
if (!tabular)
|
|
6285
|
+
return ["Which"];
|
|
6286
|
+
const result = ["Which"];
|
|
6287
|
+
for (const row of tabular) {
|
|
6288
|
+
if (row.length === 1) {
|
|
6289
|
+
result.push("True");
|
|
6290
|
+
result.push(row[0]);
|
|
6291
|
+
} else if (row.length === 2) {
|
|
6292
|
+
const s = stringValue(row[1]);
|
|
6293
|
+
result.push(s ? "True" : stripText(row[1]) ?? "True");
|
|
6294
|
+
result.push(row[0]);
|
|
6295
|
+
}
|
|
6296
|
+
}
|
|
6297
|
+
return result;
|
|
6298
|
+
}
|
|
6288
6299
|
|
|
6289
6300
|
// src/compute-engine/latex-syntax/dictionary/definitions-inequalities.ts
|
|
6290
6301
|
var DEFINITIONS_INEQUALITIES = [
|
|
@@ -6693,103 +6704,239 @@ var DEFINITIONS_LINEAR_ALGEBRA = [
|
|
|
6693
6704
|
// The third, optional, argument is the column specification.
|
|
6694
6705
|
{
|
|
6695
6706
|
name: "Matrix",
|
|
6696
|
-
// https://ctan.math.illinois.edu/macros/latex/required/tools/array.pdf
|
|
6697
6707
|
serialize: (serializer, expr) => {
|
|
6698
|
-
const
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
if (
|
|
6771
|
-
return
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6708
|
+
const rows = ops(op(expr, 1)) ?? [];
|
|
6709
|
+
return serializeTabular(
|
|
6710
|
+
serializer,
|
|
6711
|
+
rows,
|
|
6712
|
+
stringValue(op(expr, 2)),
|
|
6713
|
+
stringValue(op(expr, 3))
|
|
6714
|
+
);
|
|
6715
|
+
}
|
|
6716
|
+
},
|
|
6717
|
+
// Vector is a specialized collection to represent a column vector.
|
|
6718
|
+
{
|
|
6719
|
+
name: "Vector",
|
|
6720
|
+
serialize: (serializer, expr) => {
|
|
6721
|
+
const columns = ops(expr) ?? [];
|
|
6722
|
+
return serializeTabular(
|
|
6723
|
+
serializer,
|
|
6724
|
+
columns.map((column) => ["List", column]),
|
|
6725
|
+
stringValue(op(expr, 2)),
|
|
6726
|
+
stringValue(op(expr, 3))
|
|
6727
|
+
);
|
|
6728
|
+
}
|
|
6729
|
+
},
|
|
6730
|
+
{
|
|
6731
|
+
kind: "environment",
|
|
6732
|
+
identifierTrigger: "pmatrix",
|
|
6733
|
+
parse: (parser) => {
|
|
6734
|
+
const columns = parseColumnFormat(parser);
|
|
6735
|
+
const [head2, cells] = parseCells(parser);
|
|
6736
|
+
if (columns)
|
|
6737
|
+
return [head2, cells, { str: "()" }, { str: columns }];
|
|
6738
|
+
return [head2, cells];
|
|
6739
|
+
}
|
|
6740
|
+
},
|
|
6741
|
+
{
|
|
6742
|
+
kind: "environment",
|
|
6743
|
+
identifierTrigger: "bmatrix",
|
|
6744
|
+
parse: (parser) => {
|
|
6745
|
+
const columns = parseColumnFormat(parser);
|
|
6746
|
+
const [head2, cells] = parseCells(parser);
|
|
6747
|
+
if (columns)
|
|
6748
|
+
return [head2, cells, { str: "[]" }, { str: columns }];
|
|
6749
|
+
return [head2, cells, { str: "[]" }];
|
|
6750
|
+
}
|
|
6751
|
+
},
|
|
6752
|
+
{
|
|
6753
|
+
kind: "environment",
|
|
6754
|
+
identifierTrigger: "Bmatrix",
|
|
6755
|
+
parse: (parser) => {
|
|
6756
|
+
const columns = parseColumnFormat(parser);
|
|
6757
|
+
const [head2, cells] = parseCells(parser);
|
|
6758
|
+
if (columns)
|
|
6759
|
+
return [head2, cells, { str: "{}" }, { str: columns }];
|
|
6760
|
+
return [head2, cells, { str: "{}" }];
|
|
6761
|
+
}
|
|
6762
|
+
},
|
|
6763
|
+
{
|
|
6764
|
+
kind: "environment",
|
|
6765
|
+
identifierTrigger: "vmatrix",
|
|
6766
|
+
parse: (parser) => {
|
|
6767
|
+
const columns = parseColumnFormat(parser);
|
|
6768
|
+
const [head2, cells] = parseCells(parser);
|
|
6769
|
+
if (columns)
|
|
6770
|
+
return [head2, cells, { str: "||" }, { str: columns }];
|
|
6771
|
+
return [head2, cells, { str: "||" }];
|
|
6772
|
+
}
|
|
6773
|
+
},
|
|
6774
|
+
{
|
|
6775
|
+
kind: "environment",
|
|
6776
|
+
identifierTrigger: "Vmatrix",
|
|
6777
|
+
parse: (parser) => {
|
|
6778
|
+
const columns = parseColumnFormat(parser);
|
|
6779
|
+
const [head2, cells] = parseCells(parser);
|
|
6780
|
+
if (columns)
|
|
6781
|
+
return [head2, cells, { str: "\u2016\u2016" }, { str: columns }];
|
|
6782
|
+
return [head2, cells, { str: "\u2016\u2016" }];
|
|
6783
|
+
}
|
|
6784
|
+
},
|
|
6785
|
+
{
|
|
6786
|
+
kind: "environment",
|
|
6787
|
+
identifierTrigger: "smallmatrix",
|
|
6788
|
+
parse: (parser) => {
|
|
6789
|
+
const columns = parseColumnFormat(parser);
|
|
6790
|
+
const [head2, cells] = parseCells(parser);
|
|
6791
|
+
if (columns)
|
|
6792
|
+
return [head2, cells, { str: "()" }, { str: columns }];
|
|
6793
|
+
return [head2, cells];
|
|
6794
|
+
}
|
|
6795
|
+
},
|
|
6796
|
+
{
|
|
6797
|
+
kind: "environment",
|
|
6798
|
+
identifierTrigger: "array",
|
|
6799
|
+
parse: (parser) => {
|
|
6800
|
+
const columns = parseColumnFormat(parser, false);
|
|
6801
|
+
const [head2, cells] = parseCells(parser);
|
|
6802
|
+
if (columns)
|
|
6803
|
+
return [head2, cells, { str: ".." }, { str: columns }];
|
|
6804
|
+
return [head2, cells, { str: ".." }];
|
|
6805
|
+
}
|
|
6806
|
+
},
|
|
6807
|
+
{
|
|
6808
|
+
kind: "environment",
|
|
6809
|
+
identifierTrigger: "matrix",
|
|
6810
|
+
parse: (parser) => {
|
|
6811
|
+
const columns = parseColumnFormat(parser);
|
|
6812
|
+
const [head2, cells] = parseCells(parser);
|
|
6813
|
+
if (columns)
|
|
6814
|
+
return [head2, cells, { str: ".." }, { str: columns }];
|
|
6815
|
+
return [head2, cells, { str: ".." }];
|
|
6816
|
+
}
|
|
6817
|
+
},
|
|
6818
|
+
{
|
|
6819
|
+
kind: "environment",
|
|
6820
|
+
identifierTrigger: "matrix*",
|
|
6821
|
+
parse: (parser) => {
|
|
6822
|
+
const columns = parseColumnFormat(parser);
|
|
6823
|
+
const [head2, cells] = parseCells(parser);
|
|
6824
|
+
if (columns)
|
|
6825
|
+
return [head2, cells, { str: ".." }, { str: columns }];
|
|
6826
|
+
return [head2, cells, { str: ".." }];
|
|
6790
6827
|
}
|
|
6791
6828
|
}
|
|
6792
6829
|
];
|
|
6830
|
+
function parseCells(parser) {
|
|
6831
|
+
const tabular = parser.parseTabular();
|
|
6832
|
+
if (!tabular)
|
|
6833
|
+
return ["", null];
|
|
6834
|
+
return [
|
|
6835
|
+
"Matrix",
|
|
6836
|
+
["List", ...tabular.map((row) => ["List", row])]
|
|
6837
|
+
];
|
|
6838
|
+
}
|
|
6839
|
+
function parseColumnFormat(parser, optional = true) {
|
|
6840
|
+
const colFormat = parser.parseStringGroup(optional)?.trim();
|
|
6841
|
+
if (!colFormat)
|
|
6842
|
+
return "";
|
|
6843
|
+
let result = "";
|
|
6844
|
+
for (const c of colFormat) {
|
|
6845
|
+
if (c === "c")
|
|
6846
|
+
result += "=";
|
|
6847
|
+
if (c === "l")
|
|
6848
|
+
result += "<";
|
|
6849
|
+
if (c === "r")
|
|
6850
|
+
result += ">";
|
|
6851
|
+
if (c === "|")
|
|
6852
|
+
result += "|";
|
|
6853
|
+
if (c === ":")
|
|
6854
|
+
result += ":";
|
|
6855
|
+
}
|
|
6856
|
+
return result;
|
|
6857
|
+
}
|
|
6858
|
+
function serializeTabular(serializer, rows, delims, colSpec) {
|
|
6859
|
+
delims ?? (delims = "()");
|
|
6860
|
+
let [open, close] = ["", ""];
|
|
6861
|
+
if (typeof delims === "string" && delims.length === 2)
|
|
6862
|
+
[open, close] = delims;
|
|
6863
|
+
let columns = "";
|
|
6864
|
+
if (colSpec) {
|
|
6865
|
+
for (const c of colSpec) {
|
|
6866
|
+
if (c === "<")
|
|
6867
|
+
columns += "l";
|
|
6868
|
+
else if (c === ">")
|
|
6869
|
+
columns += "r";
|
|
6870
|
+
else if (c === "=")
|
|
6871
|
+
columns += "c";
|
|
6872
|
+
else if (c === "|")
|
|
6873
|
+
columns += "|";
|
|
6874
|
+
else if (c === ":")
|
|
6875
|
+
columns += ":";
|
|
6876
|
+
}
|
|
6877
|
+
}
|
|
6878
|
+
const serializedRows = [];
|
|
6879
|
+
for (const row of rows ?? []) {
|
|
6880
|
+
const cells = [];
|
|
6881
|
+
for (const cell of ops(row) ?? [])
|
|
6882
|
+
cells.push(serializer.serialize(cell));
|
|
6883
|
+
serializedRows.push(cells.join(" & "));
|
|
6884
|
+
}
|
|
6885
|
+
const tabular = serializedRows.join("\\\\\n");
|
|
6886
|
+
const optColumns = columns.length > 0 ? `[${columns}]` : "";
|
|
6887
|
+
if (open === "(" && close === ")")
|
|
6888
|
+
return joinLatex([
|
|
6889
|
+
"\\begin{pmatrix}",
|
|
6890
|
+
optColumns,
|
|
6891
|
+
tabular,
|
|
6892
|
+
"\\end{pmatrix}"
|
|
6893
|
+
]);
|
|
6894
|
+
if (open === "[" && close === "]")
|
|
6895
|
+
return joinLatex([
|
|
6896
|
+
"\\begin{bmatrix}",
|
|
6897
|
+
optColumns,
|
|
6898
|
+
tabular,
|
|
6899
|
+
"\\end{bmatrix}"
|
|
6900
|
+
]);
|
|
6901
|
+
if (open === "{" && close === "}")
|
|
6902
|
+
return joinLatex([
|
|
6903
|
+
"\\begin{Bmatrix}",
|
|
6904
|
+
optColumns,
|
|
6905
|
+
tabular,
|
|
6906
|
+
"\\end{Bmatrix}"
|
|
6907
|
+
]);
|
|
6908
|
+
if (open === "|" && close === "|")
|
|
6909
|
+
return joinLatex([
|
|
6910
|
+
"\\begin{vmatrix}",
|
|
6911
|
+
optColumns,
|
|
6912
|
+
tabular,
|
|
6913
|
+
"\\end{vmatrix}"
|
|
6914
|
+
]);
|
|
6915
|
+
if (open === "\u2016" && close === "\u2016")
|
|
6916
|
+
return joinLatex([
|
|
6917
|
+
"\\begin{Vmatrix}",
|
|
6918
|
+
optColumns,
|
|
6919
|
+
tabular,
|
|
6920
|
+
"\\end{Vmatrix}"
|
|
6921
|
+
]);
|
|
6922
|
+
if (open === "{" && close === ".")
|
|
6923
|
+
return joinLatex(["\\begin{dcases}", optColumns, tabular, "\\end{dcases}"]);
|
|
6924
|
+
if (open === "." && close === "}")
|
|
6925
|
+
return joinLatex(["\\begin{rcases}", optColumns, tabular, "\\end{rcases}"]);
|
|
6926
|
+
if (columns || open !== "." || close !== ".") {
|
|
6927
|
+
return joinLatex([
|
|
6928
|
+
"\\left",
|
|
6929
|
+
DELIMITERS_SHORTHAND[open] ?? open,
|
|
6930
|
+
"\\begin{array}",
|
|
6931
|
+
`{${columns}}`,
|
|
6932
|
+
tabular,
|
|
6933
|
+
"\\end{array}",
|
|
6934
|
+
"\\right",
|
|
6935
|
+
DELIMITERS_SHORTHAND[close] ?? close
|
|
6936
|
+
]);
|
|
6937
|
+
}
|
|
6938
|
+
return joinLatex(["\\begin{matrix}", tabular, "\\end{matrix}"]);
|
|
6939
|
+
}
|
|
6793
6940
|
|
|
6794
6941
|
// src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
|
|
6795
6942
|
var DEFINITIONS_LOGIC = [
|
|
@@ -8699,7 +8846,7 @@ function isValidEntry(entry, onError) {
|
|
|
8699
8846
|
});
|
|
8700
8847
|
return false;
|
|
8701
8848
|
}
|
|
8702
|
-
if ("identifierTrigger" in entry) {
|
|
8849
|
+
if ("identifierTrigger" in entry && (!("kind" in entry) || entry.kind !== "environment")) {
|
|
8703
8850
|
if (typeof entry.identifierTrigger !== "string" || !isValidIdentifier(entry.identifierTrigger)) {
|
|
8704
8851
|
onError({
|
|
8705
8852
|
severity: "warning",
|
|
@@ -9668,12 +9815,14 @@ var _Parser = class {
|
|
|
9668
9815
|
return result;
|
|
9669
9816
|
}
|
|
9670
9817
|
/** Parse a group as a a string, for example for `\operatorname` or `\begin` */
|
|
9671
|
-
parseStringGroup() {
|
|
9818
|
+
parseStringGroup(optional) {
|
|
9819
|
+
if (optional === void 0)
|
|
9820
|
+
optional = false;
|
|
9672
9821
|
const start = this.index;
|
|
9673
9822
|
while (this.match("<space>")) {
|
|
9674
9823
|
}
|
|
9675
|
-
if (this.match("<{>")) {
|
|
9676
|
-
this.addBoundary(["<}>"]);
|
|
9824
|
+
if (this.match(optional ? "[" : "<{>")) {
|
|
9825
|
+
this.addBoundary([optional ? "]" : "<}>"]);
|
|
9677
9826
|
const arg = this.parseStringGroupContent();
|
|
9678
9827
|
if (this.matchBoundary())
|
|
9679
9828
|
return arg;
|
|
@@ -11424,13 +11573,13 @@ var LatexSyntax = class _LatexSyntax {
|
|
|
11424
11573
|
};
|
|
11425
11574
|
|
|
11426
11575
|
// src/compute-engine/domain-utils.ts
|
|
11427
|
-
var import_complex3 = __toESM(require_complex());
|
|
11576
|
+
var import_complex3 = __toESM(require_complex(), 1);
|
|
11428
11577
|
|
|
11429
11578
|
// src/compute-engine/numerics/rationals.ts
|
|
11430
|
-
var import_complex2 = __toESM(require_complex());
|
|
11579
|
+
var import_complex2 = __toESM(require_complex(), 1);
|
|
11431
11580
|
|
|
11432
11581
|
// src/compute-engine/numerics/numeric.ts
|
|
11433
|
-
var import_complex = __toESM(require_complex());
|
|
11582
|
+
var import_complex = __toESM(require_complex(), 1);
|
|
11434
11583
|
|
|
11435
11584
|
// src/compute-engine/numerics/richardson.ts
|
|
11436
11585
|
function extrapolate(f, x0, options = {}) {
|
|
@@ -13462,7 +13611,7 @@ function signatureToDomain(ce, sig) {
|
|
|
13462
13611
|
}
|
|
13463
13612
|
|
|
13464
13613
|
// src/compute-engine/boxed-expression/utils.ts
|
|
13465
|
-
var import_complex4 = __toESM(require_complex());
|
|
13614
|
+
var import_complex4 = __toESM(require_complex(), 1);
|
|
13466
13615
|
function isLatexString(s) {
|
|
13467
13616
|
if (typeof s === "string")
|
|
13468
13617
|
return s.startsWith("$") && s.endsWith("$");
|
|
@@ -13682,7 +13831,7 @@ function getWildcardName(s) {
|
|
|
13682
13831
|
}
|
|
13683
13832
|
|
|
13684
13833
|
// src/compute-engine/boxed-expression/order.ts
|
|
13685
|
-
var import_complex5 = __toESM(require_complex());
|
|
13834
|
+
var import_complex5 = __toESM(require_complex(), 1);
|
|
13686
13835
|
|
|
13687
13836
|
// src/compute-engine/symbolic/polynomials.ts
|
|
13688
13837
|
function totalDegree(expr) {
|
|
@@ -13730,7 +13879,7 @@ function lex(expr) {
|
|
|
13730
13879
|
|
|
13731
13880
|
// src/compute-engine/boxed-expression/order.ts
|
|
13732
13881
|
var DEFAULT_COMPLEXITY = 1e5;
|
|
13733
|
-
function sortAdd(
|
|
13882
|
+
function sortAdd(ops2) {
|
|
13734
13883
|
return ops2.sort((a, b) => {
|
|
13735
13884
|
const aLex = lex(a);
|
|
13736
13885
|
const bLex = lex(b);
|
|
@@ -13850,6 +13999,15 @@ function order(a, b) {
|
|
|
13850
13999
|
}
|
|
13851
14000
|
return (a.complexity ?? DEFAULT_COMPLEXITY) - (b.complexity ?? DEFAULT_COMPLEXITY);
|
|
13852
14001
|
}
|
|
14002
|
+
function canonicalOrder(expr, { recursive = false }) {
|
|
14003
|
+
if (expr.ops) {
|
|
14004
|
+
const ops2 = recursive ? expr.ops.map((x) => canonicalOrder(x, { recursive })) : expr.ops;
|
|
14005
|
+
if (expr.head === "Add")
|
|
14006
|
+
return expr.engine._fn("Add", sortAdd(ops2));
|
|
14007
|
+
return expr.engine._fn(expr.head, ops2.sort(order));
|
|
14008
|
+
}
|
|
14009
|
+
return expr;
|
|
14010
|
+
}
|
|
13853
14011
|
function getLeafCount(expr) {
|
|
13854
14012
|
if (expr.keys !== null)
|
|
13855
14013
|
return 1 + expr.keysCount;
|
|
@@ -13900,7 +14058,7 @@ function flattenSequence(xs) {
|
|
|
13900
14058
|
}
|
|
13901
14059
|
|
|
13902
14060
|
// src/compute-engine/symbolic/sum.ts
|
|
13903
|
-
var import_complex6 = __toESM(require_complex());
|
|
14061
|
+
var import_complex6 = __toESM(require_complex(), 1);
|
|
13904
14062
|
|
|
13905
14063
|
// src/compute-engine/collection-utils.ts
|
|
13906
14064
|
function isCollection(col) {
|
|
@@ -14205,7 +14363,7 @@ var Sum = class {
|
|
|
14205
14363
|
return ce.Zero;
|
|
14206
14364
|
if (xs.length === 1 && !isIndexableCollection(xs[0]))
|
|
14207
14365
|
return xs[0];
|
|
14208
|
-
return ce._fn("Add", sortAdd(
|
|
14366
|
+
return ce._fn("Add", sortAdd(xs));
|
|
14209
14367
|
}
|
|
14210
14368
|
};
|
|
14211
14369
|
|
|
@@ -14415,10 +14573,10 @@ function domainSetsLibrary() {
|
|
|
14415
14573
|
}
|
|
14416
14574
|
|
|
14417
14575
|
// src/compute-engine/boxed-expression/abstract-boxed-expression.ts
|
|
14418
|
-
var import_complex8 = __toESM(require_complex());
|
|
14576
|
+
var import_complex8 = __toESM(require_complex(), 1);
|
|
14419
14577
|
|
|
14420
14578
|
// src/compute-engine/symbolic/utils.ts
|
|
14421
|
-
var import_complex7 = __toESM(require_complex());
|
|
14579
|
+
var import_complex7 = __toESM(require_complex(), 1);
|
|
14422
14580
|
function makePositive(expr) {
|
|
14423
14581
|
if (expr.head === "Negate")
|
|
14424
14582
|
return [-1, expr.op1];
|
|
@@ -15595,6 +15753,7 @@ var _BoxedExpression = class {
|
|
|
15595
15753
|
set value(_value) {
|
|
15596
15754
|
throw new Error(`Can't change the value of \\(${this.latex}\\)`);
|
|
15597
15755
|
}
|
|
15756
|
+
// @ts-ignore
|
|
15598
15757
|
get domain() {
|
|
15599
15758
|
return void 0;
|
|
15600
15759
|
}
|
|
@@ -15960,7 +16119,7 @@ function canonicalAdd(ce, ops2) {
|
|
|
15960
16119
|
return ce.number(ce.complex(re, im));
|
|
15961
16120
|
}
|
|
15962
16121
|
if (ops2.length > 1)
|
|
15963
|
-
ops2 = sortAdd(
|
|
16122
|
+
ops2 = sortAdd(ops2);
|
|
15964
16123
|
return ce._fn("Add", ops2);
|
|
15965
16124
|
}
|
|
15966
16125
|
function domainAdd(_ce, args) {
|
|
@@ -16064,12 +16223,16 @@ function evalSummation(ce, expr, range, mode) {
|
|
|
16064
16223
|
}
|
|
16065
16224
|
return result ?? void 0;
|
|
16066
16225
|
}
|
|
16067
|
-
const [index, lower, upper, isFinite2] = normalizeLimits(range);
|
|
16226
|
+
const [index, lower, upper, isFinite2] = normalizeLimits(range.evaluate());
|
|
16068
16227
|
if (!index)
|
|
16069
16228
|
return void 0;
|
|
16070
16229
|
const fn = expr;
|
|
16071
|
-
if (
|
|
16230
|
+
if (lower >= upper)
|
|
16231
|
+
return void 0;
|
|
16232
|
+
if (mode === "simplify" && upper - lower >= MAX_SYMBOLIC_TERMS)
|
|
16072
16233
|
return void 0;
|
|
16234
|
+
if (mode === "evaluate" && upper - lower >= MAX_SYMBOLIC_TERMS)
|
|
16235
|
+
mode = "N";
|
|
16073
16236
|
const savedContext = ce.swapScope(fn.scope);
|
|
16074
16237
|
ce.pushScope();
|
|
16075
16238
|
fn.bind();
|
|
@@ -16168,7 +16331,7 @@ function evalSummation(ce, expr, range, mode) {
|
|
|
16168
16331
|
}
|
|
16169
16332
|
|
|
16170
16333
|
// src/compute-engine/symbolic/negate.ts
|
|
16171
|
-
var import_complex9 = __toESM(require_complex());
|
|
16334
|
+
var import_complex9 = __toESM(require_complex(), 1);
|
|
16172
16335
|
function negateLiteral(expr, metadata) {
|
|
16173
16336
|
let n = expr.numericValue;
|
|
16174
16337
|
if (n === null)
|
|
@@ -16700,10 +16863,10 @@ function isInequality(expr) {
|
|
|
16700
16863
|
}
|
|
16701
16864
|
|
|
16702
16865
|
// src/compute-engine/boxed-expression/box.ts
|
|
16703
|
-
var import_complex14 = __toESM(require_complex());
|
|
16866
|
+
var import_complex14 = __toESM(require_complex(), 1);
|
|
16704
16867
|
|
|
16705
16868
|
// src/compute-engine/boxed-expression/serialize.ts
|
|
16706
|
-
var import_complex11 = __toESM(require_complex());
|
|
16869
|
+
var import_complex11 = __toESM(require_complex(), 1);
|
|
16707
16870
|
|
|
16708
16871
|
// src/compute-engine/numerics/numeric-bignum.ts
|
|
16709
16872
|
function gcd3(a, b) {
|
|
@@ -16828,7 +16991,7 @@ function isInMachineRange(d) {
|
|
|
16828
16991
|
}
|
|
16829
16992
|
|
|
16830
16993
|
// src/compute-engine/symbolic/product.ts
|
|
16831
|
-
var import_complex10 = __toESM(require_complex());
|
|
16994
|
+
var import_complex10 = __toESM(require_complex(), 1);
|
|
16832
16995
|
var Product = class {
|
|
16833
16996
|
constructor(ce, xs, options) {
|
|
16834
16997
|
this.options = options;
|
|
@@ -17776,7 +17939,7 @@ var BoxedDictionary = class _BoxedDictionary extends _BoxedExpression {
|
|
|
17776
17939
|
};
|
|
17777
17940
|
|
|
17778
17941
|
// src/compute-engine/boxed-expression/boxed-function.ts
|
|
17779
|
-
var import_complex12 = __toESM(require_complex());
|
|
17942
|
+
var import_complex12 = __toESM(require_complex(), 1);
|
|
17780
17943
|
|
|
17781
17944
|
// src/compute-engine/simplify-rules.ts
|
|
17782
17945
|
var SIMPLIFY_RULES = [];
|
|
@@ -18499,7 +18662,7 @@ function cheapest(oldExpr, newExpr) {
|
|
|
18499
18662
|
}
|
|
18500
18663
|
|
|
18501
18664
|
// src/compute-engine/boxed-expression/boxed-number.ts
|
|
18502
|
-
var import_complex13 = __toESM(require_complex());
|
|
18665
|
+
var import_complex13 = __toESM(require_complex(), 1);
|
|
18503
18666
|
|
|
18504
18667
|
// src/compute-engine/numerics/primes.ts
|
|
18505
18668
|
var LARGE_PRIME = 1125899906842597;
|
|
@@ -19387,7 +19550,7 @@ function asString(expr) {
|
|
|
19387
19550
|
}
|
|
19388
19551
|
|
|
19389
19552
|
// src/compute-engine/library/arithmetic.ts
|
|
19390
|
-
var import_complex16 = __toESM(require_complex());
|
|
19553
|
+
var import_complex16 = __toESM(require_complex(), 1);
|
|
19391
19554
|
|
|
19392
19555
|
// src/compute-engine/numerics/numeric-complex.ts
|
|
19393
19556
|
function gamma3(c) {
|
|
@@ -19398,7 +19561,7 @@ function gammaln3(c) {
|
|
|
19398
19561
|
}
|
|
19399
19562
|
|
|
19400
19563
|
// src/compute-engine/library/arithmetic-power.ts
|
|
19401
|
-
var import_complex15 = __toESM(require_complex());
|
|
19564
|
+
var import_complex15 = __toESM(require_complex(), 1);
|
|
19402
19565
|
function canonicalPower(ce, base, exponent, metadata) {
|
|
19403
19566
|
if (exponent.symbol === "ComplexInfinity")
|
|
19404
19567
|
return ce.NaN;
|
|
@@ -22583,6 +22746,15 @@ function indexes(ranges) {
|
|
|
22583
22746
|
return result;
|
|
22584
22747
|
}
|
|
22585
22748
|
function canonicalList(ce, ops2) {
|
|
22749
|
+
const op12 = ops2[0];
|
|
22750
|
+
if (ops2.length === 1 && op12.head === "Matrix") {
|
|
22751
|
+
const [body, delimiters, columns] = op12.ops;
|
|
22752
|
+
if (!delimiters || delimiters.string === "..") {
|
|
22753
|
+
if (!columns)
|
|
22754
|
+
return ce._fn("Matrix", [body, delimiters]);
|
|
22755
|
+
return ce._fn("Matrix", [body, ce.string("[]"), columns]);
|
|
22756
|
+
}
|
|
22757
|
+
}
|
|
22586
22758
|
ops2 = ops2.map((op3) => {
|
|
22587
22759
|
if (op3.head === "Delimiter") {
|
|
22588
22760
|
if (op3.op1.head === "Sequence")
|
|
@@ -23426,6 +23598,18 @@ var CORE_LIBRARY = [
|
|
|
23426
23598
|
evaluate: (_ce, ops2) => ops2[0].simplify()
|
|
23427
23599
|
}
|
|
23428
23600
|
},
|
|
23601
|
+
// Can be used to sort arguments of an expression.
|
|
23602
|
+
// Sorting arguments of commutative functions is a weak form of
|
|
23603
|
+
// canonicalization that can be useful in some cases, for example
|
|
23604
|
+
// to accept "x+1" and "1+x" while rejecting "x+1" and "2x-x+1"
|
|
23605
|
+
CanonicalOrder: {
|
|
23606
|
+
complexity: 8200,
|
|
23607
|
+
hold: "all",
|
|
23608
|
+
signature: {
|
|
23609
|
+
domain: ["FunctionOf", "Anything", "Anything"],
|
|
23610
|
+
canonical: (_ce, ops2) => canonicalOrder(ops2[0], { recursive: true })
|
|
23611
|
+
}
|
|
23612
|
+
},
|
|
23429
23613
|
N: {
|
|
23430
23614
|
hold: "all",
|
|
23431
23615
|
signature: {
|
|
@@ -23709,22 +23893,40 @@ var LINEAR_ALGEBRA_LIBRARY = [
|
|
|
23709
23893
|
evaluate: (_ce, ops2) => ops2[0].evaluate(),
|
|
23710
23894
|
N: (_ce, ops2) => ops2[0].N()
|
|
23711
23895
|
}
|
|
23896
|
+
},
|
|
23897
|
+
// Vector is a specialized collection to represent a column vector.
|
|
23898
|
+
// ["Vector", a, b, c] is a shorthand for ["List", ["List", a], ["List", b], ["List", c]]
|
|
23899
|
+
Vector: {
|
|
23900
|
+
complexity: 9e3,
|
|
23901
|
+
hold: "all",
|
|
23902
|
+
signature: {
|
|
23903
|
+
restParam: "Anything",
|
|
23904
|
+
result: "Lists",
|
|
23905
|
+
canonical: (ce, ops2) => {
|
|
23906
|
+
return ce._fn("Matrix", [
|
|
23907
|
+
ce._fn(
|
|
23908
|
+
"List",
|
|
23909
|
+
ce.canonical(ops2).map((op3) => ce._fn("List", [op3]))
|
|
23910
|
+
)
|
|
23911
|
+
]);
|
|
23912
|
+
}
|
|
23913
|
+
}
|
|
23712
23914
|
}
|
|
23713
23915
|
}
|
|
23714
23916
|
];
|
|
23715
|
-
function canonicalMatrix(ce, ops2) {
|
|
23917
|
+
function canonicalMatrix(ce, ops2, head2 = "Matrix") {
|
|
23716
23918
|
if (ops2.length === 0)
|
|
23717
|
-
return ce._fn(
|
|
23718
|
-
const body = ops2[0].canonical;
|
|
23919
|
+
return ce._fn(head2, []);
|
|
23920
|
+
const body = ops2[0].head === "Vector" ? ops2[0].canonical.ops[0] : ops2[0].canonical;
|
|
23719
23921
|
const delims = ops2[1]?.canonical;
|
|
23720
23922
|
const columns = ops2[2]?.canonical;
|
|
23721
23923
|
if (ops2.length > 3)
|
|
23722
|
-
return ce._fn(
|
|
23924
|
+
return ce._fn(head2, checkArity(ce, ops2, 3));
|
|
23723
23925
|
if (columns)
|
|
23724
|
-
return ce._fn(
|
|
23926
|
+
return ce._fn(head2, [body, delims, columns]);
|
|
23725
23927
|
if (delims)
|
|
23726
|
-
return ce._fn(
|
|
23727
|
-
return ce._fn(
|
|
23928
|
+
return ce._fn(head2, [body, delims]);
|
|
23929
|
+
return ce._fn(head2, [body]);
|
|
23728
23930
|
}
|
|
23729
23931
|
|
|
23730
23932
|
// src/compute-engine/library/logic.ts
|
|
@@ -23962,6 +24164,28 @@ var RELOP_LIBRARY = {
|
|
|
23962
24164
|
}
|
|
23963
24165
|
}
|
|
23964
24166
|
},
|
|
24167
|
+
IsSame: {
|
|
24168
|
+
description: "Compare two expressions for structural equality",
|
|
24169
|
+
hold: "all",
|
|
24170
|
+
signature: {
|
|
24171
|
+
domain: "RelationalOperators",
|
|
24172
|
+
// Since we want to work on non-canonical expressions,
|
|
24173
|
+
// do nothing to canonicalize the arguments
|
|
24174
|
+
evaluate: (ce, ops2) => {
|
|
24175
|
+
if (ops2.length !== 2)
|
|
24176
|
+
return void 0;
|
|
24177
|
+
let [lhs, rhs] = ops2;
|
|
24178
|
+
if (lhs.head === "CanonicalOrder")
|
|
24179
|
+
lhs = lhs.canonical;
|
|
24180
|
+
if (rhs.head === "CanonicalOrder")
|
|
24181
|
+
rhs = rhs.canonical;
|
|
24182
|
+
const test = lhs.isSame(rhs);
|
|
24183
|
+
if (test === true)
|
|
24184
|
+
return ce.True;
|
|
24185
|
+
return ce.False;
|
|
24186
|
+
}
|
|
24187
|
+
}
|
|
24188
|
+
},
|
|
23965
24189
|
Equal: {
|
|
23966
24190
|
commutative: true,
|
|
23967
24191
|
complexity: 11e3,
|
|
@@ -25649,7 +25873,7 @@ function evalTrig(ce, mode, head2, op3) {
|
|
|
25649
25873
|
}
|
|
25650
25874
|
|
|
25651
25875
|
// src/compute-engine/boxed-expression/boxed-symbol-definition.ts
|
|
25652
|
-
var import_complex17 = __toESM(require_complex());
|
|
25876
|
+
var import_complex17 = __toESM(require_complex(), 1);
|
|
25653
25877
|
var _BoxedSymbolDefinition = class {
|
|
25654
25878
|
// @todo
|
|
25655
25879
|
constructor(ce, name, def) {
|
|
@@ -26641,7 +26865,7 @@ function isFunctionDefinition(def) {
|
|
|
26641
26865
|
}
|
|
26642
26866
|
|
|
26643
26867
|
// src/compute-engine/cost-function.ts
|
|
26644
|
-
var import_complex19 = __toESM(require_complex());
|
|
26868
|
+
var import_complex19 = __toESM(require_complex(), 1);
|
|
26645
26869
|
function numericCostFunction(n) {
|
|
26646
26870
|
if (Number.isInteger(n) && n !== 0) {
|
|
26647
26871
|
return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
|
|
@@ -27223,6 +27447,7 @@ var BoxedSymbol = class _BoxedSymbol extends _BoxedExpression {
|
|
|
27223
27447
|
});
|
|
27224
27448
|
}
|
|
27225
27449
|
}
|
|
27450
|
+
// @ts-ignore
|
|
27226
27451
|
get domain() {
|
|
27227
27452
|
const def = this._def;
|
|
27228
27453
|
if (def) {
|
|
@@ -27611,7 +27836,6 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27611
27836
|
symbols: /* @__PURE__ */ new Set(),
|
|
27612
27837
|
expressions: /* @__PURE__ */ new Set()
|
|
27613
27838
|
};
|
|
27614
|
-
this._defaultDomain = null;
|
|
27615
27839
|
this._numericMode = options?.numericMode ?? "auto";
|
|
27616
27840
|
this._precision = Math.max(
|
|
27617
27841
|
options?.numericPrecision ?? 100,
|
|
@@ -27855,6 +28079,56 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27855
28079
|
return 0;
|
|
27856
28080
|
return n;
|
|
27857
28081
|
}
|
|
28082
|
+
/** Create an arbitrary precision number.
|
|
28083
|
+
*
|
|
28084
|
+
* The return value is an object with methods to perform arithmetic
|
|
28085
|
+
* operations:
|
|
28086
|
+
* - `toNumber()`: convert to a JavaScript `number` with potential loss of precision
|
|
28087
|
+
* - `add()`
|
|
28088
|
+
* - `sub()`
|
|
28089
|
+
* - `neg()` (unary minus)
|
|
28090
|
+
* - `mul()`
|
|
28091
|
+
* - `div()`
|
|
28092
|
+
* - `pow()`
|
|
28093
|
+
* - `sqrt()` (square root)
|
|
28094
|
+
* - `cbrt()` (cube root)
|
|
28095
|
+
* - `exp()` (e^x)
|
|
28096
|
+
* - `log()`
|
|
28097
|
+
* - `ln()` (natural logarithm)
|
|
28098
|
+
* - `mod()`
|
|
28099
|
+
|
|
28100
|
+
* - `abs()`
|
|
28101
|
+
* - `ceil()`
|
|
28102
|
+
* - `floor()`
|
|
28103
|
+
* - `round()`
|
|
28104
|
+
|
|
28105
|
+
* - `equals()`
|
|
28106
|
+
* - `gt()`
|
|
28107
|
+
* - `gte()`
|
|
28108
|
+
* - `lt()`
|
|
28109
|
+
* - `lte()`
|
|
28110
|
+
*
|
|
28111
|
+
* - `cos()`
|
|
28112
|
+
* - `sin()`
|
|
28113
|
+
* - `tanh()`
|
|
28114
|
+
* - `acos()`
|
|
28115
|
+
* - `asin()`
|
|
28116
|
+
* - `atan()`
|
|
28117
|
+
* - `cosh()`
|
|
28118
|
+
* - `sinh()`
|
|
28119
|
+
* - `acosh()`
|
|
28120
|
+
* - `asinh()`
|
|
28121
|
+
* - `atanh()`
|
|
28122
|
+
*
|
|
28123
|
+
* - `isFinite()`
|
|
28124
|
+
* - `isInteger()`
|
|
28125
|
+
* - `isNaN()`
|
|
28126
|
+
* - `isNegative()`
|
|
28127
|
+
* - `isPositive()`
|
|
28128
|
+
* - `isZero()`
|
|
28129
|
+
* - `sign()` (1, 0 or -1)
|
|
28130
|
+
*
|
|
28131
|
+
*/
|
|
27858
28132
|
bignum(a) {
|
|
27859
28133
|
if (typeof a === "bigint")
|
|
27860
28134
|
return new this._bignum(a.toString());
|
|
@@ -27865,6 +28139,51 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27865
28139
|
}
|
|
27866
28140
|
return this._BIGNUM_NAN;
|
|
27867
28141
|
}
|
|
28142
|
+
/** Create a complex number.
|
|
28143
|
+
* The return value is an object with methods to perform arithmetic
|
|
28144
|
+
* operations:
|
|
28145
|
+
* - `re` (real part, as a JavaScript `number`)
|
|
28146
|
+
* - `im` (imaginary part, as a JavaScript `number`)
|
|
28147
|
+
* - `add()`
|
|
28148
|
+
* - `sub()`
|
|
28149
|
+
* - `neg()` (unary minus)
|
|
28150
|
+
* - `mul()`
|
|
28151
|
+
* - `div()`
|
|
28152
|
+
* - `pow()`
|
|
28153
|
+
* - `sqrt()` (square root)
|
|
28154
|
+
* - `exp()` (e^x)
|
|
28155
|
+
* - `log()`
|
|
28156
|
+
* - `ln()` (natural logarithm)
|
|
28157
|
+
* - `mod()`
|
|
28158
|
+
|
|
28159
|
+
* - `abs()`
|
|
28160
|
+
* - `ceil()`
|
|
28161
|
+
* - `floor()`
|
|
28162
|
+
* - `round()`
|
|
28163
|
+
|
|
28164
|
+
* - `arg()` the angle of the complex number
|
|
28165
|
+
* - `inverse()` the inverse of the complex number 1/z
|
|
28166
|
+
* - `conjugate()` the conjugate of the complex number
|
|
28167
|
+
|
|
28168
|
+
* - `equals()`
|
|
28169
|
+
*
|
|
28170
|
+
* - `cos()`
|
|
28171
|
+
* - `sin()`
|
|
28172
|
+
* - `tanh()`
|
|
28173
|
+
* - `acos()`
|
|
28174
|
+
* - `asin()`
|
|
28175
|
+
* - `atan()`
|
|
28176
|
+
* - `cosh()`
|
|
28177
|
+
* - `sinh()`
|
|
28178
|
+
* - `acosh()`
|
|
28179
|
+
* - `asinh()`
|
|
28180
|
+
* - `atanh()`
|
|
28181
|
+
*
|
|
28182
|
+
* - `isFinite()`
|
|
28183
|
+
* - `isNaN()`
|
|
28184
|
+
* - `isZero()`
|
|
28185
|
+
* - `sign()` (1, 0 or -1)
|
|
28186
|
+
*/
|
|
27868
28187
|
complex(a, b) {
|
|
27869
28188
|
if (a instanceof Decimal)
|
|
27870
28189
|
a = a.toNumber();
|
|
@@ -27968,7 +28287,14 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27968
28287
|
return void 0;
|
|
27969
28288
|
}
|
|
27970
28289
|
/**
|
|
27971
|
-
*
|
|
28290
|
+
* Associate a new definition to a symbol in the current context.
|
|
28291
|
+
*
|
|
28292
|
+
* If a definition existed previously, it is replaced.
|
|
28293
|
+
*
|
|
28294
|
+
*
|
|
28295
|
+
* For internal use. Use `ce.declare()` instead.
|
|
28296
|
+
*
|
|
28297
|
+
* @internal
|
|
27972
28298
|
*/
|
|
27973
28299
|
defineSymbol(name, def) {
|
|
27974
28300
|
if (!this.context)
|
|
@@ -27985,6 +28311,15 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27985
28311
|
this.context.ids.set(boxedDef.name, boxedDef);
|
|
27986
28312
|
return boxedDef;
|
|
27987
28313
|
}
|
|
28314
|
+
/**
|
|
28315
|
+
* Associate a new delookupSymbolfinition to a function in the current context.
|
|
28316
|
+
*
|
|
28317
|
+
* If a definition existed previously, it is replaced.
|
|
28318
|
+
*
|
|
28319
|
+
* For internal use. Use `ce.declare()` instead.
|
|
28320
|
+
*
|
|
28321
|
+
* @internal
|
|
28322
|
+
*/
|
|
27988
28323
|
defineFunction(name, def) {
|
|
27989
28324
|
if (!this.context)
|
|
27990
28325
|
throw Error("Function cannot be defined: no scope available");
|
|
@@ -28029,8 +28364,8 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28029
28364
|
};
|
|
28030
28365
|
return this;
|
|
28031
28366
|
}
|
|
28032
|
-
/** Remove the
|
|
28033
|
-
*/
|
|
28367
|
+
/** Remove the most recent scope from the scope stack, and set its
|
|
28368
|
+
* parent scope as current. */
|
|
28034
28369
|
popScope() {
|
|
28035
28370
|
if (!this.context)
|
|
28036
28371
|
throw Error("No scope available");
|
|
@@ -28038,12 +28373,17 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28038
28373
|
console.assert(this.context);
|
|
28039
28374
|
return this;
|
|
28040
28375
|
}
|
|
28376
|
+
/** Set the current scope, return the previous scope. */
|
|
28041
28377
|
swapScope(scope) {
|
|
28042
28378
|
const oldScope = this.context;
|
|
28043
28379
|
this.context = scope;
|
|
28044
28380
|
console.assert(this.context);
|
|
28045
28381
|
return oldScope;
|
|
28046
28382
|
}
|
|
28383
|
+
/**
|
|
28384
|
+
* Reset the value of any identifiers that have been assigned a value
|
|
28385
|
+
* in the current scope.
|
|
28386
|
+
* @internal */
|
|
28047
28387
|
resetContext() {
|
|
28048
28388
|
if (!this.context)
|
|
28049
28389
|
return;
|
|
@@ -28063,6 +28403,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28063
28403
|
}
|
|
28064
28404
|
}
|
|
28065
28405
|
}
|
|
28406
|
+
/** @internal */
|
|
28066
28407
|
_printScope(options, scope, depth = 0) {
|
|
28067
28408
|
options ?? (options = { details: false, maxDepth: 1 });
|
|
28068
28409
|
scope ?? (scope = this.context);
|
|
@@ -28373,6 +28714,9 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28373
28714
|
}
|
|
28374
28715
|
return this._cache[cacheName]?.value;
|
|
28375
28716
|
}
|
|
28717
|
+
/**
|
|
28718
|
+
* Return a boxed expression from the input.
|
|
28719
|
+
*/
|
|
28376
28720
|
box(expr, options) {
|
|
28377
28721
|
return box(this, expr, options);
|
|
28378
28722
|
}
|
|
@@ -28382,6 +28726,16 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28382
28726
|
const bxs = xs;
|
|
28383
28727
|
return bxs.every((x) => x.isCanonical) ? bxs : bxs.map((x) => x.canonical);
|
|
28384
28728
|
}
|
|
28729
|
+
/**
|
|
28730
|
+
* Return a function expression.
|
|
28731
|
+
*
|
|
28732
|
+
* Note that the result may not be a function, or may have a different
|
|
28733
|
+
* `head` than the one specified.
|
|
28734
|
+
*
|
|
28735
|
+
* For example:
|
|
28736
|
+
* `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
|
|
28737
|
+
*
|
|
28738
|
+
*/
|
|
28385
28739
|
fn(head2, ops2, options) {
|
|
28386
28740
|
return boxFunction(this, head2, ops2, options ?? { canonical: true });
|
|
28387
28741
|
}
|
|
@@ -28426,18 +28780,33 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28426
28780
|
const actual = actualDomain ? actualDomain : this.symbol("Undefined");
|
|
28427
28781
|
return this.error(["incompatible-domain", expected, actual], where);
|
|
28428
28782
|
}
|
|
28783
|
+
/**
|
|
28784
|
+
* Add a`["Hold"]` wrapper to `expr.
|
|
28785
|
+
*/
|
|
28429
28786
|
hold(expr) {
|
|
28430
28787
|
return this._fn("Hold", [this.box(expr, { canonical: false })]);
|
|
28431
28788
|
}
|
|
28789
|
+
/** Shortcut for `this.fn("Add"...)`.
|
|
28790
|
+
*
|
|
28791
|
+
* The result is canonical.
|
|
28792
|
+
*/
|
|
28432
28793
|
add(ops2, metadata) {
|
|
28433
28794
|
const result = canonicalAdd(this, flattenOps(flattenSequence(ops2), "Add"));
|
|
28434
28795
|
if (metadata?.latex !== void 0)
|
|
28435
28796
|
result.latex = metadata.latex;
|
|
28436
28797
|
return result;
|
|
28437
28798
|
}
|
|
28799
|
+
/** Shortcut for `this.fn("Negate", [expr])`
|
|
28800
|
+
*
|
|
28801
|
+
* The result is canonical.
|
|
28802
|
+
*/
|
|
28438
28803
|
neg(expr, metadata) {
|
|
28439
28804
|
return canonicalNegate(expr, metadata);
|
|
28440
28805
|
}
|
|
28806
|
+
/** Shortcut for `this.fn("Multiply"...)`
|
|
28807
|
+
*
|
|
28808
|
+
* The result is canonical.
|
|
28809
|
+
*/
|
|
28441
28810
|
mul(ops2, metadata) {
|
|
28442
28811
|
const result = canonicalMultiply(
|
|
28443
28812
|
this,
|
|
@@ -28447,15 +28816,27 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28447
28816
|
result.latex = metadata.latex;
|
|
28448
28817
|
return result;
|
|
28449
28818
|
}
|
|
28819
|
+
/** Shortcut for `this.fn("Divide", [num, denom])`
|
|
28820
|
+
*
|
|
28821
|
+
* The result is canonical.
|
|
28822
|
+
*/
|
|
28450
28823
|
div(num, denom, metadata) {
|
|
28451
28824
|
const result = canonicalDivide(this, num, denom);
|
|
28452
28825
|
if (metadata?.latex !== void 0)
|
|
28453
28826
|
result.latex = metadata.latex;
|
|
28454
28827
|
return result;
|
|
28455
28828
|
}
|
|
28829
|
+
/** Shortcut for `this.fn("Sqrt"...)`
|
|
28830
|
+
*
|
|
28831
|
+
* The result is canonical.
|
|
28832
|
+
*/
|
|
28456
28833
|
sqrt(base, metadata) {
|
|
28457
28834
|
return canonicalPower(this, base, this.Half, metadata);
|
|
28458
28835
|
}
|
|
28836
|
+
/** Shortcut for `this.fn("Power"...)`
|
|
28837
|
+
*
|
|
28838
|
+
* The result is canonical.
|
|
28839
|
+
*/
|
|
28459
28840
|
pow(base, exponent, metadata) {
|
|
28460
28841
|
if (base.symbol === "ExponentialE" && exponent instanceof import_complex20.Complex) {
|
|
28461
28842
|
const im = exponent.im;
|
|
@@ -28506,6 +28887,10 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28506
28887
|
exponent = this.number(exponent);
|
|
28507
28888
|
return canonicalPower(this, base, exponent, metadata);
|
|
28508
28889
|
}
|
|
28890
|
+
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
28891
|
+
*
|
|
28892
|
+
* The result is canonical.
|
|
28893
|
+
*/
|
|
28509
28894
|
inv(expr, metadata) {
|
|
28510
28895
|
if (expr.isOne)
|
|
28511
28896
|
return this.One;
|
|
@@ -28538,21 +28923,33 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28538
28923
|
return this._fn("Divide", [this.One, expr], metadata);
|
|
28539
28924
|
return this._fn("Power", [expr, e], metadata);
|
|
28540
28925
|
}
|
|
28926
|
+
/** Shortcut for `this.fn("Pair"...)`
|
|
28927
|
+
*
|
|
28928
|
+
* The result is canonical.
|
|
28929
|
+
*/
|
|
28541
28930
|
pair(first, second, metadata) {
|
|
28542
28931
|
return new BoxedFunction(this, "Tuple", [first, second], {
|
|
28543
28932
|
metadata,
|
|
28544
28933
|
canonical: true
|
|
28545
28934
|
});
|
|
28546
28935
|
}
|
|
28936
|
+
/** Shortcut for `this.fn("Tuple"...)`
|
|
28937
|
+
*
|
|
28938
|
+
* The result is canonical.
|
|
28939
|
+
*/
|
|
28547
28940
|
tuple(elements, metadata) {
|
|
28548
28941
|
return new BoxedFunction(this, "Tuple", canonical(elements), {
|
|
28549
28942
|
metadata,
|
|
28550
28943
|
canonical: true
|
|
28551
28944
|
});
|
|
28552
28945
|
}
|
|
28946
|
+
array(elements, metadata) {
|
|
28947
|
+
return this.Nothing;
|
|
28948
|
+
}
|
|
28553
28949
|
string(s, metadata) {
|
|
28554
28950
|
return new BoxedString(this, s, metadata);
|
|
28555
28951
|
}
|
|
28952
|
+
/** Return a boxed symbol */
|
|
28556
28953
|
symbol(name, options) {
|
|
28557
28954
|
options = options ? { ...options } : {};
|
|
28558
28955
|
if (!("canonical" in options))
|
|
@@ -28590,6 +28987,11 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28590
28987
|
return makeCanonicalSymbol(this, name);
|
|
28591
28988
|
return new BoxedSymbol(this, name, options);
|
|
28592
28989
|
}
|
|
28990
|
+
/** Return a canonical boxed domain.
|
|
28991
|
+
*
|
|
28992
|
+
* If the domain is invalid, may return an `["Error"]` expression
|
|
28993
|
+
*
|
|
28994
|
+
*/
|
|
28593
28995
|
domain(domain, metadata) {
|
|
28594
28996
|
if (domain instanceof _BoxedDomain)
|
|
28595
28997
|
return domain;
|
|
@@ -28623,7 +29025,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28623
29025
|
throw Error("Expected a domain constructor, got " + constructor);
|
|
28624
29026
|
return new _BoxedDomain(this, domain, metadata);
|
|
28625
29027
|
}
|
|
28626
|
-
|
|
29028
|
+
/**
|
|
28627
29029
|
* This function tries to avoid creating a boxed number if `num` corresponds
|
|
28628
29030
|
* to a common value for which we have a shared instance (-1, 0, NaN, etc...)
|
|
28629
29031
|
*/
|
|
@@ -28675,6 +29077,9 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28675
29077
|
const result = this.latexSyntax.parse(latexString(latex) ?? latex);
|
|
28676
29078
|
return this.box(result, options);
|
|
28677
29079
|
}
|
|
29080
|
+
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
29081
|
+
* a LaTeX string
|
|
29082
|
+
*/
|
|
28678
29083
|
serialize(x, options) {
|
|
28679
29084
|
if (typeof x === "object" && "json" in x) {
|
|
28680
29085
|
const ce = "engine" in x ? x.engine : this;
|
|
@@ -28685,6 +29090,16 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28685
29090
|
}
|
|
28686
29091
|
return this.latexSyntax.serialize(x, options);
|
|
28687
29092
|
}
|
|
29093
|
+
/**
|
|
29094
|
+
* Options to control the serialization of MathJSON expression to LaTeX
|
|
29095
|
+
* when using `this.latex` or `this.engine.serialize()`.
|
|
29096
|
+
*
|
|
29097
|
+
*
|
|
29098
|
+
* {@inheritDoc NumberFormattingOptions}
|
|
29099
|
+
* {@inheritDoc ParseLatexOptions}
|
|
29100
|
+
* {@inheritDoc SerializeLatexOptions}
|
|
29101
|
+
*
|
|
29102
|
+
*/
|
|
28688
29103
|
get latexOptions() {
|
|
28689
29104
|
const latexSyntax = this.latexSyntax;
|
|
28690
29105
|
return new Proxy(
|
|
@@ -28705,6 +29120,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28705
29120
|
set latexOptions(opts) {
|
|
28706
29121
|
this.latexSyntax.updateOptions(opts);
|
|
28707
29122
|
}
|
|
29123
|
+
/** {@inheritDoc JsonSerializationOptions} */
|
|
28708
29124
|
get jsonSerializationOptions() {
|
|
28709
29125
|
if (this._useRawJsonSerializationOptions) {
|
|
28710
29126
|
return new Proxy(this._rawJsonSerializationOptions, {
|
|
@@ -28793,6 +29209,21 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28793
29209
|
verify(_query) {
|
|
28794
29210
|
return false;
|
|
28795
29211
|
}
|
|
29212
|
+
/**
|
|
29213
|
+
* Add an assumption.
|
|
29214
|
+
*
|
|
29215
|
+
* Note that the assumption is put into canonical form before being added.
|
|
29216
|
+
*
|
|
29217
|
+
* @param symbol - The symbol to make an assumption about
|
|
29218
|
+
*
|
|
29219
|
+
* Returns:
|
|
29220
|
+
* - `contradiction` if the new assumption is incompatible with previous
|
|
29221
|
+
* ones.
|
|
29222
|
+
* - `tautology` if the new assumption is redundant with previous ones.
|
|
29223
|
+
* - `ok` if the assumption was successfully added to the assumption set.
|
|
29224
|
+
*
|
|
29225
|
+
*
|
|
29226
|
+
*/
|
|
28796
29227
|
assume(predicate) {
|
|
28797
29228
|
try {
|
|
28798
29229
|
return assume(this.box(predicate, { canonical: false }));
|
|
@@ -28801,6 +29232,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28801
29232
|
return "internal-error";
|
|
28802
29233
|
}
|
|
28803
29234
|
}
|
|
29235
|
+
/** Remove all assumptions about one or more symbols */
|
|
28804
29236
|
forget(symbol2) {
|
|
28805
29237
|
if (!this.context)
|
|
28806
29238
|
throw Error("No scope available");
|
|
@@ -28848,10 +29280,10 @@ function isFunctionValue(value) {
|
|
|
28848
29280
|
}
|
|
28849
29281
|
|
|
28850
29282
|
// src/compute-engine.ts
|
|
28851
|
-
var version = "0.
|
|
29283
|
+
var version = "0.21.0";
|
|
28852
29284
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
28853
29285
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
28854
|
-
version: "0.
|
|
29286
|
+
version: "0.21.0"
|
|
28855
29287
|
};
|
|
28856
29288
|
export {
|
|
28857
29289
|
ADDITION_PRECEDENCE,
|