solve-engine 1.0.0-beta.7 → 1.0.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 (205) hide show
  1. package/dist/{BytecodeBuilder-3egMyuDi.d.cts → BytecodeBuilder-B0xskcv5.d.cts} +2 -1
  2. package/dist/{BytecodeBuilder-3egMyuDi.d.ts → BytecodeBuilder-B0xskcv5.d.ts} +2 -1
  3. package/dist/{Configuration-fVpd-HC-.d.cts → Configuration-B-G5gTRn.d.cts} +107 -29
  4. package/dist/{Configuration-fVpd-HC-.d.ts → Configuration-B-G5gTRn.d.ts} +107 -29
  5. package/dist/{EngineError-DvPSnhZi.d.cts → EngineError-LU7W7AgI.d.cts} +96 -16
  6. package/dist/{EngineError-DvPSnhZi.d.ts → EngineError-LU7W7AgI.d.ts} +96 -16
  7. package/dist/{Lexer-W9MBOP0V.d.ts → Lexer-BN5mt30n.d.ts} +16 -0
  8. package/dist/{Lexer-Cfm79Dak.d.cts → Lexer-D78E2yDW.d.cts} +16 -0
  9. package/dist/{PackageRegistry-CjDt-Jy_.d.ts → PackageRegistry-DFeINv2O.d.ts} +54 -13
  10. package/dist/{PackageRegistry-pHtKythi.d.cts → PackageRegistry-u2zdfFaj.d.cts} +54 -13
  11. package/dist/{Parselet-DEdF9I7n.d.ts → Parselet-BaySkMV3.d.ts} +37 -5
  12. package/dist/{Parselet-Cu0bLSis.d.cts → Parselet-DuI1Pjiq.d.cts} +37 -5
  13. package/dist/{ScopeManager-CKfQtl7l.d.cts → ScopeManager-B6GzdhVG.d.cts} +75 -6
  14. package/dist/{ScopeManager-B5k0nk05.d.ts → ScopeManager-udv4Twwq.d.ts} +75 -6
  15. package/dist/{VMCheckpoints-BmDwIXgK.d.ts → VMCheckpoints-BiaIlOOY.d.ts} +4 -4
  16. package/dist/{VMCheckpoints-CqFuLwrT.d.cts → VMCheckpoints-DwLjivM7.d.cts} +4 -4
  17. package/dist/{Value-KtAQNHur.d.cts → Value-CXJqDH9J.d.cts} +5 -2
  18. package/dist/{Value-KtAQNHur.d.ts → Value-CXJqDH9J.d.ts} +5 -2
  19. package/dist/{chunk-CSG5XVNJ.cjs → chunk-3AFRJYP4.cjs} +556 -414
  20. package/dist/chunk-3AFRJYP4.cjs.map +1 -0
  21. package/dist/chunk-3BOK2LDK.js +17 -0
  22. package/dist/chunk-3BOK2LDK.js.map +1 -0
  23. package/dist/{chunk-6RDSQURE.js → chunk-3D7V24DG.js} +57 -6
  24. package/dist/chunk-3D7V24DG.js.map +1 -0
  25. package/dist/{chunk-MEOHSQEH.js → chunk-3LAEG75D.js} +47 -15
  26. package/dist/chunk-3LAEG75D.js.map +1 -0
  27. package/dist/{chunk-P75775WC.js → chunk-3VNGREMU.js} +118 -41
  28. package/dist/chunk-3VNGREMU.js.map +1 -0
  29. package/dist/{chunk-4AVD7NZW.cjs → chunk-4B2CNWQU.cjs} +13 -7
  30. package/dist/chunk-4B2CNWQU.cjs.map +1 -0
  31. package/dist/{chunk-6GCKCWLB.js → chunk-526PMQOA.js} +126 -69
  32. package/dist/chunk-526PMQOA.js.map +1 -0
  33. package/dist/{chunk-2CS6OMZK.js → chunk-5F4C26RU.js} +8 -5
  34. package/dist/chunk-5F4C26RU.js.map +1 -0
  35. package/dist/{chunk-M4N5GA5Z.cjs → chunk-5KMIY374.cjs} +57 -6
  36. package/dist/chunk-5KMIY374.cjs.map +1 -0
  37. package/dist/{chunk-R24DI24X.cjs → chunk-5LI5EPGJ.cjs} +6 -5
  38. package/dist/chunk-5LI5EPGJ.cjs.map +1 -0
  39. package/dist/{chunk-BAMZT3GL.js → chunk-5WVP4YHP.js} +939 -134
  40. package/dist/chunk-5WVP4YHP.js.map +1 -0
  41. package/dist/{chunk-MZOVP3WI.cjs → chunk-6KFYJ6TD.cjs} +3 -2
  42. package/dist/chunk-6KFYJ6TD.cjs.map +1 -0
  43. package/dist/{chunk-BXKJLM5R.cjs → chunk-6WFMPTGB.cjs} +972 -636
  44. package/dist/chunk-6WFMPTGB.cjs.map +1 -0
  45. package/dist/{chunk-2MV4HBKC.cjs → chunk-A2N2GFCG.cjs} +10 -10
  46. package/dist/{chunk-2MV4HBKC.cjs.map → chunk-A2N2GFCG.cjs.map} +1 -1
  47. package/dist/chunk-ADBA3XBE.cjs +20 -0
  48. package/dist/chunk-ADBA3XBE.cjs.map +1 -0
  49. package/dist/{chunk-MBNQVDVC.cjs → chunk-AMOJYLG2.cjs} +16 -10
  50. package/dist/chunk-AMOJYLG2.cjs.map +1 -0
  51. package/dist/{chunk-CLVQBF5C.cjs → chunk-AQNHHJMJ.cjs} +5 -5
  52. package/dist/{chunk-CLVQBF5C.cjs.map → chunk-AQNHHJMJ.cjs.map} +1 -1
  53. package/dist/{chunk-AHCLWAM5.cjs → chunk-BHTNFEGZ.cjs} +13 -13
  54. package/dist/chunk-BHTNFEGZ.cjs.map +1 -0
  55. package/dist/{chunk-35IWNZPJ.cjs → chunk-E4NUZXVK.cjs} +58 -27
  56. package/dist/chunk-E4NUZXVK.cjs.map +1 -0
  57. package/dist/{chunk-P33SBYGG.js → chunk-GLG5ZMX7.js} +54 -23
  58. package/dist/chunk-GLG5ZMX7.js.map +1 -0
  59. package/dist/{chunk-BVAR5J2F.js → chunk-GQCOSXMG.js} +117 -6
  60. package/dist/chunk-GQCOSXMG.js.map +1 -0
  61. package/dist/{chunk-QDMPOAI7.cjs → chunk-HDP7VK3C.cjs} +1118 -313
  62. package/dist/chunk-HDP7VK3C.cjs.map +1 -0
  63. package/dist/{chunk-GVWHCL2N.js → chunk-HMOISHXR.js} +217 -75
  64. package/dist/chunk-HMOISHXR.js.map +1 -0
  65. package/dist/{chunk-MTX2KVU7.cjs → chunk-HVQFNJKE.cjs} +122 -90
  66. package/dist/chunk-HVQFNJKE.cjs.map +1 -0
  67. package/dist/{chunk-OC6LTXYS.cjs → chunk-JMXUNXQS.cjs} +126 -7
  68. package/dist/chunk-JMXUNXQS.cjs.map +1 -0
  69. package/dist/{chunk-WWOLFXTX.cjs → chunk-KBSXGXPM.cjs} +10 -7
  70. package/dist/chunk-KBSXGXPM.cjs.map +1 -0
  71. package/dist/{chunk-YU2CUNFO.js → chunk-KV7UW6T6.js} +11 -5
  72. package/dist/chunk-KV7UW6T6.js.map +1 -0
  73. package/dist/{chunk-CCJPSHGI.cjs → chunk-N7FNVFXW.cjs} +4 -12
  74. package/dist/chunk-N7FNVFXW.cjs.map +1 -0
  75. package/dist/{chunk-CYFK5SY2.js → chunk-O3ANBHSA.js} +169 -39
  76. package/dist/chunk-O3ANBHSA.js.map +1 -0
  77. package/dist/{chunk-NZFKROS7.cjs → chunk-PA4VC73I.cjs} +130 -72
  78. package/dist/chunk-PA4VC73I.cjs.map +1 -0
  79. package/dist/{chunk-NJTXJ5AG.cjs → chunk-PFUESQTW.cjs} +18 -18
  80. package/dist/{chunk-NJTXJ5AG.cjs.map → chunk-PFUESQTW.cjs.map} +1 -1
  81. package/dist/{chunk-SFQWJMKT.js → chunk-QY25VWBF.js} +51 -12
  82. package/dist/chunk-QY25VWBF.js.map +1 -0
  83. package/dist/{chunk-WC5FFSHB.js → chunk-R3PY4G7J.js} +3 -3
  84. package/dist/{chunk-WC5FFSHB.js.map → chunk-R3PY4G7J.js.map} +1 -1
  85. package/dist/{chunk-M5E34VG5.js → chunk-SBUFNJVE.js} +3 -3
  86. package/dist/{chunk-M5E34VG5.js.map → chunk-SBUFNJVE.js.map} +1 -1
  87. package/dist/{chunk-UKPGSAZW.js → chunk-TMA4RCEN.js} +3 -3
  88. package/dist/{chunk-UKPGSAZW.js.map → chunk-TMA4RCEN.js.map} +1 -1
  89. package/dist/{chunk-V6HA6JJZ.cjs → chunk-U5VAY32K.cjs} +215 -138
  90. package/dist/chunk-U5VAY32K.cjs.map +1 -0
  91. package/dist/{chunk-DUEZFTK2.js → chunk-UKQHXPGW.js} +4 -12
  92. package/dist/chunk-UKQHXPGW.js.map +1 -0
  93. package/dist/{chunk-4CVLFLOB.cjs → chunk-UM6BVY2S.cjs} +201 -69
  94. package/dist/chunk-UM6BVY2S.cjs.map +1 -0
  95. package/dist/{chunk-75JP4BZX.js → chunk-UQ3UIZJC.js} +3 -2
  96. package/dist/chunk-UQ3UIZJC.js.map +1 -0
  97. package/dist/{chunk-PCPX42KL.js → chunk-V4XG5QF6.js} +16 -10
  98. package/dist/chunk-V4XG5QF6.js.map +1 -0
  99. package/dist/{chunk-GPPLSM2Z.js → chunk-VB37OC6I.js} +6 -5
  100. package/dist/chunk-VB37OC6I.js.map +1 -0
  101. package/dist/{chunk-MVBEL57Q.js → chunk-Y7FT4IQT.js} +500 -170
  102. package/dist/chunk-Y7FT4IQT.js.map +1 -0
  103. package/dist/{chunk-OFXOTECC.js → chunk-YPPPYLSR.js} +7 -7
  104. package/dist/chunk-YPPPYLSR.js.map +1 -0
  105. package/dist/{chunk-M4F66R4O.cjs → chunk-YWQ6V4ZN.cjs} +121 -82
  106. package/dist/chunk-YWQ6V4ZN.cjs.map +1 -0
  107. package/dist/constants.cjs +5 -5
  108. package/dist/constants.d.cts +1 -1
  109. package/dist/constants.d.ts +1 -1
  110. package/dist/constants.js +2 -2
  111. package/dist/engine.cjs +31 -31
  112. package/dist/engine.d.cts +11 -11
  113. package/dist/engine.d.ts +11 -11
  114. package/dist/engine.js +21 -21
  115. package/dist/errors.cjs +19 -19
  116. package/dist/errors.d.cts +2 -2
  117. package/dist/errors.d.ts +2 -2
  118. package/dist/errors.js +1 -1
  119. package/dist/format.cjs +29 -22
  120. package/dist/format.cjs.map +1 -1
  121. package/dist/format.d.cts +1 -2
  122. package/dist/format.d.ts +1 -2
  123. package/dist/format.js +23 -16
  124. package/dist/format.js.map +1 -1
  125. package/dist/index.cjs +31 -31
  126. package/dist/index.d.cts +10 -10
  127. package/dist/index.d.ts +10 -10
  128. package/dist/index.js +22 -22
  129. package/dist/language.cjs +8 -8
  130. package/dist/language.cjs.map +1 -1
  131. package/dist/language.d.cts +10 -10
  132. package/dist/language.d.ts +10 -10
  133. package/dist/language.js +6 -6
  134. package/dist/language.js.map +1 -1
  135. package/dist/lexer.cjs +18 -18
  136. package/dist/lexer.d.cts +2 -2
  137. package/dist/lexer.d.ts +2 -2
  138. package/dist/lexer.js +6 -6
  139. package/dist/normalizer.cjs +12 -12
  140. package/dist/normalizer.js +6 -6
  141. package/dist/packages.cjs +39 -39
  142. package/dist/packages.d.cts +9 -9
  143. package/dist/packages.d.ts +9 -9
  144. package/dist/packages.js +16 -16
  145. package/dist/parser.cjs +15 -15
  146. package/dist/parser.d.cts +23 -9
  147. package/dist/parser.d.ts +23 -9
  148. package/dist/parser.js +5 -5
  149. package/dist/{pipeline-CrsRPmsv.d.ts → pipeline-B6k5lCB7.d.ts} +1 -1
  150. package/dist/{pipeline-DPUQt7yL.d.cts → pipeline-BEb3hujr.d.cts} +1 -1
  151. package/dist/resolvers.d.cts +2 -2
  152. package/dist/resolvers.d.ts +2 -2
  153. package/dist/uom.cjs +17 -17
  154. package/dist/uom.d.cts +2 -2
  155. package/dist/uom.d.ts +2 -2
  156. package/dist/uom.js +7 -7
  157. package/dist/utilities.cjs +8 -4
  158. package/dist/utilities.d.cts +19 -3
  159. package/dist/utilities.d.ts +19 -3
  160. package/dist/utilities.js +2 -2
  161. package/dist/vm.cjs +43 -31
  162. package/dist/vm.d.cts +105 -9
  163. package/dist/vm.d.ts +105 -9
  164. package/dist/vm.js +9 -9
  165. package/package.json +1 -1
  166. package/dist/chunk-2CS6OMZK.js.map +0 -1
  167. package/dist/chunk-35IWNZPJ.cjs.map +0 -1
  168. package/dist/chunk-4AVD7NZW.cjs.map +0 -1
  169. package/dist/chunk-4CVLFLOB.cjs.map +0 -1
  170. package/dist/chunk-6GCKCWLB.js.map +0 -1
  171. package/dist/chunk-6RDSQURE.js.map +0 -1
  172. package/dist/chunk-75JP4BZX.js.map +0 -1
  173. package/dist/chunk-AHCLWAM5.cjs.map +0 -1
  174. package/dist/chunk-BAMZT3GL.js.map +0 -1
  175. package/dist/chunk-BVAR5J2F.js.map +0 -1
  176. package/dist/chunk-BXKJLM5R.cjs.map +0 -1
  177. package/dist/chunk-CCJPSHGI.cjs.map +0 -1
  178. package/dist/chunk-CSG5XVNJ.cjs.map +0 -1
  179. package/dist/chunk-CYFK5SY2.js.map +0 -1
  180. package/dist/chunk-DUEZFTK2.js.map +0 -1
  181. package/dist/chunk-GPPLSM2Z.js.map +0 -1
  182. package/dist/chunk-GVWHCL2N.js.map +0 -1
  183. package/dist/chunk-M4F66R4O.cjs.map +0 -1
  184. package/dist/chunk-M4N5GA5Z.cjs.map +0 -1
  185. package/dist/chunk-MBNQVDVC.cjs.map +0 -1
  186. package/dist/chunk-MEOHSQEH.js.map +0 -1
  187. package/dist/chunk-MTX2KVU7.cjs.map +0 -1
  188. package/dist/chunk-MVBEL57Q.js.map +0 -1
  189. package/dist/chunk-MZOVP3WI.cjs.map +0 -1
  190. package/dist/chunk-N5YFR4UP.cjs +0 -10
  191. package/dist/chunk-N5YFR4UP.cjs.map +0 -1
  192. package/dist/chunk-NZFKROS7.cjs.map +0 -1
  193. package/dist/chunk-OC6LTXYS.cjs.map +0 -1
  194. package/dist/chunk-OFXOTECC.js.map +0 -1
  195. package/dist/chunk-P33SBYGG.js.map +0 -1
  196. package/dist/chunk-P75775WC.js.map +0 -1
  197. package/dist/chunk-PCPX42KL.js.map +0 -1
  198. package/dist/chunk-PFSDGGYL.js +0 -8
  199. package/dist/chunk-PFSDGGYL.js.map +0 -1
  200. package/dist/chunk-QDMPOAI7.cjs.map +0 -1
  201. package/dist/chunk-R24DI24X.cjs.map +0 -1
  202. package/dist/chunk-SFQWJMKT.js.map +0 -1
  203. package/dist/chunk-V6HA6JJZ.cjs.map +0 -1
  204. package/dist/chunk-WWOLFXTX.cjs.map +0 -1
  205. package/dist/chunk-YU2CUNFO.js.map +0 -1
