@cortex-js/compute-engine 0.20.1 → 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 +679 -220
- package/dist/compute-engine.js +679 -220
- 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)
|
|
16072
16231
|
return void 0;
|
|
16232
|
+
if (mode === "simplify" && upper - lower >= MAX_SYMBOLIC_TERMS)
|
|
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 = [];
|
|
@@ -17784,7 +17947,7 @@ var SIMPLIFY_RULES = [];
|
|
|
17784
17947
|
// src/compute-engine/function-utils.ts
|
|
17785
17948
|
function canonicalFunctionExpression(expr) {
|
|
17786
17949
|
if (expr.head === "N" && typeof expr.op1.head === "string") {
|
|
17787
|
-
const newHead = {
|
|
17950
|
+
const newHead = { Integrate: "NIntegrate", Limit: "NLimit" }[expr.op1.head];
|
|
17788
17951
|
if (newHead)
|
|
17789
17952
|
expr = expr.engine._fn(newHead, expr.op1.ops);
|
|
17790
17953
|
}
|
|
@@ -18255,6 +18418,11 @@ var BoxedFunction = class _BoxedFunction extends _BoxedExpression {
|
|
|
18255
18418
|
evaluate(options) {
|
|
18256
18419
|
if (!this.isValid)
|
|
18257
18420
|
return this;
|
|
18421
|
+
if (options?.numericMode) {
|
|
18422
|
+
const h = this.head;
|
|
18423
|
+
if (h === "Integrate" || h === "Limit")
|
|
18424
|
+
return this.engine.box(["N", this], { canonical: true }).evaluate(options);
|
|
18425
|
+
}
|
|
18258
18426
|
if (!this.isCanonical) {
|
|
18259
18427
|
this.engine.pushScope();
|
|
18260
18428
|
const canonical2 = this.canonical;
|
|
@@ -18494,7 +18662,7 @@ function cheapest(oldExpr, newExpr) {
|
|
|
18494
18662
|
}
|
|
18495
18663
|
|
|
18496
18664
|
// src/compute-engine/boxed-expression/boxed-number.ts
|
|
18497
|
-
var import_complex13 = __toESM(require_complex());
|
|
18665
|
+
var import_complex13 = __toESM(require_complex(), 1);
|
|
18498
18666
|
|
|
18499
18667
|
// src/compute-engine/numerics/primes.ts
|
|
18500
18668
|
var LARGE_PRIME = 1125899906842597;
|
|
@@ -19382,7 +19550,7 @@ function asString(expr) {
|
|
|
19382
19550
|
}
|
|
19383
19551
|
|
|
19384
19552
|
// src/compute-engine/library/arithmetic.ts
|
|
19385
|
-
var import_complex16 = __toESM(require_complex());
|
|
19553
|
+
var import_complex16 = __toESM(require_complex(), 1);
|
|
19386
19554
|
|
|
19387
19555
|
// src/compute-engine/numerics/numeric-complex.ts
|
|
19388
19556
|
function gamma3(c) {
|
|
@@ -19393,7 +19561,7 @@ function gammaln3(c) {
|
|
|
19393
19561
|
}
|
|
19394
19562
|
|
|
19395
19563
|
// src/compute-engine/library/arithmetic-power.ts
|
|
19396
|
-
var import_complex15 = __toESM(require_complex());
|
|
19564
|
+
var import_complex15 = __toESM(require_complex(), 1);
|
|
19397
19565
|
function canonicalPower(ce, base, exponent, metadata) {
|
|
19398
19566
|
if (exponent.symbol === "ComplexInfinity")
|
|
19399
19567
|
return ce.NaN;
|
|
@@ -21085,71 +21253,6 @@ var ARITHMETIC_LIBRARY = [
|
|
|
21085
21253
|
evaluate: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "evaluate"),
|
|
21086
21254
|
N: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "N")
|
|
21087
21255
|
}
|
|
21088
|
-
},
|
|
21089
|
-
// Limits
|
|
21090
|
-
Limit: {
|
|
21091
|
-
description: "Limit of a function",
|
|
21092
|
-
complexity: 5e3,
|
|
21093
|
-
hold: "all",
|
|
21094
|
-
threadable: false,
|
|
21095
|
-
signature: {
|
|
21096
|
-
domain: [
|
|
21097
|
-
"FunctionOf",
|
|
21098
|
-
"Anything",
|
|
21099
|
-
"Numbers",
|
|
21100
|
-
["OptArg", "Numbers"],
|
|
21101
|
-
"Numbers"
|
|
21102
|
-
],
|
|
21103
|
-
N: (ce, ops2) => {
|
|
21104
|
-
const [f, x, dir] = ops2;
|
|
21105
|
-
const target = asFloat(x.N());
|
|
21106
|
-
if (target === null)
|
|
21107
|
-
return void 0;
|
|
21108
|
-
const fn = applicable(f);
|
|
21109
|
-
return ce.number(
|
|
21110
|
-
limit(
|
|
21111
|
-
(x2) => {
|
|
21112
|
-
const y = fn([ce.number(x2)])?.value;
|
|
21113
|
-
return typeof y === "number" ? y : Number.NaN;
|
|
21114
|
-
},
|
|
21115
|
-
target,
|
|
21116
|
-
dir ? asFloat(dir) ?? 1 : 1
|
|
21117
|
-
)
|
|
21118
|
-
);
|
|
21119
|
-
}
|
|
21120
|
-
}
|
|
21121
|
-
},
|
|
21122
|
-
NLimit: {
|
|
21123
|
-
description: "Numerical approximation of the limit of a function",
|
|
21124
|
-
complexity: 5e3,
|
|
21125
|
-
hold: "all",
|
|
21126
|
-
threadable: false,
|
|
21127
|
-
signature: {
|
|
21128
|
-
domain: [
|
|
21129
|
-
"FunctionOf",
|
|
21130
|
-
"Anything",
|
|
21131
|
-
"Numbers",
|
|
21132
|
-
["OptArg", "Numbers"],
|
|
21133
|
-
"Numbers"
|
|
21134
|
-
],
|
|
21135
|
-
evaluate: (ce, ops2) => {
|
|
21136
|
-
const [f, x, dir] = ops2;
|
|
21137
|
-
const target = asFloat(x.N());
|
|
21138
|
-
if (target === null)
|
|
21139
|
-
return void 0;
|
|
21140
|
-
const fn = applicable(f);
|
|
21141
|
-
return ce.number(
|
|
21142
|
-
limit(
|
|
21143
|
-
(x2) => {
|
|
21144
|
-
const y = fn([ce.number(x2)])?.value;
|
|
21145
|
-
return typeof y === "number" ? y : Number.NaN;
|
|
21146
|
-
},
|
|
21147
|
-
target,
|
|
21148
|
-
dir ? asFloat(dir) ?? 1 : 1
|
|
21149
|
-
)
|
|
21150
|
-
);
|
|
21151
|
-
}
|
|
21152
|
-
}
|
|
21153
21256
|
}
|
|
21154
21257
|
},
|
|
21155
21258
|
//
|
|
@@ -21820,6 +21923,73 @@ var CALCULUS_LIBRARY = [
|
|
|
21820
21923
|
}
|
|
21821
21924
|
}
|
|
21822
21925
|
}
|
|
21926
|
+
},
|
|
21927
|
+
{
|
|
21928
|
+
// Limits
|
|
21929
|
+
Limit: {
|
|
21930
|
+
description: "Limit of a function",
|
|
21931
|
+
complexity: 5e3,
|
|
21932
|
+
hold: "all",
|
|
21933
|
+
threadable: false,
|
|
21934
|
+
signature: {
|
|
21935
|
+
domain: [
|
|
21936
|
+
"FunctionOf",
|
|
21937
|
+
"Anything",
|
|
21938
|
+
"Numbers",
|
|
21939
|
+
["OptArg", "Numbers"],
|
|
21940
|
+
"Numbers"
|
|
21941
|
+
],
|
|
21942
|
+
N: (ce, ops2) => {
|
|
21943
|
+
const [f, x, dir] = ops2;
|
|
21944
|
+
const target = asFloat(x.N());
|
|
21945
|
+
if (target === null)
|
|
21946
|
+
return void 0;
|
|
21947
|
+
const fn = applicable(f);
|
|
21948
|
+
return ce.number(
|
|
21949
|
+
limit(
|
|
21950
|
+
(x2) => {
|
|
21951
|
+
const y = fn([ce.number(x2)])?.value;
|
|
21952
|
+
return typeof y === "number" ? y : Number.NaN;
|
|
21953
|
+
},
|
|
21954
|
+
target,
|
|
21955
|
+
dir ? asFloat(dir) ?? 1 : 1
|
|
21956
|
+
)
|
|
21957
|
+
);
|
|
21958
|
+
}
|
|
21959
|
+
}
|
|
21960
|
+
},
|
|
21961
|
+
NLimit: {
|
|
21962
|
+
description: "Numerical approximation of the limit of a function",
|
|
21963
|
+
complexity: 5e3,
|
|
21964
|
+
hold: "all",
|
|
21965
|
+
threadable: false,
|
|
21966
|
+
signature: {
|
|
21967
|
+
domain: [
|
|
21968
|
+
"FunctionOf",
|
|
21969
|
+
"Anything",
|
|
21970
|
+
"Numbers",
|
|
21971
|
+
["OptArg", "Numbers"],
|
|
21972
|
+
"Numbers"
|
|
21973
|
+
],
|
|
21974
|
+
evaluate: (ce, ops2) => {
|
|
21975
|
+
const [f, x, dir] = ops2;
|
|
21976
|
+
const target = asFloat(x.N());
|
|
21977
|
+
if (target === null)
|
|
21978
|
+
return void 0;
|
|
21979
|
+
const fn = applicable(f);
|
|
21980
|
+
return ce.number(
|
|
21981
|
+
limit(
|
|
21982
|
+
(x2) => {
|
|
21983
|
+
const y = fn([ce.number(x2)])?.value;
|
|
21984
|
+
return typeof y === "number" ? y : Number.NaN;
|
|
21985
|
+
},
|
|
21986
|
+
target,
|
|
21987
|
+
dir ? asFloat(dir) ?? 1 : 1
|
|
21988
|
+
)
|
|
21989
|
+
);
|
|
21990
|
+
}
|
|
21991
|
+
}
|
|
21992
|
+
}
|
|
21823
21993
|
}
|
|
21824
21994
|
];
|
|
21825
21995
|
|
|
@@ -22576,6 +22746,15 @@ function indexes(ranges) {
|
|
|
22576
22746
|
return result;
|
|
22577
22747
|
}
|
|
22578
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
|
+
}
|
|
22579
22758
|
ops2 = ops2.map((op3) => {
|
|
22580
22759
|
if (op3.head === "Delimiter") {
|
|
22581
22760
|
if (op3.op1.head === "Sequence")
|
|
@@ -23419,12 +23598,44 @@ var CORE_LIBRARY = [
|
|
|
23419
23598
|
evaluate: (_ce, ops2) => ops2[0].simplify()
|
|
23420
23599
|
}
|
|
23421
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
|
+
},
|
|
23422
23613
|
N: {
|
|
23423
23614
|
hold: "all",
|
|
23424
23615
|
signature: {
|
|
23425
23616
|
domain: ["FunctionOf", "Anything", "Anything"],
|
|
23426
23617
|
result: (_ce, ops2) => ops2[0].domain,
|
|
23427
|
-
canonical: (ce, ops2) =>
|
|
23618
|
+
canonical: (ce, ops2) => {
|
|
23619
|
+
if (ops2.length !== 1)
|
|
23620
|
+
return ce._fn("N", checkArity(ce, ops2, 1));
|
|
23621
|
+
const h = ops2[0].head;
|
|
23622
|
+
if (h === "N")
|
|
23623
|
+
return ops2[0].canonical;
|
|
23624
|
+
if (h === "Integrate") {
|
|
23625
|
+
const [index, lower, upper] = normalizeLimits(ops2[0].op2);
|
|
23626
|
+
if (!index || lower === void 0 || upper === void 0)
|
|
23627
|
+
return null;
|
|
23628
|
+
const fn = ops2[0].op1;
|
|
23629
|
+
return ce._fn("NIntegrate", [
|
|
23630
|
+
ce.box(["Function", fn, index]),
|
|
23631
|
+
ce.number(lower),
|
|
23632
|
+
ce.number(upper)
|
|
23633
|
+
]);
|
|
23634
|
+
}
|
|
23635
|
+
if (h === "Limit")
|
|
23636
|
+
return ce._fn("NLimit", ops2[0].ops);
|
|
23637
|
+
return ce._fn("N", ops2);
|
|
23638
|
+
},
|
|
23428
23639
|
evaluate: (_ce, ops2) => ops2[0].N()
|
|
23429
23640
|
}
|
|
23430
23641
|
},
|
|
@@ -23682,22 +23893,40 @@ var LINEAR_ALGEBRA_LIBRARY = [
|
|
|
23682
23893
|
evaluate: (_ce, ops2) => ops2[0].evaluate(),
|
|
23683
23894
|
N: (_ce, ops2) => ops2[0].N()
|
|
23684
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
|
+
}
|
|
23685
23914
|
}
|
|
23686
23915
|
}
|
|
23687
23916
|
];
|
|
23688
|
-
function canonicalMatrix(ce, ops2) {
|
|
23917
|
+
function canonicalMatrix(ce, ops2, head2 = "Matrix") {
|
|
23689
23918
|
if (ops2.length === 0)
|
|
23690
|
-
return ce._fn(
|
|
23691
|
-
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;
|
|
23692
23921
|
const delims = ops2[1]?.canonical;
|
|
23693
23922
|
const columns = ops2[2]?.canonical;
|
|
23694
23923
|
if (ops2.length > 3)
|
|
23695
|
-
return ce._fn(
|
|
23924
|
+
return ce._fn(head2, checkArity(ce, ops2, 3));
|
|
23696
23925
|
if (columns)
|
|
23697
|
-
return ce._fn(
|
|
23926
|
+
return ce._fn(head2, [body, delims, columns]);
|
|
23698
23927
|
if (delims)
|
|
23699
|
-
return ce._fn(
|
|
23700
|
-
return ce._fn(
|
|
23928
|
+
return ce._fn(head2, [body, delims]);
|
|
23929
|
+
return ce._fn(head2, [body]);
|
|
23701
23930
|
}
|
|
23702
23931
|
|
|
23703
23932
|
// src/compute-engine/library/logic.ts
|
|
@@ -23935,6 +24164,28 @@ var RELOP_LIBRARY = {
|
|
|
23935
24164
|
}
|
|
23936
24165
|
}
|
|
23937
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
|
+
},
|
|
23938
24189
|
Equal: {
|
|
23939
24190
|
commutative: true,
|
|
23940
24191
|
complexity: 11e3,
|
|
@@ -25622,7 +25873,7 @@ function evalTrig(ce, mode, head2, op3) {
|
|
|
25622
25873
|
}
|
|
25623
25874
|
|
|
25624
25875
|
// src/compute-engine/boxed-expression/boxed-symbol-definition.ts
|
|
25625
|
-
var import_complex17 = __toESM(require_complex());
|
|
25876
|
+
var import_complex17 = __toESM(require_complex(), 1);
|
|
25626
25877
|
var _BoxedSymbolDefinition = class {
|
|
25627
25878
|
// @todo
|
|
25628
25879
|
constructor(ce, name, def) {
|
|
@@ -26614,7 +26865,7 @@ function isFunctionDefinition(def) {
|
|
|
26614
26865
|
}
|
|
26615
26866
|
|
|
26616
26867
|
// src/compute-engine/cost-function.ts
|
|
26617
|
-
var import_complex19 = __toESM(require_complex());
|
|
26868
|
+
var import_complex19 = __toESM(require_complex(), 1);
|
|
26618
26869
|
function numericCostFunction(n) {
|
|
26619
26870
|
if (Number.isInteger(n) && n !== 0) {
|
|
26620
26871
|
return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
|
|
@@ -27196,6 +27447,7 @@ var BoxedSymbol = class _BoxedSymbol extends _BoxedExpression {
|
|
|
27196
27447
|
});
|
|
27197
27448
|
}
|
|
27198
27449
|
}
|
|
27450
|
+
// @ts-ignore
|
|
27199
27451
|
get domain() {
|
|
27200
27452
|
const def = this._def;
|
|
27201
27453
|
if (def) {
|
|
@@ -27584,7 +27836,6 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27584
27836
|
symbols: /* @__PURE__ */ new Set(),
|
|
27585
27837
|
expressions: /* @__PURE__ */ new Set()
|
|
27586
27838
|
};
|
|
27587
|
-
this._defaultDomain = null;
|
|
27588
27839
|
this._numericMode = options?.numericMode ?? "auto";
|
|
27589
27840
|
this._precision = Math.max(
|
|
27590
27841
|
options?.numericPrecision ?? 100,
|
|
@@ -27828,6 +28079,56 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27828
28079
|
return 0;
|
|
27829
28080
|
return n;
|
|
27830
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
|
+
*/
|
|
27831
28132
|
bignum(a) {
|
|
27832
28133
|
if (typeof a === "bigint")
|
|
27833
28134
|
return new this._bignum(a.toString());
|
|
@@ -27838,6 +28139,51 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27838
28139
|
}
|
|
27839
28140
|
return this._BIGNUM_NAN;
|
|
27840
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
|
+
*/
|
|
27841
28187
|
complex(a, b) {
|
|
27842
28188
|
if (a instanceof Decimal)
|
|
27843
28189
|
a = a.toNumber();
|
|
@@ -27941,7 +28287,14 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27941
28287
|
return void 0;
|
|
27942
28288
|
}
|
|
27943
28289
|
/**
|
|
27944
|
-
*
|
|
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
|
|
27945
28298
|
*/
|
|
27946
28299
|
defineSymbol(name, def) {
|
|
27947
28300
|
if (!this.context)
|
|
@@ -27958,6 +28311,15 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
27958
28311
|
this.context.ids.set(boxedDef.name, boxedDef);
|
|
27959
28312
|
return boxedDef;
|
|
27960
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
|
+
*/
|
|
27961
28323
|
defineFunction(name, def) {
|
|
27962
28324
|
if (!this.context)
|
|
27963
28325
|
throw Error("Function cannot be defined: no scope available");
|
|
@@ -28002,8 +28364,8 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28002
28364
|
};
|
|
28003
28365
|
return this;
|
|
28004
28366
|
}
|
|
28005
|
-
/** Remove the
|
|
28006
|
-
*/
|
|
28367
|
+
/** Remove the most recent scope from the scope stack, and set its
|
|
28368
|
+
* parent scope as current. */
|
|
28007
28369
|
popScope() {
|
|
28008
28370
|
if (!this.context)
|
|
28009
28371
|
throw Error("No scope available");
|
|
@@ -28011,12 +28373,17 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28011
28373
|
console.assert(this.context);
|
|
28012
28374
|
return this;
|
|
28013
28375
|
}
|
|
28376
|
+
/** Set the current scope, return the previous scope. */
|
|
28014
28377
|
swapScope(scope) {
|
|
28015
28378
|
const oldScope = this.context;
|
|
28016
28379
|
this.context = scope;
|
|
28017
28380
|
console.assert(this.context);
|
|
28018
28381
|
return oldScope;
|
|
28019
28382
|
}
|
|
28383
|
+
/**
|
|
28384
|
+
* Reset the value of any identifiers that have been assigned a value
|
|
28385
|
+
* in the current scope.
|
|
28386
|
+
* @internal */
|
|
28020
28387
|
resetContext() {
|
|
28021
28388
|
if (!this.context)
|
|
28022
28389
|
return;
|
|
@@ -28036,6 +28403,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28036
28403
|
}
|
|
28037
28404
|
}
|
|
28038
28405
|
}
|
|
28406
|
+
/** @internal */
|
|
28039
28407
|
_printScope(options, scope, depth = 0) {
|
|
28040
28408
|
options ?? (options = { details: false, maxDepth: 1 });
|
|
28041
28409
|
scope ?? (scope = this.context);
|
|
@@ -28346,6 +28714,9 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28346
28714
|
}
|
|
28347
28715
|
return this._cache[cacheName]?.value;
|
|
28348
28716
|
}
|
|
28717
|
+
/**
|
|
28718
|
+
* Return a boxed expression from the input.
|
|
28719
|
+
*/
|
|
28349
28720
|
box(expr, options) {
|
|
28350
28721
|
return box(this, expr, options);
|
|
28351
28722
|
}
|
|
@@ -28355,6 +28726,16 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28355
28726
|
const bxs = xs;
|
|
28356
28727
|
return bxs.every((x) => x.isCanonical) ? bxs : bxs.map((x) => x.canonical);
|
|
28357
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
|
+
*/
|
|
28358
28739
|
fn(head2, ops2, options) {
|
|
28359
28740
|
return boxFunction(this, head2, ops2, options ?? { canonical: true });
|
|
28360
28741
|
}
|
|
@@ -28399,18 +28780,33 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28399
28780
|
const actual = actualDomain ? actualDomain : this.symbol("Undefined");
|
|
28400
28781
|
return this.error(["incompatible-domain", expected, actual], where);
|
|
28401
28782
|
}
|
|
28783
|
+
/**
|
|
28784
|
+
* Add a`["Hold"]` wrapper to `expr.
|
|
28785
|
+
*/
|
|
28402
28786
|
hold(expr) {
|
|
28403
28787
|
return this._fn("Hold", [this.box(expr, { canonical: false })]);
|
|
28404
28788
|
}
|
|
28789
|
+
/** Shortcut for `this.fn("Add"...)`.
|
|
28790
|
+
*
|
|
28791
|
+
* The result is canonical.
|
|
28792
|
+
*/
|
|
28405
28793
|
add(ops2, metadata) {
|
|
28406
28794
|
const result = canonicalAdd(this, flattenOps(flattenSequence(ops2), "Add"));
|
|
28407
28795
|
if (metadata?.latex !== void 0)
|
|
28408
28796
|
result.latex = metadata.latex;
|
|
28409
28797
|
return result;
|
|
28410
28798
|
}
|
|
28799
|
+
/** Shortcut for `this.fn("Negate", [expr])`
|
|
28800
|
+
*
|
|
28801
|
+
* The result is canonical.
|
|
28802
|
+
*/
|
|
28411
28803
|
neg(expr, metadata) {
|
|
28412
28804
|
return canonicalNegate(expr, metadata);
|
|
28413
28805
|
}
|
|
28806
|
+
/** Shortcut for `this.fn("Multiply"...)`
|
|
28807
|
+
*
|
|
28808
|
+
* The result is canonical.
|
|
28809
|
+
*/
|
|
28414
28810
|
mul(ops2, metadata) {
|
|
28415
28811
|
const result = canonicalMultiply(
|
|
28416
28812
|
this,
|
|
@@ -28420,15 +28816,27 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28420
28816
|
result.latex = metadata.latex;
|
|
28421
28817
|
return result;
|
|
28422
28818
|
}
|
|
28819
|
+
/** Shortcut for `this.fn("Divide", [num, denom])`
|
|
28820
|
+
*
|
|
28821
|
+
* The result is canonical.
|
|
28822
|
+
*/
|
|
28423
28823
|
div(num, denom, metadata) {
|
|
28424
28824
|
const result = canonicalDivide(this, num, denom);
|
|
28425
28825
|
if (metadata?.latex !== void 0)
|
|
28426
28826
|
result.latex = metadata.latex;
|
|
28427
28827
|
return result;
|
|
28428
28828
|
}
|
|
28829
|
+
/** Shortcut for `this.fn("Sqrt"...)`
|
|
28830
|
+
*
|
|
28831
|
+
* The result is canonical.
|
|
28832
|
+
*/
|
|
28429
28833
|
sqrt(base, metadata) {
|
|
28430
28834
|
return canonicalPower(this, base, this.Half, metadata);
|
|
28431
28835
|
}
|
|
28836
|
+
/** Shortcut for `this.fn("Power"...)`
|
|
28837
|
+
*
|
|
28838
|
+
* The result is canonical.
|
|
28839
|
+
*/
|
|
28432
28840
|
pow(base, exponent, metadata) {
|
|
28433
28841
|
if (base.symbol === "ExponentialE" && exponent instanceof import_complex20.Complex) {
|
|
28434
28842
|
const im = exponent.im;
|
|
@@ -28479,6 +28887,10 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28479
28887
|
exponent = this.number(exponent);
|
|
28480
28888
|
return canonicalPower(this, base, exponent, metadata);
|
|
28481
28889
|
}
|
|
28890
|
+
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
28891
|
+
*
|
|
28892
|
+
* The result is canonical.
|
|
28893
|
+
*/
|
|
28482
28894
|
inv(expr, metadata) {
|
|
28483
28895
|
if (expr.isOne)
|
|
28484
28896
|
return this.One;
|
|
@@ -28511,21 +28923,33 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28511
28923
|
return this._fn("Divide", [this.One, expr], metadata);
|
|
28512
28924
|
return this._fn("Power", [expr, e], metadata);
|
|
28513
28925
|
}
|
|
28926
|
+
/** Shortcut for `this.fn("Pair"...)`
|
|
28927
|
+
*
|
|
28928
|
+
* The result is canonical.
|
|
28929
|
+
*/
|
|
28514
28930
|
pair(first, second, metadata) {
|
|
28515
28931
|
return new BoxedFunction(this, "Tuple", [first, second], {
|
|
28516
28932
|
metadata,
|
|
28517
28933
|
canonical: true
|
|
28518
28934
|
});
|
|
28519
28935
|
}
|
|
28936
|
+
/** Shortcut for `this.fn("Tuple"...)`
|
|
28937
|
+
*
|
|
28938
|
+
* The result is canonical.
|
|
28939
|
+
*/
|
|
28520
28940
|
tuple(elements, metadata) {
|
|
28521
28941
|
return new BoxedFunction(this, "Tuple", canonical(elements), {
|
|
28522
28942
|
metadata,
|
|
28523
28943
|
canonical: true
|
|
28524
28944
|
});
|
|
28525
28945
|
}
|
|
28946
|
+
array(elements, metadata) {
|
|
28947
|
+
return this.Nothing;
|
|
28948
|
+
}
|
|
28526
28949
|
string(s, metadata) {
|
|
28527
28950
|
return new BoxedString(this, s, metadata);
|
|
28528
28951
|
}
|
|
28952
|
+
/** Return a boxed symbol */
|
|
28529
28953
|
symbol(name, options) {
|
|
28530
28954
|
options = options ? { ...options } : {};
|
|
28531
28955
|
if (!("canonical" in options))
|
|
@@ -28563,6 +28987,11 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28563
28987
|
return makeCanonicalSymbol(this, name);
|
|
28564
28988
|
return new BoxedSymbol(this, name, options);
|
|
28565
28989
|
}
|
|
28990
|
+
/** Return a canonical boxed domain.
|
|
28991
|
+
*
|
|
28992
|
+
* If the domain is invalid, may return an `["Error"]` expression
|
|
28993
|
+
*
|
|
28994
|
+
*/
|
|
28566
28995
|
domain(domain, metadata) {
|
|
28567
28996
|
if (domain instanceof _BoxedDomain)
|
|
28568
28997
|
return domain;
|
|
@@ -28596,7 +29025,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28596
29025
|
throw Error("Expected a domain constructor, got " + constructor);
|
|
28597
29026
|
return new _BoxedDomain(this, domain, metadata);
|
|
28598
29027
|
}
|
|
28599
|
-
|
|
29028
|
+
/**
|
|
28600
29029
|
* This function tries to avoid creating a boxed number if `num` corresponds
|
|
28601
29030
|
* to a common value for which we have a shared instance (-1, 0, NaN, etc...)
|
|
28602
29031
|
*/
|
|
@@ -28648,6 +29077,9 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28648
29077
|
const result = this.latexSyntax.parse(latexString(latex) ?? latex);
|
|
28649
29078
|
return this.box(result, options);
|
|
28650
29079
|
}
|
|
29080
|
+
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
29081
|
+
* a LaTeX string
|
|
29082
|
+
*/
|
|
28651
29083
|
serialize(x, options) {
|
|
28652
29084
|
if (typeof x === "object" && "json" in x) {
|
|
28653
29085
|
const ce = "engine" in x ? x.engine : this;
|
|
@@ -28658,6 +29090,16 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28658
29090
|
}
|
|
28659
29091
|
return this.latexSyntax.serialize(x, options);
|
|
28660
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
|
+
*/
|
|
28661
29103
|
get latexOptions() {
|
|
28662
29104
|
const latexSyntax = this.latexSyntax;
|
|
28663
29105
|
return new Proxy(
|
|
@@ -28678,6 +29120,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28678
29120
|
set latexOptions(opts) {
|
|
28679
29121
|
this.latexSyntax.updateOptions(opts);
|
|
28680
29122
|
}
|
|
29123
|
+
/** {@inheritDoc JsonSerializationOptions} */
|
|
28681
29124
|
get jsonSerializationOptions() {
|
|
28682
29125
|
if (this._useRawJsonSerializationOptions) {
|
|
28683
29126
|
return new Proxy(this._rawJsonSerializationOptions, {
|
|
@@ -28766,6 +29209,21 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28766
29209
|
verify(_query) {
|
|
28767
29210
|
return false;
|
|
28768
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
|
+
*/
|
|
28769
29227
|
assume(predicate) {
|
|
28770
29228
|
try {
|
|
28771
29229
|
return assume(this.box(predicate, { canonical: false }));
|
|
@@ -28774,6 +29232,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
28774
29232
|
return "internal-error";
|
|
28775
29233
|
}
|
|
28776
29234
|
}
|
|
29235
|
+
/** Remove all assumptions about one or more symbols */
|
|
28777
29236
|
forget(symbol2) {
|
|
28778
29237
|
if (!this.context)
|
|
28779
29238
|
throw Error("No scope available");
|
|
@@ -28821,10 +29280,10 @@ function isFunctionValue(value) {
|
|
|
28821
29280
|
}
|
|
28822
29281
|
|
|
28823
29282
|
// src/compute-engine.ts
|
|
28824
|
-
var version = "0.
|
|
29283
|
+
var version = "0.21.0";
|
|
28825
29284
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
28826
29285
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
28827
|
-
version: "0.
|
|
29286
|
+
version: "0.21.0"
|
|
28828
29287
|
};
|
|
28829
29288
|
export {
|
|
28830
29289
|
ADDITION_PRECEDENCE,
|