@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.
Files changed (102) hide show
  1. package/dist/compute-engine.esm.js +585 -153
  2. package/dist/compute-engine.js +585 -153
  3. package/dist/compute-engine.min.esm.js +10 -10
  4. package/dist/compute-engine.min.js +10 -10
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/order.d.ts +8 -2
  27. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  30. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  31. package/dist/types/compute-engine/compile.d.ts +1 -1
  32. package/dist/types/compute-engine/compute-engine.d.ts +265 -29
  33. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  34. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  35. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +2 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
  53. package/dist/types/compute-engine/latex-syntax/public.d.ts +5 -2
  54. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  57. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  62. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  63. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  64. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  65. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  66. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  67. package/dist/types/compute-engine/library/core.d.ts +1 -1
  68. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  69. package/dist/types/compute-engine/library/library.d.ts +1 -1
  70. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  71. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  72. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  73. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  74. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  75. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  76. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  77. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  78. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  79. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  80. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  81. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  82. package/dist/types/compute-engine/numerics/numeric.d.ts +3 -3
  83. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  85. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  86. package/dist/types/compute-engine/public.d.ts +8 -260
  87. package/dist/types/compute-engine/rules.d.ts +1 -1
  88. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  89. package/dist/types/compute-engine/solve.d.ts +1 -1
  90. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  92. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  96. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  97. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  98. package/dist/types/compute-engine.d.ts +2 -2
  99. package/dist/types/math-json/math-json-format.d.ts +1 -1
  100. package/dist/types/math-json/utils.d.ts +1 -1
  101. package/dist/types/math-json.d.ts +2 -2
  102. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.20.2 */