@@ -1,18 +1,10 @@
1
1
  // src/utilities/Number.ts
2
2
  function removeThousandsSeparators(value, locale, decimalPlaces) {
3
- let localeNumber = value.toLocaleString(locale, {
3
+ return value.toLocaleString(locale, {
4
+ useGrouping: false,
4
5
  maximumFractionDigits: decimalPlaces,
5
6
  minimumFractionDigits: decimalPlaces
6
7
  });
7
- switch (locale) {
8
- case "de-DE":
9
- localeNumber = localeNumber.replace(".", "");
10
- break;
11
- default:
12
- localeNumber = localeNumber.replace(",", "");
13
- break;
14
- }
15
- return localeNumber;
16
8
  }
17
9
  function autoFormatIntegerOrFloat(number, decimalPlaces = 2, includeThousandSeparators = false, numberLocale = "en-US") {
18
10
  if (Number.isInteger(number)) {
@@ -34,5 +26,5 @@ function autoFormatIntegerOrFloat(number, decimalPlaces = 2, includeThousandSepa
34
26
  }
35
27
 
36
28
  export { autoFormatIntegerOrFloat };
37
- //# sourceMappingURL=chunk-DUEZFTK2.js.map
38
- //# sourceMappingURL=chunk-DUEZFTK2.js.map
29
+ //# sourceMappingURL=chunk-UKQHXPGW.js.map
30
+ //# sourceMappingURL=chunk-UKQHXPGW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utilities/Number.ts"],"names":[],"mappings":";AAoBA,SAAS,yBAAA,CACR,KAAA,EACA,MAAA,EACA,aAAA,EACC;AACD,EAAA,OAAO,KAAA,CAAM,eAAe,MAAA,EAAQ;AAAA,IACnC,WAAA,EAAa,KAAA;AAAA,IACb,qBAAA,EAAuB,aAAA;AAAA,IACvB,qBAAA,EAAuB;AAAA,GACvB,CAAA;AACF;AAcO,SAAS,yBACf,MAAA,EACA,aAAA,GAAwB,GACxB,yBAAA,GAAqC,KAAA,EACrC,eAAuB,OAAA,EACtB;AACD,EAAA,IAAI,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA,EAAG;AAC7B,IAAA,IAAI,yBAAA,EAA2B;AAE9B,MAAA,OAAO,MAAA,CAAO,eAAe,YAAA,EAAc;AAAA,QAC1C,qBAAA,EAAuB,CAAA;AAAA,QACvB,qBAAA,EAAuB;AAAA,OACvB,CAAA;AAAA,IACF;AAEA,IAAA,OAAO,0BAA0B,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,cAAc,CAAC,CAAA;AAAA,EACrE;AAGA,EAAA,IAAI,yBAAA,EAA2B;AAE9B,IAAA,OAAO,MAAA,CAAO,eAAe,YAAA,EAAc;AAAA,MAC1C,qBAAA,EAAuB,aAAA;AAAA,MACvB,qBAAA,EAAuB;AAAA,KACvB,CAAA;AAAA,EACF;AAIA,EAAA,OAAO,yBAAA,CAA0B,MAAA,EAAQ,YAAA,EAAc,aAAa,CAAA;AACrE","file":"chunk-UKQHXPGW.js","sourcesContent":["/**\n * Render `value` in `locale` with `decimalPlaces` fractional digits and no\n * digit grouping, leaving the locale's own decimal separator alone.\n *\n * Asks `Intl` not to group in the first place rather than formatting with\n * grouping and then deleting a character afterwards. Deleting was wrong twice\n * over. It used `String.replace` with a string pattern, which removes one\n * occurrence, so \"1,234,567\" came back as \"1234,567\" and the surviving comma\n * read as a decimal point. And it chose the character to delete from a\n * two-case switch, \"de-DE\" or a comma for everything else, when a comma is the\n * DECIMAL separator in French, Spanish, Italian, Portuguese and every other\n * comma-decimal locale: deleting it turned 1.5 into \"150\", a hundred times the\n * number, while leaving French's actual group separator (a narrow no-break\n * space) in place. `numberResult.decimalSeparatorLocale` is an unvalidated\n * host string, so no locale can be assumed.\n *\n * An unusable locale tag still throws the `RangeError` `toLocaleString` has\n * always thrown for one, since swallowing it would hide the host's typo behind\n * silently different output.\n */\nfunction removeThousandsSeparators(\n\tvalue: number,\n\tlocale: string,\n\tdecimalPlaces: number\n) {\n\treturn value.toLocaleString(locale, {\n\t\tuseGrouping: false,\n\t\tmaximumFractionDigits: decimalPlaces,\n\t\tminimumFractionDigits: decimalPlaces,\n\t});\n}\n\n/**\n * Format `number` for display, branching on whether it's a whole number:\n * integers are always rendered with zero decimal places (never padded to\n * `decimalPlaces`), while non-integers are rendered with up to\n * `decimalPlaces` fractional digits. `includeThousandSeparators` controls\n * whether groups are separated (e.g. `\"1,234\"`) per `numberLocale`.\n *\n * @param number - The value to format.\n * @param decimalPlaces - Max fractional digits for non-integer values (default 2).\n * @param includeThousandSeparators - Whether to group digits (default false).\n * @param numberLocale - `Intl`/`toLocaleString` locale to format with (default \"en-US\").\n */\nexport function autoFormatIntegerOrFloat(\n\tnumber: number,\n\tdecimalPlaces: number = 2,\n\tincludeThousandSeparators: boolean = false,\n\tnumberLocale: string = \"en-US\"\n) {\n\tif (Number.isInteger(number)) {\n\t\tif (includeThousandSeparators) {\n\t\t\t// We can return the format early as we don't need to strip thousands\n\t\t\treturn number.toLocaleString(numberLocale, {\n\t\t\t\tminimumFractionDigits: 0,\n\t\t\t\tmaximumFractionDigits: 0,\n\t\t\t});\n\t\t}\n\n\t\treturn removeThousandsSeparators(Math.trunc(number), numberLocale, 0);\n\t}\n\n\t// Decimal\n\tif (includeThousandSeparators) {\n\t\t// We can return the format early as we don't need to strip thousands\n\t\treturn number.toLocaleString(numberLocale, {\n\t\t\tmaximumFractionDigits: decimalPlaces,\n\t\t\tminimumFractionDigits: decimalPlaces,\n\t\t});\n\t}\n\n\t// number.toFixed(decimalPlaces)\n\n\treturn removeThousandsSeparators(number, numberLocale, decimalPlaces);\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkOC6LTXYS_cjs = require('./chunk-OC6LTXYS.cjs');
4
- var chunkM4N5GA5Z_cjs = require('./chunk-M4N5GA5Z.cjs');
3
+ var chunkJMXUNXQS_cjs = require('./chunk-JMXUNXQS.cjs');
4
+ var chunk5KMIY374_cjs = require('./chunk-5KMIY374.cjs');
5
5
 
6
6
  // src/symbolic/Rational.ts
7
7
  var RATIONAL_ZERO = { n: 0n, d: 1n };
@@ -33,7 +33,7 @@ function gcd(a, b) {
33
33
  function guardMagnitude(n, d) {
34
34
  const magnitude = n < 0n ? -n : n;
35
35
  if (magnitude >= MAX_MAGNITUDE || d >= MAX_MAGNITUDE) {
36
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution(
36
+ throw chunk5KMIY374_cjs.ErrorFactory.execution(
37
37
  "SYMBOLIC_RATIONAL_OVERFLOW",
38
38
  `This calculation produced a fraction too large to represent exactly (over ${RATIONAL_MAX_BITS} bits).`,
39
39
  { limitBits: RATIONAL_MAX_BITS }
@@ -42,7 +42,7 @@ function guardMagnitude(n, d) {
42
42
  }
43
43
  function normalize(n, d) {
44
44
  if (d === 0n) {
45
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
45
+ throw chunk5KMIY374_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
46
46
  }
47
47
  if (n === 0n) return RATIONAL_ZERO;
48
48
  let numerator = d < 0n ? -n : n;
@@ -59,7 +59,7 @@ function rational(numerator, denominator = 1n) {
59
59
  var DECIMAL_FORM = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
60
60
  function rationalFromNumber(value) {
61
61
  if (!Number.isFinite(value)) {
62
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution(
62
+ throw chunk5KMIY374_cjs.ErrorFactory.execution(
63
63
  "SYMBOLIC_NONFINITE_OPERAND",
64
64
  `"${String(value)}" has no exact value, so it cannot appear in a symbolic expression.`,
65
65
  { value: String(value) }
@@ -68,7 +68,7 @@ function rationalFromNumber(value) {
68
68
  if (Number.isInteger(value)) return normalize(BigInt(value), 1n);
69
69
  const parts = DECIMAL_FORM.exec(String(value));
70
70
  if (parts === null) {
71
- throw chunkM4N5GA5Z_cjs.ErrorFactory.internal(
71
+ throw chunk5KMIY374_cjs.ErrorFactory.internal(
72
72
  "INTERNAL_RATIONAL_PARSE",
73
73
  `Internal error: could not read "${String(value)}" as a decimal number.`,
74
74
  { value: String(value) }
@@ -100,7 +100,7 @@ function rationalMul(a, b) {
100
100
  }
101
101
  function rationalDiv(a, b) {
102
102
  if (b.n === 0n) {
103
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
103
+ throw chunk5KMIY374_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
104
104
  }
105
105
  return normalize(a.n * b.d, a.d * b.n);
106
106
  }
@@ -111,7 +111,7 @@ function rationalPow(base, exponent) {
111
111
  if (exponent === 0n) return RATIONAL_ONE;
112
112
  if (exponent < 0n) {
113
113
  if (base.n === 0n) {
114
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
114
+ throw chunk5KMIY374_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
115
115
  }
116
116
  const positive = -exponent;
117
117
  return normalize(bigintPow(base.d, positive), bigintPow(base.n, positive));
@@ -191,7 +191,7 @@ function complexMul(a, b) {
191
191
  }
192
192
  function complexDiv(a, b) {
193
193
  if (isComplexZero(b)) {
194
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a complex expression.");
194
+ throw chunk5KMIY374_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a complex expression.");
195
195
  }
196
196
  const denominator = rationalAdd(rationalMul(b.re, b.re), rationalMul(b.im, b.im));
197
197
  return {
@@ -212,7 +212,7 @@ function complexPow(base, exponent) {
212
212
  if (exponent === 0n) return COMPLEX_ONE;
213
213
  if (exponent < 0n) {
214
214
  if (isComplexZero(base)) {
215
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
215
+ throw chunk5KMIY374_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
216
216
  }
217
217
  return complexDiv(COMPLEX_ONE, complexPow(base, -exponent));
218
218
  }
@@ -734,6 +734,17 @@ function divideOutConstant(numerator, denominator, original) {
734
734
  }
735
735
  return { kind: "div", left: fromPolynomial(numerator), right: fromPolynomial(denominator) };
736
736
  }
737
+ function squareFreePart(coefficients) {
738
+ const trimmed = trim([...coefficients]);
739
+ if (trimmed.length <= 1) return monic(trimmed);
740
+ const derivative = [];
741
+ for (let power = 1; power < trimmed.length; power++) {
742
+ derivative.push(rationalMul(trimmed[power], { n: BigInt(power), d: 1n }));
743
+ }
744
+ const shared = coefficientGcd(trimmed, derivative);
745
+ if (shared.length <= 1) return monic(trimmed);
746
+ return monic(polynomialDivide(trimmed, shared).quotient);
747
+ }
737
748
 
738
749
  // src/symbolic/Radicals.ts
739
750
  function exactIntegerSqrt(value) {
@@ -789,14 +800,15 @@ function signedSurdNode(value) {
789
800
  }
790
801
 
791
802
  // src/symbolic/Simplify.ts
792
- function flattenSum(node, negated, out) {
803
+ function flattenSum(node, negated, out, depth = 0) {
804
+ if (depth >= MAX_SIMPLIFY_DEPTH) return false;
793
805
  switch (node.kind) {
794
806
  case "add":
795
- return flattenSum(node.left, negated, out) && flattenSum(node.right, negated, out);
807
+ return flattenSum(node.left, negated, out, depth + 1) && flattenSum(node.right, negated, out, depth + 1);
796
808
  case "sub":
797
- return flattenSum(node.left, negated, out) && flattenSum(node.right, !negated, out);
809
+ return flattenSum(node.left, negated, out, depth + 1) && flattenSum(node.right, !negated, out, depth + 1);
798
810
  case "neg":
799
- return flattenSum(node.operand, !negated, out);
811
+ return flattenSum(node.operand, !negated, out, depth + 1);
800
812
  case "const":
801
813
  out.push({ coeff: negated ? rationalNeg(node.value) : node.value, name: null });
802
814
  return true;
@@ -913,13 +925,27 @@ function foldCall(name, args) {
913
925
  }
914
926
  function simplifySymbolic(node) {
915
927
  if (nodeCount(node, SYMBOLIC_MAX_NODES) > SYMBOLIC_MAX_NODES) {
916
- throw chunkM4N5GA5Z_cjs.ErrorFactory.execution(
928
+ throw chunk5KMIY374_cjs.ErrorFactory.execution(
917
929
  "SYMBOLIC_NODE_LIMIT_EXCEEDED",
918
930
  `This symbolic expression is too large to simplify (over ${SYMBOLIC_MAX_NODES} terms).`,
919
931
  { limit: SYMBOLIC_MAX_NODES }
920
932
  );
921
933
  }
922
- return simplifyNode(node);
934
+ const depthOnEntry = walkDepth;
935
+ try {
936
+ return simplifyNode(node);
937
+ } finally {
938
+ walkDepth = depthOnEntry;
939
+ }
940
+ }
941
+ var MAX_SIMPLIFY_DEPTH = 900;
942
+ var walkDepth = 0;
943
+ function simplifyNode(node) {
944
+ if (walkDepth >= MAX_SIMPLIFY_DEPTH) return node;
945
+ walkDepth++;
946
+ const simplified = simplifyNodeAt(node);
947
+ walkDepth--;
948
+ return simplified;
923
949
  }
924
950
  function asComplex(node) {
925
951
  if (node.kind === "complex") return node.value;
@@ -974,7 +1000,7 @@ function foldComplexCall(name, args) {
974
1000
  return null;
975
1001
  }
976
1002
  }
977
- function simplifyNode(node) {
1003
+ function simplifyNodeAt(node) {
978
1004
  switch (node.kind) {
979
1005
  case "const":
980
1006
  case "complex":
@@ -1118,7 +1144,10 @@ function formatCoefficient(coeff, text) {
1118
1144
  if (coeff.n === -1n && coeff.d === 1n) return `-${text}`;
1119
1145
  return `${formatRational(coeff)}${text}`;
1120
1146
  }
1121
- function formatFactor(node) {
1147
+ var MAX_FORMAT_DEPTH = 600;
1148
+ var ELIDED = "...";
1149
+ function formatFactor(node, depth) {
1150
+ if (depth >= MAX_FORMAT_DEPTH) return ELIDED;
1122
1151
  switch (node.kind) {
1123
1152
  case "const":
1124
1153
  return formatRational(node.value);
@@ -1128,43 +1157,50 @@ function formatFactor(node) {
1128
1157
  return node.name;
1129
1158
  case "add":
1130
1159
  case "sub":
1131
- return `(${formatSymbolic(node)})`;
1160
+ return `(${formatSum(node, depth)})`;
1132
1161
  case "neg":
1133
- return `-${formatFactor(node.operand)}`;
1162
+ return `-${formatFactor(node.operand, depth + 1)}`;
1134
1163
  case "call":
1135
- return `${node.name}(${node.args.map(formatSymbolic).join(", ")})`;
1164
+ return `${node.name}(${node.args.map((arg) => formatSum(arg, depth + 1)).join(", ")})`;
1136
1165
  case "pow": {
1137
- const base = isAtomic(node.base) ? formatFactor(node.base) : `(${formatSymbolic(node.base)})`;
1138
- const exponent = isAtomic(node.exponent) ? formatFactor(node.exponent) : `(${formatSymbolic(node.exponent)})`;
1166
+ const base = isAtomic(node.base) ? formatFactor(node.base, depth + 1) : `(${formatSum(node.base, depth + 1)})`;
1167
+ const exponent = isAtomic(node.exponent) ? formatFactor(node.exponent, depth + 1) : `(${formatSum(node.exponent, depth + 1)})`;
1139
1168
  return `${base}^${exponent}`;
1140
1169
  }
1141
1170
  case "mul": {
1142
1171
  const coeffVar = tryExtractCoeffVar(node);
1143
1172
  if (coeffVar) return formatCoefficient(coeffVar.coeff, coeffVar.name);
1144
1173
  const coeffPow = tryExtractCoeffPow(node);
1145
- if (coeffPow) return formatCoefficient(coeffPow.coeff, formatFactor(coeffPow.power));
1174
+ if (coeffPow) return formatCoefficient(coeffPow.coeff, formatFactor(coeffPow.power, depth + 1));
1146
1175
  if (node.left.kind === "const" && node.right.kind === "mul") {
1147
- const inner = formatFactor(node.right);
1176
+ const inner = formatFactor(node.right, depth + 1);
1148
1177
  if (!/^[\d.]/.test(inner)) return formatCoefficient(node.left.value, inner);
1149
1178
  }
1150
- return `${formatFactor(node.left)}*${formatFactor(node.right)}`;
1179
+ return `${formatFactor(node.left, depth + 1)}*${formatFactor(node.right, depth + 1)}`;
1180
+ }
1181
+ case "div": {
1182
+ const denominator = formatFactor(node.right, depth + 1);
1183
+ const needsBrackets = node.right.kind === "mul" || node.right.kind === "div";
1184
+ return `${formatFactor(node.left, depth + 1)}/${needsBrackets ? `(${denominator})` : denominator}`;
1151
1185
  }
1152
- case "div":
1153
- return `${formatFactor(node.left)}/${formatFactor(node.right)}`;
1154
1186
  }
1155
1187
  }
1156
- function collectDisplayTerms(node, negated, out) {
1188
+ function collectDisplayTerms(node, negated, out, depth) {
1189
+ if (depth >= MAX_FORMAT_DEPTH) {
1190
+ out.push({ negated, text: ELIDED });
1191
+ return;
1192
+ }
1157
1193
  switch (node.kind) {
1158
1194
  case "add":
1159
- collectDisplayTerms(node.left, negated, out);
1160
- collectDisplayTerms(node.right, negated, out);
1195
+ collectDisplayTerms(node.left, negated, out, depth + 1);
1196
+ collectDisplayTerms(node.right, negated, out, depth + 1);
1161
1197
  return;
1162
1198
  case "sub":
1163
- collectDisplayTerms(node.left, negated, out);
1164
- collectDisplayTerms(node.right, !negated, out);
1199
+ collectDisplayTerms(node.left, negated, out, depth + 1);
1200
+ collectDisplayTerms(node.right, !negated, out, depth + 1);
1165
1201
  return;
1166
1202
  case "neg":
1167
- collectDisplayTerms(node.operand, !negated, out);
1203
+ collectDisplayTerms(node.operand, !negated, out, depth + 1);
1168
1204
  return;
1169
1205
  case "const": {
1170
1206
  if (node.value.n === 0n) return;
@@ -1188,7 +1224,7 @@ function collectDisplayTerms(node, negated, out) {
1188
1224
  return;
1189
1225
  }
1190
1226
  default: {
1191
- const text = formatFactor(node);
1227
+ const text = formatFactor(node, depth);
1192
1228
  const liftsSign = (node.kind === "mul" || node.kind === "div") && text.startsWith("-");
1193
1229
  if (liftsSign) out.push({ negated: !negated, text: text.slice(1) });
1194
1230
  else out.push({ negated, text });
@@ -1196,8 +1232,16 @@ function collectDisplayTerms(node, negated, out) {
1196
1232
  }
1197
1233
  }
1198
1234
  function formatSymbolic(node) {
1235
+ try {
1236
+ return formatSum(node, 0);
1237
+ } catch (thrown) {
1238
+ if (thrown instanceof RangeError) return ELIDED;
1239
+ throw thrown;
1240
+ }
1241
+ }
1242
+ function formatSum(node, depth) {
1199
1243
  const terms = [];
1200
- collectDisplayTerms(node, false, terms);
1244
+ collectDisplayTerms(node, false, terms, depth);
1201
1245
  if (terms.length === 0) return "0";
1202
1246
  let out = "";
1203
1247
  terms.forEach((term, index) => {
@@ -1233,9 +1277,9 @@ function symbolicToEntry(node) {
1233
1277
  return simplified.kind === "const" ? rationalToNumber(simplified.value) : simplified;
1234
1278
  }
1235
1279
  function matrixEntryToValue(cell) {
1236
- if (typeof cell === "boolean") return chunkOC6LTXYS_cjs.boolValue(cell);
1237
- if (typeof cell === "object" && cell !== null) return chunkOC6LTXYS_cjs.symbolicValue(cell);
1238
- return chunkOC6LTXYS_cjs.numberValue(cell);
1280
+ if (typeof cell === "boolean") return chunkJMXUNXQS_cjs.boolValue(cell);
1281
+ if (typeof cell === "object" && cell !== null) return chunkJMXUNXQS_cjs.symbolicValue(cell);
1282
+ return chunkJMXUNXQS_cjs.numberValue(cell);
1239
1283
  }
1240
1284
  function rowMajorToColumnMajor(rows, cols, rowMajorData) {
1241
1285
  const data = new Array(rows * cols);
@@ -1264,21 +1308,21 @@ function matrixMultiply(l, r) {
1264
1308
  if (useSymbolic) {
1265
1309
  const scalarNode = entryToSymbolic(scalarOperand.data[0]);
1266
1310
  const result2 = matrixOperand.data.map((v) => symbolicToEntry(simplifySymbolic({ kind: "mul", left: entryToSymbolic(v), right: scalarNode })));
1267
- return chunkOC6LTXYS_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result2);
1311
+ return chunkJMXUNXQS_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result2);
1268
1312
  }
1269
1313
  const scalar = scalarOperand.data[0];
1270
1314
  const result = matrixOperand.data.map((v) => v * scalar);
1271
- return chunkOC6LTXYS_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result);
1315
+ return chunkJMXUNXQS_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result);
1272
1316
  }
1273
1317
  if (l.cols !== r.rows) {
1274
- return chunkOC6LTXYS_cjs.errorValue(
1318
+ return chunkJMXUNXQS_cjs.errorValue(
1275
1319
  "DIMENSION_MISMATCH",
1276
1320
  `Cannot multiply a ${l.rows}x${l.cols} matrix by a ${r.rows}x${r.cols} matrix \u2014 inner dimensions must match (${l.cols} !== ${r.rows}).`
1277
1321
  );
1278
1322
  }
1279
1323
  const resultRows = l.rows;
1280
1324
  const resultCols = r.cols;
1281
- const data = new Array(resultRows * resultCols);
1325
+ const data = chunkJMXUNXQS_cjs.checkedArray(resultRows * resultCols, "matrix cells");
1282
1326
  for (let row = 0; row < resultRows; row++) {
1283
1327
  for (let col = 0; col < resultCols; col++) {
1284
1328
  if (useSymbolic) {
@@ -1297,18 +1341,49 @@ function matrixMultiply(l, r) {
1297
1341
  }
1298
1342
  }
1299
1343
  }
1300
- return chunkOC6LTXYS_cjs.matrixValue(resultRows, resultCols, data);
1344
+ return chunkJMXUNXQS_cjs.matrixValue(resultRows, resultCols, data);
1345
+ }
1346
+ function matrixPower(m, exponent) {
1347
+ if (!isSquare(m)) {
1348
+ return chunkJMXUNXQS_cjs.errorValue("MATRIX_POWER_REQUIRES_SQUARE_MATRIX", `^: only a square matrix can be raised to a power (got ${m.rows}x${m.cols}).`);
1349
+ }
1350
+ if (!Number.isInteger(exponent) || exponent < 0) {
1351
+ return chunkJMXUNXQS_cjs.errorValue(
1352
+ "MATRIX_POWER_REQUIRES_WHOLE_EXPONENT",
1353
+ `^: a matrix can only be raised to a whole number of 0 or more (got ${exponent}); "^-1" means the inverse and "^T" the transpose.`
1354
+ );
1355
+ }
1356
+ const n = m.rows;
1357
+ const identity = new Array(n * n).fill(0);
1358
+ for (let i = 0; i < n; i++) identity[i + i * n] = 1;
1359
+ let accumulated = { rows: n, cols: n, data: identity, hasSymbolic: false };
1360
+ let squared = m;
1361
+ let remaining = exponent;
1362
+ while (remaining > 0) {
1363
+ if (remaining % 2 === 1) {
1364
+ const product = matrixMultiply(accumulated, squared);
1365
+ if (product.type === 13 /* Error */) return product;
1366
+ accumulated = product.value;
1367
+ }
1368
+ remaining = Math.floor(remaining / 2);
1369
+ if (remaining > 0) {
1370
+ const doubled = matrixMultiply(squared, squared);
1371
+ if (doubled.type === 13 /* Error */) return doubled;
1372
+ squared = doubled.value;
1373
+ }
1374
+ }
1375
+ return chunkJMXUNXQS_cjs.matrixValue(accumulated.rows, accumulated.cols, accumulated.data);
1301
1376
  }
1302
1377
  function matrixCompare(l, r, cmp) {
1303
1378
  if (!sameShape(l, r)) {
1304
- return chunkOC6LTXYS_cjs.errorValue(
1379
+ return chunkJMXUNXQS_cjs.errorValue(
1305
1380
  "DIMENSION_MISMATCH",
1306
1381
  `Cannot compare matrices of different shapes: ${l.rows}x${l.cols} and ${r.rows}x${r.cols}`
1307
1382
  );
1308
1383
  }
1309
1384
  const data = new Array(l.data.length);
1310
1385
  for (let i = 0; i < l.data.length; i++) data[i] = cmp(l.data[i], r.data[i]);
1311
- return chunkOC6LTXYS_cjs.matrixValue(l.rows, l.cols, data);
1386
+ return chunkJMXUNXQS_cjs.matrixValue(l.rows, l.cols, data);
1312
1387
  }
1313
1388
  function transpose(m) {
1314
1389
  const data = new Array(m.rows * m.cols);
@@ -1317,7 +1392,7 @@ function transpose(m) {
1317
1392
  data[r + c * m.cols] = matAt(m, c, r);
1318
1393
  }
1319
1394
  }
1320
- return chunkOC6LTXYS_cjs.matrixValue(m.cols, m.rows, data);
1395
+ return chunkJMXUNXQS_cjs.matrixValue(m.cols, m.rows, data);
1321
1396
  }
1322
1397
  function toWorkingRows(m) {
1323
1398
  const rows = [];
@@ -1328,7 +1403,52 @@ function toWorkingRows(m) {
1328
1403
  }
1329
1404
  return rows;
1330
1405
  }
1406
+ var EXACT_DETERMINANT_DIMENSION_LIMIT = 12;
1407
+ function toIntegerRows(m) {
1408
+ if (m.rows > EXACT_DETERMINANT_DIMENSION_LIMIT) return null;
1409
+ const rows = [];
1410
+ for (let r = 0; r < m.rows; r++) {
1411
+ const row = [];
1412
+ for (let c = 0; c < m.cols; c++) {
1413
+ const cell = matAt(m, r, c);
1414
+ if (typeof cell !== "number" || !Number.isSafeInteger(cell)) return null;
1415
+ row.push(BigInt(cell));
1416
+ }
1417
+ rows.push(row);
1418
+ }
1419
+ return rows;
1420
+ }
1421
+ function integerDeterminant(rows) {
1422
+ const n = rows.length;
1423
+ let previous = 1n;
1424
+ let sign = 1n;
1425
+ for (let k = 0; k < n - 1; k++) {
1426
+ if (rows[k][k] === 0n) {
1427
+ let candidate = -1;
1428
+ for (let r = k + 1; r < n; r++) {
1429
+ if (rows[r][k] !== 0n) {
1430
+ candidate = r;
1431
+ break;
1432
+ }
1433
+ }
1434
+ if (candidate === -1) return 0n;
1435
+ const swapped = rows[k];
1436
+ rows[k] = rows[candidate];
1437
+ rows[candidate] = swapped;
1438
+ sign = -sign;
1439
+ }
1440
+ for (let i = k + 1; i < n; i++) {
1441
+ for (let j = k + 1; j < n; j++) {
1442
+ rows[i][j] = (rows[i][j] * rows[k][k] - rows[i][k] * rows[k][j]) / previous;
1443
+ }
1444
+ }
1445
+ previous = rows[k][k];
1446
+ }
1447
+ return sign * rows[n - 1][n - 1];
1448
+ }
1331
1449
  function numericDeterminant(m) {
1450
+ const integers = toIntegerRows(m);
1451
+ if (integers !== null) return chunkJMXUNXQS_cjs.numberValue(Number(integerDeterminant(integers)));
1332
1452
  const n = m.rows;
1333
1453
  const a = toWorkingRows(m);
1334
1454
  let det = 1;
@@ -1341,7 +1461,7 @@ function numericDeterminant(m) {
1341
1461
  pivotRow = r;
1342
1462
  }
1343
1463
  }
1344
- if (maxAbs === 0) return chunkOC6LTXYS_cjs.numberValue(0);
1464
+ if (maxAbs === 0) return chunkJMXUNXQS_cjs.numberValue(0);
1345
1465
  if (pivotRow !== col) {
1346
1466
  const tmp = a[col];
1347
1467
  a[col] = a[pivotRow];
@@ -1355,7 +1475,7 @@ function numericDeterminant(m) {
1355
1475
  for (let c = col; c < n; c++) a[r][c] -= factor * a[col][c];
1356
1476
  }
1357
1477
  }
1358
- return chunkOC6LTXYS_cjs.numberValue(det);
1478
+ return chunkJMXUNXQS_cjs.numberValue(det);
1359
1479
  }
1360
1480
  function symbolicDeterminant(m) {
1361
1481
  const n = m.rows;
@@ -1368,7 +1488,7 @@ function symbolicDeterminant(m) {
1368
1488
  let det = constNode(1);
1369
1489
  for (let col = 0; col < n; col++) {
1370
1490
  const pivot = simplifySymbolic(a[col][col]);
1371
- if (pivot.kind === "const" && isRationalZero(pivot.value)) return chunkOC6LTXYS_cjs.numberValue(0);
1491
+ if (pivot.kind === "const" && isRationalZero(pivot.value)) return chunkJMXUNXQS_cjs.numberValue(0);
1372
1492
  det = simplifySymbolic({ kind: "mul", left: det, right: pivot });
1373
1493
  for (let r = col + 1; r < n; r++) {
1374
1494
  const factor = simplifySymbolic({ kind: "div", left: a[r][col], right: pivot });
@@ -1377,11 +1497,11 @@ function symbolicDeterminant(m) {
1377
1497
  }
1378
1498
  }
1379
1499
  }
1380
- return det.kind === "const" ? chunkOC6LTXYS_cjs.numberValue(rationalToNumber(det.value)) : chunkOC6LTXYS_cjs.symbolicValue(det);
1500
+ return det.kind === "const" ? chunkJMXUNXQS_cjs.numberValue(rationalToNumber(det.value)) : chunkJMXUNXQS_cjs.symbolicValue(det);
1381
1501
  }
1382
1502
  function determinant(m) {
1383
1503
  if (!isSquare(m)) {
1384
- return chunkOC6LTXYS_cjs.errorValue("DETERMINANT_REQUIRES_SQUARE_MATRIX", `det: matrix must be square (got ${m.rows}x${m.cols}).`);
1504
+ return chunkJMXUNXQS_cjs.errorValue("DETERMINANT_REQUIRES_SQUARE_MATRIX", `det: matrix must be square (got ${m.rows}x${m.cols}).`);
1385
1505
  }
1386
1506
  return m.hasSymbolic ? symbolicDeterminant(m) : numericDeterminant(m);
1387
1507
  }
@@ -1401,7 +1521,7 @@ function numericInverse(m) {
1401
1521
  }
1402
1522
  }
1403
1523
  if (maxAbs < 1e-10) {
1404
- return chunkOC6LTXYS_cjs.errorValue("SINGULAR_MATRIX", `inv: a ${n}x${n} matrix with a zero (or near-zero) pivot column is not invertible.`);
1524
+ return chunkJMXUNXQS_cjs.errorValue("SINGULAR_MATRIX", `inv: a ${n}x${n} matrix with a zero (or near-zero) pivot column is not invertible.`);
1405
1525
  }
1406
1526
  if (pivotRow !== col) {
1407
1527
  const tmp = a[col];
@@ -1421,13 +1541,13 @@ function numericInverse(m) {
1421
1541
  for (let r = 0; r < n; r++) {
1422
1542
  for (let c = 0; c < n; c++) data[r + c * n] = a[r][n + c];
1423
1543
  }
1424
- return chunkOC6LTXYS_cjs.matrixValue(n, n, data);
1544
+ return chunkJMXUNXQS_cjs.matrixValue(n, n, data);
1425
1545
  }
1426
1546
  var SYMBOLIC_INVERSE_DIMENSION_LIMIT = 9;
1427
1547
  function symbolicInverse(m) {
1428
1548
  const n = m.rows;
1429
1549
  if (n >= SYMBOLIC_INVERSE_DIMENSION_LIMIT) {
1430
- return chunkOC6LTXYS_cjs.errorValue(
1550
+ return chunkJMXUNXQS_cjs.errorValue(
1431
1551
  "SYMBOLIC_INVERSE_DIMENSION_LIMIT",
1432
1552
  `Symbolic matrix inversion is limited to matrices smaller than ${SYMBOLIC_INVERSE_DIMENSION_LIMIT}x${SYMBOLIC_INVERSE_DIMENSION_LIMIT} (got ${n}x${n}).`
1433
1553
  );
@@ -1442,48 +1562,58 @@ function symbolicInverse(m) {
1442
1562
  for (let col = 0; col < n; col++) {
1443
1563
  const pivot = simplifySymbolic(a[col][col]);
1444
1564
  if (pivot.kind === "const" && isRationalZero(pivot.value)) {
1445
- return chunkOC6LTXYS_cjs.errorValue(
1565
+ return chunkJMXUNXQS_cjs.errorValue(
1446
1566
  "SYMBOLIC_SINGULAR_OR_UNSUPPORTED_PIVOT",
1447
1567
  `Symbolic inverse: the pivot at row/col ${col} is exactly zero \u2014 this matrix's structure isn't invertible via this engine's diagonal-first symbolic elimination (no row-swapping); try reordering rows manually.`
1448
1568
  );
1449
1569
  }
1450
- for (let c = 0; c < 2 * n; c++) {
1451
- a[col][c] = simplifySymbolic({ kind: "div", left: a[col][c], right: pivot });
1452
- }
1453
1570
  for (let r = 0; r < n; r++) {
1454
1571
  if (r === col) continue;
1455
- const factor = simplifySymbolic(a[r][col]);
1572
+ const factor = simplifySymbolic({ kind: "div", left: a[r][col], right: pivot });
1456
1573
  if (factor.kind === "const" && isRationalZero(factor.value)) continue;
1457
1574
  for (let c = 0; c < 2 * n; c++) {
1458
1575
  a[r][c] = simplifySymbolic({ kind: "sub", left: a[r][c], right: { kind: "mul", left: factor, right: a[col][c] } });
1459
1576
  }
1460
1577
  }
1578
+ for (let c = 0; c < 2 * n; c++) {
1579
+ a[col][c] = simplifySymbolic({ kind: "div", left: a[col][c], right: pivot });
1580
+ }
1461
1581
  }
1462
1582
  const data = new Array(n * n);
1463
1583
  for (let r = 0; r < n; r++) {
1464
1584
  for (let c = 0; c < n; c++) data[r + c * n] = symbolicToEntry(a[r][n + c]);
1465
1585
  }
1466
- return chunkOC6LTXYS_cjs.matrixValue(n, n, data);
1586
+ return chunkJMXUNXQS_cjs.matrixValue(n, n, data);
1467
1587
  }
1468
1588
  function inverse(m) {
1469
1589
  if (!isSquare(m)) {
1470
- return chunkOC6LTXYS_cjs.errorValue("INVERSE_REQUIRES_SQUARE_MATRIX", `inv: matrix must be square (got ${m.rows}x${m.cols}).`);
1590
+ return chunkJMXUNXQS_cjs.errorValue("INVERSE_REQUIRES_SQUARE_MATRIX", `inv: matrix must be square (got ${m.rows}x${m.cols}).`);
1471
1591
  }
1472
1592
  return m.hasSymbolic ? symbolicInverse(m) : numericInverse(m);
1473
1593
  }
1474
- function collectionToValues(v) {
1475
- if (v.type === 13 /* Error */) return v;
1594
+ function tooLarge(length, maxElements) {
1595
+ return chunkJMXUNXQS_cjs.errorValue(
1596
+ "COLLECTION_TOO_LARGE",
1597
+ `This collection has ${length} elements, past the limit of ${maxElements} (see the engine's vm.maxCollectionSize setting).`
1598
+ );
1599
+ }
1600
+ function collectionToValues(v, maxElements = Number.POSITIVE_INFINITY) {
1601
+ const faulted = chunkJMXUNXQS_cjs.faultedOperand(v);
1602
+ if (faulted) return faulted;
1476
1603
  if (v.type === 7 /* Matrix */) {
1477
1604
  const m = v.value;
1605
+ if (m.data.length > maxElements) return tooLarge(m.data.length, maxElements);
1478
1606
  return m.data.map(matrixEntryToValue);
1479
1607
  }
1480
1608
  if (v.type === 8 /* Range */) {
1481
1609
  const r = v.value;
1482
- const out = [];
1483
- for (let i = r.min; i <= r.max; i++) out.push(chunkOC6LTXYS_cjs.numberValue(i));
1610
+ const length = r.max - r.min + 1;
1611
+ if (length > maxElements) return tooLarge(length, maxElements);
1612
+ const out = new Array(length);
1613
+ for (let i = 0; i < length; i++) out[i] = chunkJMXUNXQS_cjs.numberValue(r.min + i);
1484
1614
  return out;
1485
1615
  }
1486
- return chunkOC6LTXYS_cjs.errorValue(
1616
+ return chunkJMXUNXQS_cjs.errorValue(
1487
1617
  "MAP_REDUCE_REQUIRES_COLLECTION",
1488
1618
  `map/reduce requires a Matrix or Range collection (e.g. "[1,2,3]" or "0:3").`
1489
1619
  );
@@ -1628,6 +1758,7 @@ exports.matIndex = matIndex;
1628
1758
  exports.matrixCompare = matrixCompare;
1629
1759
  exports.matrixEntryToValue = matrixEntryToValue;
1630
1760
  exports.matrixMultiply = matrixMultiply;
1761
+ exports.matrixPower = matrixPower;
1631
1762
  exports.monomialFromKey = monomialFromKey;
1632
1763
  exports.monomialToKey = monomialToKey;
1633
1764
  exports.polyCoefficients = polyCoefficients;
@@ -1648,6 +1779,7 @@ exports.rowMajorToColumnMajor = rowMajorToColumnMajor;
1648
1779
  exports.sameShape = sameShape;
1649
1780
  exports.signedSurdNode = signedSurdNode;
1650
1781
  exports.simplifySymbolic = simplifySymbolic;
1782
+ exports.squareFreePart = squareFreePart;
1651
1783
  exports.substitute = substitute;
1652
1784
  exports.surdNode = surdNode;
1653
1785
  exports.symbolicKey = symbolicKey;
@@ -1655,5 +1787,5 @@ exports.symbolicToEntry = symbolicToEntry;
1655
1787
  exports.toPolynomial = toPolynomial;
1656
1788
  exports.transpose = transpose;
1657
1789
  exports.varNode = varNode;
1658
- //# sourceMappingURL=chunk-4CVLFLOB.cjs.map
1659
- //# sourceMappingURL=chunk-4CVLFLOB.cjs.map
1790
+ //# sourceMappingURL=chunk-UM6BVY2S.cjs.map
1791
+ //# sourceMappingURL=chunk-UM6BVY2S.cjs.map