1
+ /** CortexJS Compute Engine 0.21.0 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
3
3
  var ComputeEngine = (() => {
4
4
  var __create = Object.create;
@@ -1093,7 +1093,7 @@ var ComputeEngine = (() => {
1093
1093
  }
1094
1094
 
1095
1095
  // src/compute-engine/compute-engine.ts
1096
- var import_complex20 = __toESM(require_complex());
1096
+ var import_complex20 = __toESM(require_complex(), 1);
1097
1097
 
1098
1098
  // node_modules/decimal.js/decimal.mjs
1099
1099
  var EXP_LIMIT = 9e15;
@@ -5965,23 +5965,7 @@ var ComputeEngine = (() => {
5965
5965
  kind: "environment",
5966
5966
  name: "Which",
5967
5967
  identifierTrigger: "cases",
5968
- parse: (parser) => {
5969
- const tabular = parser.parseTabular();
5970
- if (!tabular)
5971
- return ["Which"];
5972
- const result = ["Which"];
5973
- for (const row of tabular) {
5974
- if (row.length === 1) {
5975
- result.push("True");
5976
- result.push(row[0]);
5977
- } else if (row.length === 2) {
5978
- const s = stringValue(row[1]);
5979
- result.push(s ? "True" : stripText(row[1]) ?? "True");
5980
- result.push(row[0]);
5981
- }
5982
- }
5983
- return result;
5984
- },
5968
+ parse: parseWhich,
5985
5969
  serialize: (serialize, expr) => {
5986
5970
  const rows = [];
5987
5971
  const args = ops(expr);
@@ -5995,6 +5979,16 @@ var ComputeEngine = (() => {
5995
5979
  }
5996
5980
  return joinLatex(["\\begin{cases}", rows.join("\\\\"), "\\end{cases}"]);
5997
5981
  }
5982
+ },
5983
+ {
5984
+ kind: "environment",
5985
+ identifierTrigger: "dcases",
5986
+ parse: parseWhich
5987
+ },
5988
+ {
5989
+ kind: "environment",
5990
+ identifierTrigger: "rcases",
5991
+ parse: parseWhich
5998
5992
  }
5999
5993
  ];
6000
5994
  function parseTextRun(parser, style) {
@@ -6315,6 +6309,23 @@ var ComputeEngine = (() => {
6315
6309
  }
6316
6310
  return ["Assign", lhs, rhs];
6317
6311
  }
6312
+ function parseWhich(parser) {
6313
+ const tabular = parser.parseTabular();
6314
+ if (!tabular)
6315
+ return ["Which"];
6316
+ const result = ["Which"];
6317
+ for (const row of tabular) {
6318
+ if (row.length === 1) {
6319
+ result.push("True");
6320
+ result.push(row[0]);
6321
+ } else if (row.length === 2) {
6322
+ const s = stringValue(row[1]);
6323
+ result.push(s ? "True" : stripText(row[1]) ?? "True");
6324
+ result.push(row[0]);
6325
+ }
6326
+ }
6327
+ return result;
6328
+ }
6318
6329
 
6319
6330
  // src/compute-engine/latex-syntax/dictionary/definitions-inequalities.ts
6320
6331
  var DEFINITIONS_INEQUALITIES = [
@@ -6723,103 +6734,239 @@ var ComputeEngine = (() => {
6723
6734
  // The third, optional, argument is the column specification.
6724
6735
  {
6725
6736
  name: "Matrix",
6726
- // https://ctan.math.illinois.edu/macros/latex/required/tools/array.pdf
6727
6737
  serialize: (serializer, expr) => {
6728
- const body = op(expr, 1);
6729
- const delims = op(expr, 2) ?? "()";
6730
- let columns = "";
6731
- if (op(expr, 3) !== null) {
6732
- const colsSpec = stringValue(op(expr, 3)) ?? "";
6733
- for (const c of colsSpec) {
6734
- if (c === "<")
6735
- columns += "l";
6736
- else if (c === ">")
6737
- columns += "r";
6738
- else if (c === "=")
6739
- columns += "c";
6740
- else if (c === "|")
6741
- columns += "|";
6742
- else if (c === ":")
6743
- columns += ":";
6744
- }
6745
- }
6746
- let [open, close] = ["", ""];
6747
- if (typeof delims === "string" && delims.length === 2)
6748
- [open, close] = delims;
6749
- const rows = [];
6750
- for (const row of ops(body) ?? []) {
6751
- const cells = [];
6752
- for (const cell of ops(row) ?? [])
6753
- cells.push(serializer.serialize(cell));
6754
- rows.push(cells.join(" & "));
6755
- }
6756
- const tabular = rows.join("\\\\\n");
6757
- const optColumns = columns.length > 0 ? `[${columns}]` : "";
6758
- if (open === "(" && close === ")")
6759
- return joinLatex([
6760
- "\\begin{pmatrix}",
6761
- optColumns,
6762
- tabular,
6763
- "\\end{pmatrix}"
6764
- ]);
6765
- if (open === "[" && close === "]")
6766
- return joinLatex([
6767
- "\\begin{bmatrix}",
6768
- optColumns,
6769
- tabular,
6770
- "\\end{bmatrix}"
6771
- ]);
6772
- if (open === "{" && close === "}")
6773
- return joinLatex([
6774
- "\\begin{Bmatrix}",
6775
- optColumns,
6776
- tabular,
6777
- "\\end{Bmatrix}"
6778
- ]);
6779
- if (open === "|" && close === "|")
6780
- return joinLatex([
6781
- "\\begin{vmatrix}",
6782
- optColumns,
6783
- tabular,
6784
- "\\end{vmatrix}"
6785
- ]);
6786
- if (open === "\u2016" && close === "\u2016")
6787
- return joinLatex([
6788
- "\\begin{Vmatrix}",
6789
- optColumns,
6790
- tabular,
6791
- "\\end{Vmatrix}"
6792
- ]);
6793
- if (open === "{" && close === ".")
6794
- return joinLatex([
6795
- "\\begin{dcases}",
6796
- optColumns,
6797
- tabular,
6798
- "\\end{dcases}"
6799
- ]);
6800
- if (open === "." && close === "}")
6801
- return joinLatex([
6802
- "\\begin{rcases}",
6803
- optColumns,
6804
- tabular,
6805
- "\\end{rcases}"
6806
- ]);
6807
- if (columns || open !== "." || close !== ".") {
6808
- return joinLatex([
6809
- "\\left",
6810
- DELIMITERS_SHORTHAND[open] ?? open,
6811
- "\\begin{array}",
6812
- `{${columns}}`,
6813
- tabular,
6814
- "\\end{array}",
6815
- "\\right",
6816
- DELIMITERS_SHORTHAND[close] ?? close
6817
- ]);
6818
- }
6819
- return joinLatex(["\\begin{matrix}", tabular, "\\end{matrix}"]);
6738
+ const rows = ops(op(expr, 1)) ?? [];
6739
+ return serializeTabular(
6740
+ serializer,
6741
+ rows,
6742
+ stringValue(op(expr, 2)),
6743
+ stringValue(op(expr, 3))
6744
+ );
6745
+ }
6746
+ },
6747
+ // Vector is a specialized collection to represent a column vector.
6748
+ {
6749
+ name: "Vector",
6750
+ serialize: (serializer, expr) => {
6751
+ const columns = ops(expr) ?? [];
6752
+ return serializeTabular(
6753
+ serializer,
6754
+ columns.map((column) => ["List", column]),
6755
+ stringValue(op(expr, 2)),
6756
+ stringValue(op(expr, 3))
6757
+ );
6758
+ }
6759
+ },
6760
+ {
6761
+ kind: "environment",
6762
+ identifierTrigger: "pmatrix",
6763
+ parse: (parser) => {
6764
+ const columns = parseColumnFormat(parser);
6765
+ const [head2, cells] = parseCells(parser);
6766
+ if (columns)
6767
+ return [head2, cells, { str: "()" }, { str: columns }];
6768
+ return [head2, cells];
6769
+ }
6770
+ },
6771
+ {
6772
+ kind: "environment",
6773
+ identifierTrigger: "bmatrix",
6774
+ parse: (parser) => {
6775
+ const columns = parseColumnFormat(parser);
6776
+ const [head2, cells] = parseCells(parser);
6777
+ if (columns)
6778
+ return [head2, cells, { str: "[]" }, { str: columns }];
6779
+ return [head2, cells, { str: "[]" }];
6780
+ }
6781
+ },
6782
+ {
6783
+ kind: "environment",
6784
+ identifierTrigger: "Bmatrix",
6785
+ parse: (parser) => {
6786
+ const columns = parseColumnFormat(parser);
6787
+ const [head2, cells] = parseCells(parser);
6788
+ if (columns)
6789
+ return [head2, cells, { str: "{}" }, { str: columns }];
6790
+ return [head2, cells, { str: "{}" }];
6791
+ }
6792
+ },
6793
+ {
6794
+ kind: "environment",
6795
+ identifierTrigger: "vmatrix",
6796
+ parse: (parser) => {
6797
+ const columns = parseColumnFormat(parser);
6798
+ const [head2, cells] = parseCells(parser);
6799
+ if (columns)
6800
+ return [head2, cells, { str: "||" }, { str: columns }];
6801
+ return [head2, cells, { str: "||" }];
6802
+ }
6803
+ },
6804
+ {
6805
+ kind: "environment",
6806
+ identifierTrigger: "Vmatrix",
6807
+ parse: (parser) => {
6808
+ const columns = parseColumnFormat(parser);
6809
+ const [head2, cells] = parseCells(parser);
6810
+ if (columns)
6811
+ return [head2, cells, { str: "\u2016\u2016" }, { str: columns }];
6812
+ return [head2, cells, { str: "\u2016\u2016" }];
6813
+ }
6814
+ },
6815
+ {
6816
+ kind: "environment",
6817
+ identifierTrigger: "smallmatrix",
6818
+ parse: (parser) => {
6819
+ const columns = parseColumnFormat(parser);
6820
+ const [head2, cells] = parseCells(parser);
6821
+ if (columns)
6822
+ return [head2, cells, { str: "()" }, { str: columns }];
6823
+ return [head2, cells];
6824
+ }
6825
+ },
6826
+ {
6827
+ kind: "environment",
6828
+ identifierTrigger: "array",
6829
+ parse: (parser) => {
6830
+ const columns = parseColumnFormat(parser, false);
6831
+ const [head2, cells] = parseCells(parser);
6832
+ if (columns)
6833
+ return [head2, cells, { str: ".." }, { str: columns }];
6834
+ return [head2, cells, { str: ".." }];
6835
+ }
6836
+ },
6837
+ {
6838
+ kind: "environment",
6839
+ identifierTrigger: "matrix",
6840
+ parse: (parser) => {
6841
+ const columns = parseColumnFormat(parser);
6842
+ const [head2, cells] = parseCells(parser);
6843
+ if (columns)
6844
+ return [head2, cells, { str: ".." }, { str: columns }];
6845
+ return [head2, cells, { str: ".." }];
6846
+ }
6847
+ },
6848
+ {
6849
+ kind: "environment",
6850
+ identifierTrigger: "matrix*",
6851
+ parse: (parser) => {
6852
+ const columns = parseColumnFormat(parser);
6853
+ const [head2, cells] = parseCells(parser);
6854
+ if (columns)
6855
+ return [head2, cells, { str: ".." }, { str: columns }];
6856
+ return [head2, cells, { str: ".." }];
6820
6857
  }
6821
6858
  }
6822
6859
  ];
6860
+ function parseCells(parser) {
6861
+ const tabular = parser.parseTabular();
6862
+ if (!tabular)
6863
+ return ["", null];
6864
+ return [
6865
+ "Matrix",
6866
+ ["List", ...tabular.map((row) => ["List", row])]
6867
+ ];
6868
+ }
6869
+ function parseColumnFormat(parser, optional = true) {
6870
+ const colFormat = parser.parseStringGroup(optional)?.trim();
6871
+ if (!colFormat)
6872
+ return "";
6873
+ let result = "";
6874
+ for (const c of colFormat) {
6875
+ if (c === "c")
6876
+ result += "=";
6877
+ if (c === "l")
6878
+ result += "<";
6879
+ if (c === "r")
6880
+ result += ">";
6881
+ if (c === "|")
6882
+ result += "|";
6883
+ if (c === ":")
6884
+ result += ":";
6885
+ }
6886
+ return result;
6887
+ }
6888
+ function serializeTabular(serializer, rows, delims, colSpec) {
6889
+ delims ?? (delims = "()");
6890
+ let [open, close] = ["", ""];
6891
+ if (typeof delims === "string" && delims.length === 2)
6892
+ [open, close] = delims;
6893
+ let columns = "";
6894
+ if (colSpec) {
6895
+ for (const c of colSpec) {
6896
+ if (c === "<")
6897
+ columns += "l";
6898
+ else if (c === ">")
6899
+ columns += "r";
6900
+ else if (c === "=")
6901
+ columns += "c";
6902
+ else if (c === "|")
6903
+ columns += "|";
6904
+ else if (c === ":")
6905
+ columns += ":";
6906
+ }
6907
+ }
6908
+ const serializedRows = [];
6909
+ for (const row of rows ?? []) {
6910
+ const cells = [];
6911
+ for (const cell of ops(row) ?? [])
6912
+ cells.push(serializer.serialize(cell));
6913
+ serializedRows.push(cells.join(" & "));
6914
+ }
6915
+ const tabular = serializedRows.join("\\\\\n");
6916
+ const optColumns = columns.length > 0 ? `[${columns}]` : "";
6917
+ if (open === "(" && close === ")")
6918
+ return joinLatex([
6919
+ "\\begin{pmatrix}",
6920
+ optColumns,
6921
+ tabular,
6922
+ "\\end{pmatrix}"
6923
+ ]);
6924
+ if (open === "[" && close === "]")
6925
+ return joinLatex([
6926
+ "\\begin{bmatrix}",
6927
+ optColumns,
6928
+ tabular,
6929
+ "\\end{bmatrix}"
6930
+ ]);
6931
+ if (open === "{" && close === "}")
6932
+ return joinLatex([
6933
+ "\\begin{Bmatrix}",
6934
+ optColumns,
6935
+ tabular,
6936
+ "\\end{Bmatrix}"
6937
+ ]);
6938
+ if (open === "|" && close === "|")
6939
+ return joinLatex([
6940
+ "\\begin{vmatrix}",
6941
+ optColumns,
6942
+ tabular,
6943
+ "\\end{vmatrix}"
6944
+ ]);
6945
+ if (open === "\u2016" && close === "\u2016")
6946
+ return joinLatex([
6947
+ "\\begin{Vmatrix}",
6948
+ optColumns,
6949
+ tabular,
6950
+ "\\end{Vmatrix}"
6951
+ ]);
6952
+ if (open === "{" && close === ".")
6953
+ return joinLatex(["\\begin{dcases}", optColumns, tabular, "\\end{dcases}"]);
6954
+ if (open === "." && close === "}")
6955
+ return joinLatex(["\\begin{rcases}", optColumns, tabular, "\\end{rcases}"]);
6956
+ if (columns || open !== "." || close !== ".") {
6957
+ return joinLatex([
6958
+ "\\left",
6959
+ DELIMITERS_SHORTHAND[open] ?? open,
6960
+ "\\begin{array}",
6961
+ `{${columns}}`,
6962
+ tabular,
6963
+ "\\end{array}",
6964
+ "\\right",
6965
+ DELIMITERS_SHORTHAND[close] ?? close
6966
+ ]);
6967
+ }
6968
+ return joinLatex(["\\begin{matrix}", tabular, "\\end{matrix}"]);
6969
+ }
6823
6970
 
6824
6971
  // src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
6825
6972
  var DEFINITIONS_LOGIC = [
@@ -8729,7 +8876,7 @@ var ComputeEngine = (() => {
8729
8876
  });
8730
8877
  return false;
8731
8878
  }
8732
- if ("identifierTrigger" in entry) {
8879
+ if ("identifierTrigger" in entry && (!("kind" in entry) || entry.kind !== "environment")) {
8733
8880
  if (typeof entry.identifierTrigger !== "string" || !isValidIdentifier(entry.identifierTrigger)) {
8734
8881
  onError({
8735
8882
  severity: "warning",
@@ -9698,12 +9845,14 @@ var ComputeEngine = (() => {
9698
9845
  return result;
9699
9846
  }
9700
9847
  /** Parse a group as a a string, for example for `\operatorname` or `\begin` */
9701
- parseStringGroup() {
9848
+ parseStringGroup(optional) {
9849
+ if (optional === void 0)
9850
+ optional = false;
9702
9851
  const start = this.index;
9703
9852
  while (this.match("<space>")) {
9704
9853
  }
9705
- if (this.match("<{>")) {
9706
- this.addBoundary(["<}>"]);
9854
+ if (this.match(optional ? "[" : "<{>")) {
9855
+ this.addBoundary([optional ? "]" : "<}>"]);
9707
9856
  const arg = this.parseStringGroupContent();
9708
9857
  if (this.matchBoundary())
9709
9858
  return arg;
@@ -11454,13 +11603,13 @@ var ComputeEngine = (() => {
11454
11603
  };
11455
11604
 
11456
11605
  // src/compute-engine/domain-utils.ts
11457
- var import_complex3 = __toESM(require_complex());
11606
+ var import_complex3 = __toESM(require_complex(), 1);
11458
11607
 
11459
11608
  // src/compute-engine/numerics/rationals.ts
11460
- var import_complex2 = __toESM(require_complex());
11609
+ var import_complex2 = __toESM(require_complex(), 1);
11461
11610
 
11462
11611
  // src/compute-engine/numerics/numeric.ts
11463
- var import_complex = __toESM(require_complex());
11612
+ var import_complex = __toESM(require_complex(), 1);
11464
11613
 
11465
11614
  // src/compute-engine/numerics/richardson.ts
11466
11615
  function extrapolate(f, x0, options = {}) {
@@ -13492,7 +13641,7 @@ var ComputeEngine = (() => {
13492
13641
  }
13493
13642
 
13494
13643
  // src/compute-engine/boxed-expression/utils.ts
13495
- var import_complex4 = __toESM(require_complex());
13644
+ var import_complex4 = __toESM(require_complex(), 1);
13496
13645
  function isLatexString(s) {
13497
13646
  if (typeof s === "string")
13498
13647
  return s.startsWith("$") && s.endsWith("$");
@@ -13712,7 +13861,7 @@ var ComputeEngine = (() => {
13712
13861
  }
13713
13862
 
13714
13863
  // src/compute-engine/boxed-expression/order.ts
13715
- var import_complex5 = __toESM(require_complex());
13864
+ var import_complex5 = __toESM(require_complex(), 1);
13716
13865
 
13717
13866
  // src/compute-engine/symbolic/polynomials.ts
13718
13867
  function totalDegree(expr) {
@@ -13760,7 +13909,7 @@ var ComputeEngine = (() => {
13760
13909
 
13761
13910
  // src/compute-engine/boxed-expression/order.ts
13762
13911
  var DEFAULT_COMPLEXITY = 1e5;
13763
- function sortAdd(ce, ops2) {
13912
+ function sortAdd(ops2) {
13764
13913
  return ops2.sort((a, b) => {
13765
13914
  const aLex = lex(a);
13766
13915
  const bLex = lex(b);
@@ -13880,6 +14029,15 @@ var ComputeEngine = (() => {
13880
14029
  }
13881
14030
  return (a.complexity ?? DEFAULT_COMPLEXITY) - (b.complexity ?? DEFAULT_COMPLEXITY);
13882
14031
  }
14032
+ function canonicalOrder(expr, { recursive = false }) {
14033
+ if (expr.ops) {
14034
+ const ops2 = recursive ? expr.ops.map((x) => canonicalOrder(x, { recursive })) : expr.ops;
14035
+ if (expr.head === "Add")
14036
+ return expr.engine._fn("Add", sortAdd(ops2));
14037
+ return expr.engine._fn(expr.head, ops2.sort(order));
14038
+ }
14039
+ return expr;
14040
+ }
13883
14041
  function getLeafCount(expr) {
13884
14042
  if (expr.keys !== null)
13885
14043
  return 1 + expr.keysCount;
@@ -13930,7 +14088,7 @@ var ComputeEngine = (() => {
13930
14088
  }
13931
14089
 
13932
14090
  // src/compute-engine/symbolic/sum.ts
13933
- var import_complex6 = __toESM(require_complex());
14091
+ var import_complex6 = __toESM(require_complex(), 1);
13934
14092
 
13935
14093
  // src/compute-engine/collection-utils.ts
13936
14094
  function isCollection(col) {
@@ -14235,7 +14393,7 @@ var ComputeEngine = (() => {
14235
14393
  return ce.Zero;
14236
14394
  if (xs.length === 1 && !isIndexableCollection(xs[0]))
14237
14395
  return xs[0];
14238
- return ce._fn("Add", sortAdd(ce, xs));
14396
+ return ce._fn("Add", sortAdd(xs));
14239
14397
  }
14240
14398
  };
14241
14399
 
@@ -14445,10 +14603,10 @@ var ComputeEngine = (() => {
14445
14603
  }
14446
14604
 
14447
14605
  // src/compute-engine/boxed-expression/abstract-boxed-expression.ts
14448
- var import_complex8 = __toESM(require_complex());
14606
+ var import_complex8 = __toESM(require_complex(), 1);
14449
14607
 
14450
14608
  // src/compute-engine/symbolic/utils.ts
14451
- var import_complex7 = __toESM(require_complex());
14609
+ var import_complex7 = __toESM(require_complex(), 1);
14452
14610
  function makePositive(expr) {
14453
14611
  if (expr.head === "Negate")
14454
14612
  return [-1, expr.op1];
@@ -15625,6 +15783,7 @@ var ComputeEngine = (() => {
15625
15783
  set value(_value) {
15626
15784
  throw new Error(`Can't change the value of \\(${this.latex}\\)`);
15627
15785
  }
15786
+ // @ts-ignore
15628
15787
  get domain() {
15629
15788
  return void 0;
15630
15789
  }
@@ -15990,7 +16149,7 @@ var ComputeEngine = (() => {
15990
16149
  return ce.number(ce.complex(re, im));
15991
16150
  }
15992
16151
  if (ops2.length > 1)
15993
- ops2 = sortAdd(ce, ops2);
16152
+ ops2 = sortAdd(ops2);
15994
16153
  return ce._fn("Add", ops2);
15995
16154
  }
15996
16155
  function domainAdd(_ce, args) {
@@ -16094,12 +16253,16 @@ var ComputeEngine = (() => {
16094
16253
  }
16095
16254
  return result ?? void 0;
16096
16255
  }
16097
- const [index, lower, upper, isFinite2] = normalizeLimits(range);
16256
+ const [index, lower, upper, isFinite2] = normalizeLimits(range.evaluate());
16098
16257
  if (!index)
16099
16258
  return void 0;
16100
16259
  const fn = expr;
16101
- if (mode == "simplify" && (lower >= upper || upper - lower >= MAX_SYMBOLIC_TERMS))
16260
+ if (lower >= upper)
16261
+ return void 0;
16262
+ if (mode === "simplify" && upper - lower >= MAX_SYMBOLIC_TERMS)
16102
16263
  return void 0;
16264
+ if (mode === "evaluate" && upper - lower >= MAX_SYMBOLIC_TERMS)
16265
+ mode = "N";
16103
16266
  const savedContext = ce.swapScope(fn.scope);
16104
16267
  ce.pushScope();
16105
16268
  fn.bind();
@@ -16198,7 +16361,7 @@ var ComputeEngine = (() => {
16198
16361
  }
16199
16362
 
16200
16363
  // src/compute-engine/symbolic/negate.ts
16201
- var import_complex9 = __toESM(require_complex());
16364
+ var import_complex9 = __toESM(require_complex(), 1);
16202
16365
  function negateLiteral(expr, metadata) {
16203
16366
  let n = expr.numericValue;
16204
16367
  if (n === null)
@@ -16730,10 +16893,10 @@ var ComputeEngine = (() => {
16730
16893
  }
16731
16894
 
16732
16895
  // src/compute-engine/boxed-expression/box.ts
16733
- var import_complex14 = __toESM(require_complex());
16896
+ var import_complex14 = __toESM(require_complex(), 1);
16734
16897
 
16735
16898
  // src/compute-engine/boxed-expression/serialize.ts
16736
- var import_complex11 = __toESM(require_complex());
16899
+ var import_complex11 = __toESM(require_complex(), 1);
16737
16900
 
16738
16901
  // src/compute-engine/numerics/numeric-bignum.ts
16739
16902
  function gcd3(a, b) {
@@ -16858,7 +17021,7 @@ var ComputeEngine = (() => {
16858
17021
  }
16859
17022
 
16860
17023
  // src/compute-engine/symbolic/product.ts
16861
- var import_complex10 = __toESM(require_complex());
17024
+ var import_complex10 = __toESM(require_complex(), 1);
16862
17025
  var Product = class {
16863
17026
  constructor(ce, xs, options) {
16864
17027
  this.options = options;
@@ -17806,7 +17969,7 @@ var ComputeEngine = (() => {
17806
17969
  };
17807
17970
 
17808
17971
  // src/compute-engine/boxed-expression/boxed-function.ts
17809
- var import_complex12 = __toESM(require_complex());
17972
+ var import_complex12 = __toESM(require_complex(), 1);
17810
17973
 
17811
17974
  // src/compute-engine/simplify-rules.ts
17812
17975
  var SIMPLIFY_RULES = [];
@@ -18529,7 +18692,7 @@ var ComputeEngine = (() => {
18529
18692
  }
18530
18693
 
18531
18694
  // src/compute-engine/boxed-expression/boxed-number.ts
18532
- var import_complex13 = __toESM(require_complex());
18695
+ var import_complex13 = __toESM(require_complex(), 1);
18533
18696
 
18534
18697
  // src/compute-engine/numerics/primes.ts
18535
18698
  var LARGE_PRIME = 1125899906842597;
@@ -19417,7 +19580,7 @@ var ComputeEngine = (() => {
19417
19580
  }
19418
19581
 
19419
19582
  // src/compute-engine/library/arithmetic.ts
19420
- var import_complex16 = __toESM(require_complex());
19583
+ var import_complex16 = __toESM(require_complex(), 1);
19421
19584
 
19422
19585
  // src/compute-engine/numerics/numeric-complex.ts
19423
19586
  function gamma3(c) {
@@ -19428,7 +19591,7 @@ var ComputeEngine = (() => {
19428
19591
  }
19429
19592
 
19430
19593
  // src/compute-engine/library/arithmetic-power.ts
19431
- var import_complex15 = __toESM(require_complex());
19594
+ var import_complex15 = __toESM(require_complex(), 1);
19432
19595
  function canonicalPower(ce, base, exponent, metadata) {
19433
19596
  if (exponent.symbol === "ComplexInfinity")
19434
19597
  return ce.NaN;
@@ -22613,6 +22776,15 @@ var ComputeEngine = (() => {
22613
22776
  return result;
22614
22777
  }
22615
22778
  function canonicalList(ce, ops2) {
22779
+ const op12 = ops2[0];
22780
+ if (ops2.length === 1 && op12.head === "Matrix") {
22781
+ const [body, delimiters, columns] = op12.ops;
22782
+ if (!delimiters || delimiters.string === "..") {
22783
+ if (!columns)
22784
+ return ce._fn("Matrix", [body, delimiters]);
22785
+ return ce._fn("Matrix", [body, ce.string("[]"), columns]);
22786
+ }
22787
+ }
22616
22788
  ops2 = ops2.map((op3) => {
22617
22789
  if (op3.head === "Delimiter") {
22618
22790
  if (op3.op1.head === "Sequence")
@@ -23456,6 +23628,18 @@ var ComputeEngine = (() => {
23456
23628
  evaluate: (_ce, ops2) => ops2[0].simplify()
23457
23629
  }
23458
23630
  },
23631
+ // Can be used to sort arguments of an expression.
23632
+ // Sorting arguments of commutative functions is a weak form of
23633
+ // canonicalization that can be useful in some cases, for example
23634
+ // to accept "x+1" and "1+x" while rejecting "x+1" and "2x-x+1"
23635
+ CanonicalOrder: {
23636
+ complexity: 8200,
23637
+ hold: "all",
23638
+ signature: {
23639
+ domain: ["FunctionOf", "Anything", "Anything"],
23640
+ canonical: (_ce, ops2) => canonicalOrder(ops2[0], { recursive: true })
23641
+ }
23642
+ },
23459
23643
  N: {
23460
23644
  hold: "all",
23461
23645
  signature: {
@@ -23739,22 +23923,40 @@ var ComputeEngine = (() => {
23739
23923
  evaluate: (_ce, ops2) => ops2[0].evaluate(),
23740
23924
  N: (_ce, ops2) => ops2[0].N()
23741
23925
  }
23926
+ },
23927
+ // Vector is a specialized collection to represent a column vector.
23928
+ // ["Vector", a, b, c] is a shorthand for ["List", ["List", a], ["List", b], ["List", c]]
23929
+ Vector: {
23930
+ complexity: 9e3,
23931
+ hold: "all",
23932
+ signature: {
23933
+ restParam: "Anything",
23934
+ result: "Lists",
23935
+ canonical: (ce, ops2) => {
23936
+ return ce._fn("Matrix", [
23937
+ ce._fn(
23938
+ "List",
23939
+ ce.canonical(ops2).map((op3) => ce._fn("List", [op3]))
23940
+ )
23941
+ ]);
23942
+ }
23943
+ }
23742
23944
  }
23743
23945
  }
23744
23946
  ];
23745
- function canonicalMatrix(ce, ops2) {
23947
+ function canonicalMatrix(ce, ops2, head2 = "Matrix") {
23746
23948
  if (ops2.length === 0)
23747
- return ce._fn("Matrix", []);
23748
- const body = ops2[0].canonical;
23949
+ return ce._fn(head2, []);
23950
+ const body = ops2[0].head === "Vector" ? ops2[0].canonical.ops[0] : ops2[0].canonical;
23749
23951
  const delims = ops2[1]?.canonical;
23750
23952
  const columns = ops2[2]?.canonical;
23751
23953
  if (ops2.length > 3)
23752
- return ce._fn("Matrix", checkArity(ce, ops2, 3));
23954
+ return ce._fn(head2, checkArity(ce, ops2, 3));
23753
23955
  if (columns)
23754
- return ce._fn("Matrix", [body, delims, columns]);
23956
+ return ce._fn(head2, [body, delims, columns]);
23755
23957
  if (delims)
23756
- return ce._fn("Matrix", [body, delims]);
23757
- return ce._fn("Matrix", [body]);
23958
+ return ce._fn(head2, [body, delims]);
23959
+ return ce._fn(head2, [body]);
23758
23960
  }
23759
23961
 
23760
23962
  // src/compute-engine/library/logic.ts
@@ -23992,6 +24194,28 @@ var ComputeEngine = (() => {
23992
24194
  }
23993
24195
  }
23994
24196
  },
24197
+ IsSame: {
24198
+ description: "Compare two expressions for structural equality",
24199
+ hold: "all",
24200
+ signature: {
24201
+ domain: "RelationalOperators",
24202
+ // Since we want to work on non-canonical expressions,
24203
+ // do nothing to canonicalize the arguments
24204
+ evaluate: (ce, ops2) => {
24205
+ if (ops2.length !== 2)
24206
+ return void 0;
24207
+ let [lhs, rhs] = ops2;
24208
+ if (lhs.head === "CanonicalOrder")
24209
+ lhs = lhs.canonical;
24210
+ if (rhs.head === "CanonicalOrder")
24211
+ rhs = rhs.canonical;
24212
+ const test = lhs.isSame(rhs);
24213
+ if (test === true)
24214
+ return ce.True;
24215
+ return ce.False;
24216
+ }
24217
+ }
24218
+ },
23995
24219
  Equal: {
23996
24220
  commutative: true,
23997
24221
  complexity: 11e3,
@@ -25679,7 +25903,7 @@ var ComputeEngine = (() => {
25679
25903
  }
25680
25904
 
25681
25905
  // src/compute-engine/boxed-expression/boxed-symbol-definition.ts
25682
- var import_complex17 = __toESM(require_complex());
25906
+ var import_complex17 = __toESM(require_complex(), 1);
25683
25907
  var _BoxedSymbolDefinition = class {
25684
25908
  // @todo
25685
25909
  constructor(ce, name, def) {
@@ -26671,7 +26895,7 @@ ${JSON.stringify(entry)}`
26671
26895
  }
26672
26896
 
26673
26897
  // src/compute-engine/cost-function.ts
26674
- var import_complex19 = __toESM(require_complex());
26898
+ var import_complex19 = __toESM(require_complex(), 1);
26675
26899
  function numericCostFunction(n) {
26676
26900
  if (Number.isInteger(n) && n !== 0) {
26677
26901
  return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
@@ -27253,6 +27477,7 @@ ${JSON.stringify(entry)}`
27253
27477
  });
27254
27478
  }
27255
27479
  }
27480
+ // @ts-ignore
27256
27481
  get domain() {
27257
27482
  const def = this._def;
27258
27483
  if (def) {
@@ -27641,7 +27866,6 @@ ${JSON.stringify(entry)}`
27641
27866
  symbols: /* @__PURE__ */ new Set(),
27642
27867
  expressions: /* @__PURE__ */ new Set()
27643
27868
  };
27644
- this._defaultDomain = null;
27645
27869
  this._numericMode = options?.numericMode ?? "auto";
27646
27870
  this._precision = Math.max(
27647
27871
  options?.numericPrecision ?? 100,
@@ -27885,6 +28109,56 @@ ${JSON.stringify(entry)}`
27885
28109
  return 0;
27886
28110
  return n;
27887
28111
  }
28112
+ /** Create an arbitrary precision number.
28113
+ *
28114
+ * The return value is an object with methods to perform arithmetic
28115
+ * operations:
28116
+ * - `toNumber()`: convert to a JavaScript `number` with potential loss of precision
28117
+ * - `add()`
28118
+ * - `sub()`
28119
+ * - `neg()` (unary minus)
28120
+ * - `mul()`
28121
+ * - `div()`
28122
+ * - `pow()`
28123
+ * - `sqrt()` (square root)
28124
+ * - `cbrt()` (cube root)
28125
+ * - `exp()` (e^x)
28126
+ * - `log()`
28127
+ * - `ln()` (natural logarithm)
28128
+ * - `mod()`
28129
+
28130
+ * - `abs()`
28131
+ * - `ceil()`
28132
+ * - `floor()`
28133
+ * - `round()`
28134
+
28135
+ * - `equals()`
28136
+ * - `gt()`
28137
+ * - `gte()`
28138
+ * - `lt()`
28139
+ * - `lte()`
28140
+ *
28141
+ * - `cos()`
28142
+ * - `sin()`
28143
+ * - `tanh()`
28144
+ * - `acos()`
28145
+ * - `asin()`
28146
+ * - `atan()`
28147
+ * - `cosh()`
28148
+ * - `sinh()`
28149
+ * - `acosh()`
28150
+ * - `asinh()`
28151
+ * - `atanh()`
28152
+ *
28153
+ * - `isFinite()`
28154
+ * - `isInteger()`
28155
+ * - `isNaN()`
28156
+ * - `isNegative()`
28157
+ * - `isPositive()`
28158
+ * - `isZero()`
28159
+ * - `sign()` (1, 0 or -1)
28160
+ *
28161
+ */
27888
28162
  bignum(a) {
27889
28163
  if (typeof a === "bigint")
27890
28164
  return new this._bignum(a.toString());
@@ -27895,6 +28169,51 @@ ${JSON.stringify(entry)}`
27895
28169
  }
27896
28170
  return this._BIGNUM_NAN;
27897
28171
  }
28172
+ /** Create a complex number.
28173
+ * The return value is an object with methods to perform arithmetic
28174
+ * operations:
28175
+ * - `re` (real part, as a JavaScript `number`)
28176
+ * - `im` (imaginary part, as a JavaScript `number`)
28177
+ * - `add()`
28178
+ * - `sub()`
28179
+ * - `neg()` (unary minus)
28180
+ * - `mul()`
28181
+ * - `div()`
28182
+ * - `pow()`
28183
+ * - `sqrt()` (square root)
28184
+ * - `exp()` (e^x)
28185
+ * - `log()`
28186
+ * - `ln()` (natural logarithm)
28187
+ * - `mod()`
28188
+
28189
+ * - `abs()`
28190
+ * - `ceil()`
28191
+ * - `floor()`
28192
+ * - `round()`
28193
+
28194
+ * - `arg()` the angle of the complex number
28195
+ * - `inverse()` the inverse of the complex number 1/z
28196
+ * - `conjugate()` the conjugate of the complex number
28197
+
28198
+ * - `equals()`
28199
+ *
28200
+ * - `cos()`
28201
+ * - `sin()`
28202
+ * - `tanh()`
28203
+ * - `acos()`
28204
+ * - `asin()`
28205
+ * - `atan()`
28206
+ * - `cosh()`
28207
+ * - `sinh()`
28208
+ * - `acosh()`
28209
+ * - `asinh()`
28210
+ * - `atanh()`
28211
+ *
28212
+ * - `isFinite()`
28213
+ * - `isNaN()`
28214
+ * - `isZero()`
28215
+ * - `sign()` (1, 0 or -1)
28216
+ */
27898
28217
  complex(a, b) {
27899
28218
  if (a instanceof Decimal)
27900
28219
  a = a.toNumber();
@@ -27998,7 +28317,14 @@ ${JSON.stringify(entry)}`
27998
28317
  return void 0;
27999
28318
  }
28000
28319
  /**
28001
- * Add (or replace) a definition for a symbol in the current scope.
28320
+ * Associate a new definition to a symbol in the current context.
28321
+ *
28322
+ * If a definition existed previously, it is replaced.
28323
+ *
28324
+ *
28325
+ * For internal use. Use `ce.declare()` instead.
28326
+ *
28327
+ * @internal
28002
28328
  */
28003
28329
  defineSymbol(name, def) {
28004
28330
  if (!this.context)
@@ -28015,6 +28341,15 @@ ${JSON.stringify(entry)}`
28015
28341
  this.context.ids.set(boxedDef.name, boxedDef);
28016
28342
  return boxedDef;
28017
28343
  }
28344
+ /**
28345
+ * Associate a new delookupSymbolfinition to a function in the current context.
28346
+ *
28347
+ * If a definition existed previously, it is replaced.
28348
+ *
28349
+ * For internal use. Use `ce.declare()` instead.
28350
+ *
28351
+ * @internal
28352
+ */
28018
28353
  defineFunction(name, def) {
28019
28354
  if (!this.context)
28020
28355
  throw Error("Function cannot be defined: no scope available");
@@ -28059,8 +28394,8 @@ ${JSON.stringify(entry)}`
28059
28394
  };
28060
28395
  return this;
28061
28396
  }
28062
- /** Remove the topmost scope from the scope stack.
28063
- */
28397
+ /** Remove the most recent scope from the scope stack, and set its
28398
+ * parent scope as current. */
28064
28399
  popScope() {
28065
28400
  if (!this.context)
28066
28401
  throw Error("No scope available");
@@ -28068,12 +28403,17 @@ ${JSON.stringify(entry)}`
28068
28403
  console.assert(this.context);
28069
28404
  return this;
28070
28405
  }
28406
+ /** Set the current scope, return the previous scope. */
28071
28407
  swapScope(scope) {
28072
28408
  const oldScope = this.context;
28073
28409
  this.context = scope;
28074
28410
  console.assert(this.context);
28075
28411
  return oldScope;
28076
28412
  }
28413
+ /**
28414
+ * Reset the value of any identifiers that have been assigned a value
28415
+ * in the current scope.
28416
+ * @internal */
28077
28417
  resetContext() {
28078
28418
  if (!this.context)
28079
28419
  return;
@@ -28093,6 +28433,7 @@ ${JSON.stringify(entry)}`
28093
28433
  }
28094
28434
  }
28095
28435
  }
28436
+ /** @internal */
28096
28437
  _printScope(options, scope, depth = 0) {
28097
28438
  options ?? (options = { details: false, maxDepth: 1 });
28098
28439
  scope ?? (scope = this.context);
@@ -28403,6 +28744,9 @@ ${JSON.stringify(entry)}`
28403
28744
  }
28404
28745
  return this._cache[cacheName]?.value;
28405
28746
  }
28747
+ /**
28748
+ * Return a boxed expression from the input.
28749
+ */
28406
28750
  box(expr, options) {
28407
28751
  return box(this, expr, options);
28408
28752
  }
@@ -28412,6 +28756,16 @@ ${JSON.stringify(entry)}`
28412
28756
  const bxs = xs;
28413
28757
  return bxs.every((x) => x.isCanonical) ? bxs : bxs.map((x) => x.canonical);
28414
28758
  }
28759
+ /**
28760
+ * Return a function expression.
28761
+ *
28762
+ * Note that the result may not be a function, or may have a different
28763
+ * `head` than the one specified.
28764
+ *
28765
+ * For example:
28766
+ * `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
28767
+ *
28768
+ */
28415
28769
  fn(head2, ops2, options) {
28416
28770
  return boxFunction(this, head2, ops2, options ?? { canonical: true });
28417
28771
  }
@@ -28456,18 +28810,33 @@ ${JSON.stringify(entry)}`
28456
28810
  const actual = actualDomain ? actualDomain : this.symbol("Undefined");
28457
28811
  return this.error(["incompatible-domain", expected, actual], where);
28458
28812
  }
28813
+ /**
28814
+ * Add a`["Hold"]` wrapper to `expr.
28815
+ */
28459
28816
  hold(expr) {
28460
28817
  return this._fn("Hold", [this.box(expr, { canonical: false })]);
28461
28818
  }
28819
+ /** Shortcut for `this.fn("Add"...)`.
28820
+ *
28821
+ * The result is canonical.
28822
+ */
28462
28823
  add(ops2, metadata) {
28463
28824
  const result = canonicalAdd(this, flattenOps(flattenSequence(ops2), "Add"));
28464
28825
  if (metadata?.latex !== void 0)
28465
28826
  result.latex = metadata.latex;
28466
28827
  return result;
28467
28828
  }
28829
+ /** Shortcut for `this.fn("Negate", [expr])`
28830
+ *
28831
+ * The result is canonical.
28832
+ */
28468
28833
  neg(expr, metadata) {
28469
28834
  return canonicalNegate(expr, metadata);
28470
28835
  }
28836
+ /** Shortcut for `this.fn("Multiply"...)`
28837
+ *
28838
+ * The result is canonical.
28839
+ */
28471
28840
  mul(ops2, metadata) {
28472
28841
  const result = canonicalMultiply(
28473
28842
  this,
@@ -28477,15 +28846,27 @@ ${JSON.stringify(entry)}`
28477
28846
  result.latex = metadata.latex;
28478
28847
  return result;
28479
28848
  }
28849
+ /** Shortcut for `this.fn("Divide", [num, denom])`
28850
+ *
28851
+ * The result is canonical.
28852
+ */
28480
28853
  div(num, denom, metadata) {
28481
28854
  const result = canonicalDivide(this, num, denom);
28482
28855
  if (metadata?.latex !== void 0)
28483
28856
  result.latex = metadata.latex;
28484
28857
  return result;
28485
28858
  }
28859
+ /** Shortcut for `this.fn("Sqrt"...)`
28860
+ *
28861
+ * The result is canonical.
28862
+ */
28486
28863
  sqrt(base, metadata) {
28487
28864
  return canonicalPower(this, base, this.Half, metadata);
28488
28865
  }
28866
+ /** Shortcut for `this.fn("Power"...)`
28867
+ *
28868
+ * The result is canonical.
28869
+ */
28489
28870
  pow(base, exponent, metadata) {
28490
28871
  if (base.symbol === "ExponentialE" && exponent instanceof import_complex20.Complex) {
28491
28872
  const im = exponent.im;
@@ -28536,6 +28917,10 @@ ${JSON.stringify(entry)}`
28536
28917
  exponent = this.number(exponent);
28537
28918
  return canonicalPower(this, base, exponent, metadata);
28538
28919
  }
28920
+ /** Shortcut for `this.fn("Divide", [1, expr])`
28921
+ *
28922
+ * The result is canonical.
28923
+ */
28539
28924
  inv(expr, metadata) {
28540
28925
  if (expr.isOne)
28541
28926
  return this.One;
@@ -28568,21 +28953,33 @@ ${JSON.stringify(entry)}`
28568
28953
  return this._fn("Divide", [this.One, expr], metadata);
28569
28954
  return this._fn("Power", [expr, e], metadata);
28570
28955
  }
28956
+ /** Shortcut for `this.fn("Pair"...)`
28957
+ *
28958
+ * The result is canonical.
28959
+ */
28571
28960
  pair(first, second, metadata) {
28572
28961
  return new BoxedFunction(this, "Tuple", [first, second], {
28573
28962
  metadata,
28574
28963
  canonical: true
28575
28964
  });
28576
28965
  }
28966
+ /** Shortcut for `this.fn("Tuple"...)`
28967
+ *
28968
+ * The result is canonical.
28969
+ */
28577
28970
  tuple(elements, metadata) {
28578
28971
  return new BoxedFunction(this, "Tuple", canonical(elements), {
28579
28972
  metadata,
28580
28973
  canonical: true
28581
28974
  });
28582
28975
  }
28976
+ array(elements, metadata) {
28977
+ return this.Nothing;
28978
+ }
28583
28979
  string(s, metadata) {
28584
28980
  return new BoxedString(this, s, metadata);
28585
28981
  }
28982
+ /** Return a boxed symbol */
28586
28983
  symbol(name, options) {
28587
28984
  options = options ? { ...options } : {};
28588
28985
  if (!("canonical" in options))
@@ -28620,6 +29017,11 @@ ${JSON.stringify(entry)}`
28620
29017
  return makeCanonicalSymbol(this, name);
28621
29018
  return new BoxedSymbol(this, name, options);
28622
29019
  }
29020
+ /** Return a canonical boxed domain.
29021
+ *
29022
+ * If the domain is invalid, may return an `["Error"]` expression
29023
+ *
29024
+ */
28623
29025
  domain(domain, metadata) {
28624
29026
  if (domain instanceof _BoxedDomain)
28625
29027
  return domain;
@@ -28653,7 +29055,7 @@ ${JSON.stringify(entry)}`
28653
29055
  throw Error("Expected a domain constructor, got " + constructor);
28654
29056
  return new _BoxedDomain(this, domain, metadata);
28655
29057
  }
28656
- /*
29058
+ /**
28657
29059
  * This function tries to avoid creating a boxed number if `num` corresponds
28658
29060
  * to a common value for which we have a shared instance (-1, 0, NaN, etc...)
28659
29061
  */
@@ -28705,6 +29107,9 @@ ${JSON.stringify(entry)}`
28705
29107
  const result = this.latexSyntax.parse(latexString(latex) ?? latex);
28706
29108
  return this.box(result, options);
28707
29109
  }
29110
+ /** Serialize a `BoxedExpression` or a `MathJSON` expression to
29111
+ * a LaTeX string
29112
+ */
28708
29113
  serialize(x, options) {
28709
29114
  if (typeof x === "object" && "json" in x) {
28710
29115
  const ce = "engine" in x ? x.engine : this;
@@ -28715,6 +29120,16 @@ ${JSON.stringify(entry)}`
28715
29120
  }
28716
29121
  return this.latexSyntax.serialize(x, options);
28717
29122
  }
29123
+ /**
29124
+ * Options to control the serialization of MathJSON expression to LaTeX
29125
+ * when using `this.latex` or `this.engine.serialize()`.
29126
+ *
29127
+ *
29128
+ * {@inheritDoc NumberFormattingOptions}
29129
+ * {@inheritDoc ParseLatexOptions}
29130
+ * {@inheritDoc SerializeLatexOptions}
29131
+ *
29132
+ */
28718
29133
  get latexOptions() {
28719
29134
  const latexSyntax = this.latexSyntax;
28720
29135
  return new Proxy(
@@ -28735,6 +29150,7 @@ ${JSON.stringify(entry)}`
28735
29150
  set latexOptions(opts) {
28736
29151
  this.latexSyntax.updateOptions(opts);
28737
29152
  }
29153
+ /** {@inheritDoc JsonSerializationOptions} */
28738
29154
  get jsonSerializationOptions() {
28739
29155
  if (this._useRawJsonSerializationOptions) {
28740
29156
  return new Proxy(this._rawJsonSerializationOptions, {
@@ -28823,6 +29239,21 @@ ${JSON.stringify(entry)}`
28823
29239
  verify(_query) {
28824
29240
  return false;
28825
29241
  }
29242
+ /**
29243
+ * Add an assumption.
29244
+ *
29245
+ * Note that the assumption is put into canonical form before being added.
29246
+ *
29247
+ * @param symbol - The symbol to make an assumption about
29248
+ *
29249
+ * Returns:
29250
+ * - `contradiction` if the new assumption is incompatible with previous
29251
+ * ones.
29252
+ * - `tautology` if the new assumption is redundant with previous ones.
29253
+ * - `ok` if the assumption was successfully added to the assumption set.
29254
+ *
29255
+ *
29256
+ */
28826
29257
  assume(predicate) {
28827
29258
  try {
28828
29259
  return assume(this.box(predicate, { canonical: false }));
@@ -28831,6 +29262,7 @@ ${JSON.stringify(entry)}`
28831
29262
  return "internal-error";
28832
29263
  }
28833
29264
  }
29265
+ /** Remove all assumptions about one or more symbols */
28834
29266
  forget(symbol2) {
28835
29267
  if (!this.context)
28836
29268
  throw Error("No scope available");
@@ -28878,10 +29310,10 @@ ${JSON.stringify(entry)}`
28878
29310
  }
28879
29311
 
28880
29312
  // src/compute-engine.ts
28881
- var version = "0.20.2";
29313
+ var version = "0.21.0";
28882
29314
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
28883
29315
  ComputeEngine: ComputeEngine.prototype.constructor,
28884
- version: "0.20.2"
29316
+ version: "0.21.0"
28885
29317
  };
28886
29318
  return __toCommonJS(compute_engine_exports);
28887
29319
  })();