solve-engine 1.2.0 → 2.1.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 (385) hide show
  1. package/README.md +12 -17
  2. package/dist/{BytecodeBuilder-Bp9xeTmX.d.cts → BytecodeBuilder-DGGeByAP.d.cts} +18 -0
  3. package/dist/{BytecodeBuilder-Bp9xeTmX.d.ts → BytecodeBuilder-DGGeByAP.d.ts} +18 -0
  4. package/dist/{Configuration-C9W8tJv_.d.cts → Configuration-B6W0-T67.d.cts} +17 -4
  5. package/dist/{Configuration-C9W8tJv_.d.ts → Configuration-B6W0-T67.d.ts} +17 -4
  6. package/dist/{EngineError-CNA_rHY-.d.cts → EngineError-Ce1lPkjZ.d.cts} +2 -0
  7. package/dist/{EngineError-CNA_rHY-.d.ts → EngineError-Ce1lPkjZ.d.ts} +2 -0
  8. package/dist/{PackageCompatibility-B6NX9IaN.d.cts → PackageCompatibility-Bn5jnBtA.d.cts} +2 -2
  9. package/dist/{PackageCompatibility-Ceg5XdAp.d.ts → PackageCompatibility-CIvq2MP5.d.ts} +2 -2
  10. package/dist/{PackageRegistry-DrCPQNyy.d.ts → PackageRegistry-DzeiWcv4.d.ts} +93 -172
  11. package/dist/{PackageRegistry-DnJYVw9G.d.cts → PackageRegistry-dpdurBVO.d.cts} +93 -172
  12. package/dist/{Parselet-Bhf7d0_W.d.ts → Parselet-B-zoPrTa.d.ts} +8 -5
  13. package/dist/{Parselet-Cv7S7KRt.d.cts → Parselet-C4Wu055_.d.cts} +8 -5
  14. package/dist/{ScopeManager-Bzq87GfA.d.ts → ScopeManager-C2LDOrDx.d.ts} +7 -16
  15. package/dist/{ScopeManager-DRDBVfan.d.cts → ScopeManager-D7uMXbhS.d.cts} +7 -16
  16. package/dist/{VMCheckpoints-C6c17Hbo.d.ts → VMCheckpoints-CGyFhivM.d.ts} +3 -3
  17. package/dist/{VMCheckpoints-dZxSMGHG.d.cts → VMCheckpoints-I9jg3jWR.d.cts} +3 -3
  18. package/dist/{Value-DZNQ_PU7.d.cts → Value-CCi_Eecs.d.cts} +40 -0
  19. package/dist/{Value-DZNQ_PU7.d.ts → Value-CCi_Eecs.d.ts} +40 -0
  20. package/dist/{WorkerError-Djd7GGGa.d.cts → WorkerError-B4p6PNfx.d.cts} +1 -1
  21. package/dist/{WorkerError-B7t7R2-m.d.ts → WorkerError-Dhj9BQ_A.d.ts} +1 -1
  22. package/dist/chunk-2JMFUQZH.js +2 -0
  23. package/dist/chunk-2JMFUQZH.js.map +1 -0
  24. package/dist/chunk-2LFLR3VZ.cjs +2 -0
  25. package/dist/chunk-2LFLR3VZ.cjs.map +1 -0
  26. package/dist/chunk-2RWAXT6O.js +0 -1
  27. package/dist/chunk-32GC2FHC.cjs +2 -0
  28. package/dist/chunk-32GC2FHC.cjs.map +1 -0
  29. package/dist/chunk-4BZIYU7S.cjs +3 -0
  30. package/dist/chunk-4BZIYU7S.cjs.map +1 -0
  31. package/dist/chunk-4E4YVQKK.js +5 -0
  32. package/dist/chunk-4E4YVQKK.js.map +1 -0
  33. package/dist/chunk-4QVBSG6B.cjs +2 -0
  34. package/dist/chunk-4QVBSG6B.cjs.map +1 -0
  35. package/dist/chunk-5FO4PDIG.js +2 -0
  36. package/dist/chunk-5FO4PDIG.js.map +1 -0
  37. package/dist/chunk-5IJD5L3O.cjs +2 -0
  38. package/dist/chunk-5IJD5L3O.cjs.map +1 -0
  39. package/dist/chunk-62LMTO4F.js +2 -0
  40. package/dist/chunk-62LMTO4F.js.map +1 -0
  41. package/dist/chunk-6G3PMEPA.js +2 -0
  42. package/dist/chunk-6G3PMEPA.js.map +1 -0
  43. package/dist/chunk-6INX773F.cjs +2 -0
  44. package/dist/chunk-6INX773F.cjs.map +1 -0
  45. package/dist/chunk-76F3LCIL.js +4 -0
  46. package/dist/chunk-76F3LCIL.js.map +1 -0
  47. package/dist/chunk-7BXPCWKM.cjs +2 -0
  48. package/dist/chunk-7BXPCWKM.cjs.map +1 -0
  49. package/dist/chunk-7GK3XEZF.js +2 -0
  50. package/dist/chunk-7GK3XEZF.js.map +1 -0
  51. package/dist/chunk-AXMQG5TS.cjs +2 -0
  52. package/dist/chunk-AXMQG5TS.cjs.map +1 -0
  53. package/dist/chunk-CIQOK7Q4.cjs +2 -0
  54. package/dist/chunk-CIQOK7Q4.cjs.map +1 -0
  55. package/dist/chunk-E2Q3PQ2G.js +3 -0
  56. package/dist/chunk-E2Q3PQ2G.js.map +1 -0
  57. package/dist/chunk-E6Z4NQAS.js +2 -0
  58. package/dist/chunk-E6Z4NQAS.js.map +1 -0
  59. package/dist/chunk-EFJCC6FJ.cjs +2 -0
  60. package/dist/chunk-EFJCC6FJ.cjs.map +1 -0
  61. package/dist/chunk-ESUN2THE.cjs +2 -0
  62. package/dist/chunk-ESUN2THE.cjs.map +1 -0
  63. package/dist/chunk-EVAOPEO4.js +2 -0
  64. package/dist/chunk-EVAOPEO4.js.map +1 -0
  65. package/dist/chunk-EVI6OHQH.cjs +2 -0
  66. package/dist/chunk-EVI6OHQH.cjs.map +1 -0
  67. package/dist/chunk-FDE5HWDI.cjs +2 -0
  68. package/dist/chunk-FDE5HWDI.cjs.map +1 -0
  69. package/dist/chunk-FWW3M36J.cjs +2 -0
  70. package/dist/chunk-FWW3M36J.cjs.map +1 -0
  71. package/dist/chunk-G7TBEQRQ.js +2 -0
  72. package/dist/chunk-G7TBEQRQ.js.map +1 -0
  73. package/dist/chunk-GK2OHWRF.cjs +5 -0
  74. package/dist/chunk-GK2OHWRF.cjs.map +1 -0
  75. package/dist/chunk-HFKDWQUL.js +2 -0
  76. package/dist/chunk-HFKDWQUL.js.map +1 -0
  77. package/dist/chunk-HLBYHXQD.cjs +3 -0
  78. package/dist/chunk-HLBYHXQD.cjs.map +1 -0
  79. package/dist/chunk-I52MYCVI.js +3 -0
  80. package/dist/chunk-I52MYCVI.js.map +1 -0
  81. package/dist/chunk-IANAMBJQ.cjs +2 -0
  82. package/dist/chunk-IANAMBJQ.cjs.map +1 -0
  83. package/dist/chunk-IJMNVBIS.js +2 -0
  84. package/dist/chunk-IJMNVBIS.js.map +1 -0
  85. package/dist/chunk-J4LZD4ZY.js +3 -0
  86. package/dist/chunk-J4LZD4ZY.js.map +1 -0
  87. package/dist/chunk-JAK3RAFA.cjs +2 -0
  88. package/dist/chunk-JAK3RAFA.cjs.map +1 -0
  89. package/dist/chunk-JFAJN3C2.cjs +2 -0
  90. package/dist/chunk-JFAJN3C2.cjs.map +1 -0
  91. package/dist/chunk-JPFCXLJV.js +2 -0
  92. package/dist/chunk-JPFCXLJV.js.map +1 -0
  93. package/dist/chunk-JUIJ6NRD.cjs +3 -0
  94. package/dist/chunk-JUIJ6NRD.cjs.map +1 -0
  95. package/dist/chunk-MIQBJGGR.js +2 -0
  96. package/dist/chunk-MIQBJGGR.js.map +1 -0
  97. package/dist/chunk-MPB7KUN5.js +3 -0
  98. package/dist/chunk-MPB7KUN5.js.map +1 -0
  99. package/dist/chunk-MSYX32PF.cjs +2 -0
  100. package/dist/chunk-MSYX32PF.cjs.map +1 -0
  101. package/dist/chunk-MVZUTETT.js +2 -0
  102. package/dist/chunk-MVZUTETT.js.map +1 -0
  103. package/dist/chunk-N7N7MPMK.cjs +2 -0
  104. package/dist/chunk-N7N7MPMK.cjs.map +1 -0
  105. package/dist/chunk-NGBBNL4K.cjs +1 -3
  106. package/dist/chunk-OVKDDTXO.cjs +3 -0
  107. package/dist/chunk-OVKDDTXO.cjs.map +1 -0
  108. package/dist/chunk-P6WPEUAJ.cjs +2 -0
  109. package/dist/chunk-P6WPEUAJ.cjs.map +1 -0
  110. package/dist/chunk-PS272DZJ.cjs +2 -0
  111. package/dist/chunk-PS272DZJ.cjs.map +1 -0
  112. package/dist/chunk-R2ENWQ76.js +2 -0
  113. package/dist/chunk-R2ENWQ76.js.map +1 -0
  114. package/dist/chunk-R2SZFJTT.cjs +2 -0
  115. package/dist/chunk-R2SZFJTT.cjs.map +1 -0
  116. package/dist/chunk-RAF57WYO.js +2 -0
  117. package/dist/chunk-RAF57WYO.js.map +1 -0
  118. package/dist/chunk-RSF25YSJ.js +2 -0
  119. package/dist/chunk-RSF25YSJ.js.map +1 -0
  120. package/dist/chunk-SOMGSIO4.cjs +3 -0
  121. package/dist/chunk-SOMGSIO4.cjs.map +1 -0
  122. package/dist/chunk-SYYE3QAX.cjs +2 -0
  123. package/dist/chunk-SYYE3QAX.cjs.map +1 -0
  124. package/dist/chunk-TCZSPH4A.js +2 -0
  125. package/dist/chunk-TCZSPH4A.js.map +1 -0
  126. package/dist/chunk-TLG7VZRX.cjs +2 -0
  127. package/dist/chunk-TLG7VZRX.cjs.map +1 -0
  128. package/dist/chunk-TN5E6JU6.js +2 -0
  129. package/dist/chunk-TN5E6JU6.js.map +1 -0
  130. package/dist/chunk-TRBXW6HW.js +2 -0
  131. package/dist/{chunk-AQNHHJMJ.cjs.map → chunk-TRBXW6HW.js.map} +1 -1
  132. package/dist/chunk-TTFO4YDP.cjs +2 -0
  133. package/dist/chunk-TTFO4YDP.cjs.map +1 -0
  134. package/dist/chunk-TWC7K3ZX.js +2 -0
  135. package/dist/chunk-TWC7K3ZX.js.map +1 -0
  136. package/dist/chunk-U4AEVL5Z.js +2 -0
  137. package/dist/chunk-U4AEVL5Z.js.map +1 -0
  138. package/dist/chunk-UURM7P3P.cjs +4 -0
  139. package/dist/chunk-UURM7P3P.cjs.map +1 -0
  140. package/dist/chunk-VAGS5JS7.cjs +2 -0
  141. package/dist/chunk-VAGS5JS7.cjs.map +1 -0
  142. package/dist/chunk-W2JAR233.js +2 -0
  143. package/dist/chunk-W2JAR233.js.map +1 -0
  144. package/dist/chunk-WGZ3FNHI.js +2 -0
  145. package/dist/chunk-WGZ3FNHI.js.map +1 -0
  146. package/dist/chunk-XEIDV5JP.js +2 -0
  147. package/dist/chunk-XEIDV5JP.js.map +1 -0
  148. package/dist/chunk-XNIWQHXY.js +2 -0
  149. package/dist/chunk-XNIWQHXY.js.map +1 -0
  150. package/dist/chunk-Y7O4D3BJ.cjs +2 -0
  151. package/dist/chunk-Y7O4D3BJ.cjs.map +1 -0
  152. package/dist/chunk-YAHGSBMC.js +2 -0
  153. package/dist/chunk-YAHGSBMC.js.map +1 -0
  154. package/dist/chunk-YAYBVVG2.js +3 -0
  155. package/dist/chunk-YAYBVVG2.js.map +1 -0
  156. package/dist/chunk-YJ2OPULK.js +2 -0
  157. package/dist/chunk-YJ2OPULK.js.map +1 -0
  158. package/dist/chunk-YVKHEAFT.js +2 -0
  159. package/dist/chunk-YVKHEAFT.js.map +1 -0
  160. package/dist/chunk-ZCNBT44X.cjs +2 -0
  161. package/dist/chunk-ZCNBT44X.cjs.map +1 -0
  162. package/dist/chunk-ZLRJ7TDP.cjs +2 -0
  163. package/dist/chunk-ZLRJ7TDP.cjs.map +1 -0
  164. package/dist/constants.cjs +1 -21
  165. package/dist/constants.d.cts +1 -1
  166. package/dist/constants.d.ts +1 -1
  167. package/dist/constants.js +1 -4
  168. package/dist/engine.cjs +1 -94
  169. package/dist/engine.d.cts +10 -11
  170. package/dist/engine.d.ts +10 -11
  171. package/dist/engine.js +1 -37
  172. package/dist/errors.cjs +1 -105
  173. package/dist/errors.d.cts +3 -3
  174. package/dist/errors.d.ts +3 -3
  175. package/dist/errors.js +1 -4
  176. package/dist/format.cjs +1 -26
  177. package/dist/format.d.cts +2 -2
  178. package/dist/format.d.ts +2 -2
  179. package/dist/format.js +1 -9
  180. package/dist/index.cjs +1 -314
  181. package/dist/index.cjs.map +1 -1
  182. package/dist/index.d.cts +52 -20
  183. package/dist/index.d.ts +52 -20
  184. package/dist/index.js +1 -278
  185. package/dist/index.js.map +1 -1
  186. package/dist/language.cjs +1 -369
  187. package/dist/language.cjs.map +1 -1
  188. package/dist/language.d.cts +9 -10
  189. package/dist/language.d.ts +9 -10
  190. package/dist/language.js +1 -348
  191. package/dist/language.js.map +1 -1
  192. package/dist/lexer.cjs +1 -63
  193. package/dist/lexer.js +1 -10
  194. package/dist/normalizer.cjs +1 -39
  195. package/dist/normalizer.js +1 -10
  196. package/dist/packages.cjs +1 -132
  197. package/dist/packages.d.cts +8 -9
  198. package/dist/packages.d.ts +8 -9
  199. package/dist/packages.js +1 -23
  200. package/dist/parser.cjs +1 -54
  201. package/dist/parser.d.cts +8 -8
  202. package/dist/parser.d.ts +8 -8
  203. package/dist/parser.js +1 -9
  204. package/dist/{pipeline-D-PS9gVw.d.ts → pipeline-72QmQlGx.d.ts} +1 -1
  205. package/dist/{pipeline-DtSBJ8TS.d.cts → pipeline-DCQicwWX.d.cts} +1 -1
  206. package/dist/resolvers.cjs +1 -12
  207. package/dist/resolvers.d.cts +2 -2
  208. package/dist/resolvers.d.ts +2 -2
  209. package/dist/resolvers.js +1 -3
  210. package/dist/services.cjs +1 -20
  211. package/dist/services.js +1 -3
  212. package/dist/testing.cjs +3 -477
  213. package/dist/testing.cjs.map +1 -1
  214. package/dist/testing.d.cts +9 -10
  215. package/dist/testing.d.ts +9 -10
  216. package/dist/testing.js +3 -469
  217. package/dist/testing.js.map +1 -1
  218. package/dist/uom.cjs +1 -55
  219. package/dist/uom.d.cts +2 -2
  220. package/dist/uom.d.ts +2 -2
  221. package/dist/uom.js +1 -10
  222. package/dist/utilities.cjs +1 -36
  223. package/dist/utilities.js +1 -7
  224. package/dist/vm.cjs +1 -295
  225. package/dist/vm.cjs.map +1 -1
  226. package/dist/vm.d.cts +22 -10
  227. package/dist/vm.d.ts +22 -10
  228. package/dist/vm.js +1 -193
  229. package/dist/vm.js.map +1 -1
  230. package/dist/worker.cjs +2 -492
  231. package/dist/worker.cjs.map +1 -1
  232. package/dist/worker.d.cts +16 -17
  233. package/dist/worker.d.ts +16 -17
  234. package/dist/worker.js +2 -483
  235. package/dist/worker.js.map +1 -1
  236. package/package.json +1 -13
  237. package/dist/chunk-3BOK2LDK.js +0 -17
  238. package/dist/chunk-3BOK2LDK.js.map +0 -1
  239. package/dist/chunk-3VGDNEE3.js +0 -84
  240. package/dist/chunk-3VGDNEE3.js.map +0 -1
  241. package/dist/chunk-4K5W7EH2.cjs +0 -112
  242. package/dist/chunk-4K5W7EH2.cjs.map +0 -1
  243. package/dist/chunk-5EFKSKMA.js +0 -413
  244. package/dist/chunk-5EFKSKMA.js.map +0 -1
  245. package/dist/chunk-5HRB36DK.js +0 -405
  246. package/dist/chunk-5HRB36DK.js.map +0 -1
  247. package/dist/chunk-5ON7PUAZ.js +0 -12
  248. package/dist/chunk-5ON7PUAZ.js.map +0 -1
  249. package/dist/chunk-7AXJNQMF.cjs +0 -297
  250. package/dist/chunk-7AXJNQMF.cjs.map +0 -1
  251. package/dist/chunk-7JM3F4KL.js +0 -1795
  252. package/dist/chunk-7JM3F4KL.js.map +0 -1
  253. package/dist/chunk-7USV76HV.cjs +0 -341
  254. package/dist/chunk-7USV76HV.cjs.map +0 -1
  255. package/dist/chunk-A2DZ5BEJ.cjs +0 -1930
  256. package/dist/chunk-A2DZ5BEJ.cjs.map +0 -1
  257. package/dist/chunk-ADBA3XBE.cjs +0 -20
  258. package/dist/chunk-ADBA3XBE.cjs.map +0 -1
  259. package/dist/chunk-AKNGX4TZ.cjs +0 -236
  260. package/dist/chunk-AKNGX4TZ.cjs.map +0 -1
  261. package/dist/chunk-ALYRJ72W.cjs +0 -434
  262. package/dist/chunk-ALYRJ72W.cjs.map +0 -1
  263. package/dist/chunk-AMOJYLG2.cjs +0 -1692
  264. package/dist/chunk-AMOJYLG2.cjs.map +0 -1
  265. package/dist/chunk-AOH6UR2L.js +0 -825
  266. package/dist/chunk-AOH6UR2L.js.map +0 -1
  267. package/dist/chunk-AQNHHJMJ.cjs +0 -261
  268. package/dist/chunk-B7LXJ6LC.cjs +0 -36
  269. package/dist/chunk-B7LXJ6LC.cjs.map +0 -1
  270. package/dist/chunk-BESTLPRK.cjs +0 -6919
  271. package/dist/chunk-BESTLPRK.cjs.map +0 -1
  272. package/dist/chunk-BLI4NIQY.js +0 -98
  273. package/dist/chunk-BLI4NIQY.js.map +0 -1
  274. package/dist/chunk-BSPXMGIS.js +0 -455
  275. package/dist/chunk-BSPXMGIS.js.map +0 -1
  276. package/dist/chunk-C2OMO3WN.cjs +0 -2806
  277. package/dist/chunk-C2OMO3WN.cjs.map +0 -1
  278. package/dist/chunk-CSDQMDU2.js +0 -204
  279. package/dist/chunk-CSDQMDU2.js.map +0 -1
  280. package/dist/chunk-EJ3ILXX6.cjs +0 -223
  281. package/dist/chunk-EJ3ILXX6.cjs.map +0 -1
  282. package/dist/chunk-ENRIK36Q.cjs +0 -94
  283. package/dist/chunk-ENRIK36Q.cjs.map +0 -1
  284. package/dist/chunk-F4UB4XIL.js +0 -109
  285. package/dist/chunk-F4UB4XIL.js.map +0 -1
  286. package/dist/chunk-FD5ZZHEU.js +0 -92
  287. package/dist/chunk-FD5ZZHEU.js.map +0 -1
  288. package/dist/chunk-FE4RC37D.js +0 -2801
  289. package/dist/chunk-FE4RC37D.js.map +0 -1
  290. package/dist/chunk-FEAIOR7N.cjs +0 -91
  291. package/dist/chunk-FEAIOR7N.cjs.map +0 -1
  292. package/dist/chunk-FR7RNOPT.cjs +0 -3303
  293. package/dist/chunk-FR7RNOPT.cjs.map +0 -1
  294. package/dist/chunk-G2YPPLGX.cjs +0 -484
  295. package/dist/chunk-G2YPPLGX.cjs.map +0 -1
  296. package/dist/chunk-GCM5JHMX.js +0 -88
  297. package/dist/chunk-GCM5JHMX.js.map +0 -1
  298. package/dist/chunk-GDEU72RG.cjs +0 -829
  299. package/dist/chunk-GDEU72RG.cjs.map +0 -1
  300. package/dist/chunk-HKTQCQ4Z.cjs +0 -8383
  301. package/dist/chunk-HKTQCQ4Z.cjs.map +0 -1
  302. package/dist/chunk-HWHU642X.cjs +0 -316
  303. package/dist/chunk-HWHU642X.cjs.map +0 -1
  304. package/dist/chunk-ICEKS6YC.cjs +0 -507
  305. package/dist/chunk-ICEKS6YC.cjs.map +0 -1
  306. package/dist/chunk-IJGOFP2J.js +0 -6904
  307. package/dist/chunk-IJGOFP2J.js.map +0 -1
  308. package/dist/chunk-IQJGDZOP.js +0 -333
  309. package/dist/chunk-IQJGDZOP.js.map +0 -1
  310. package/dist/chunk-IT74O4BE.cjs +0 -456
  311. package/dist/chunk-IT74O4BE.cjs.map +0 -1
  312. package/dist/chunk-KXDQKVNX.cjs +0 -459
  313. package/dist/chunk-KXDQKVNX.cjs.map +0 -1
  314. package/dist/chunk-L2TE7PMO.cjs +0 -14
  315. package/dist/chunk-L2TE7PMO.cjs.map +0 -1
  316. package/dist/chunk-L5YHV6BQ.js +0 -499
  317. package/dist/chunk-L5YHV6BQ.js.map +0 -1
  318. package/dist/chunk-LO7HU5WB.cjs +0 -209
  319. package/dist/chunk-LO7HU5WB.cjs.map +0 -1
  320. package/dist/chunk-LSALB3IN.js +0 -292
  321. package/dist/chunk-LSALB3IN.js.map +0 -1
  322. package/dist/chunk-MI7OTUHL.cjs +0 -339
  323. package/dist/chunk-MI7OTUHL.cjs.map +0 -1
  324. package/dist/chunk-MIGXCBXT.cjs +0 -381
  325. package/dist/chunk-MIGXCBXT.cjs.map +0 -1
  326. package/dist/chunk-MVTOCRV2.js +0 -213
  327. package/dist/chunk-MVTOCRV2.js.map +0 -1
  328. package/dist/chunk-N7FNVFXW.cjs +0 -32
  329. package/dist/chunk-N7FNVFXW.cjs.map +0 -1
  330. package/dist/chunk-N7OA4WPJ.js +0 -362
  331. package/dist/chunk-N7OA4WPJ.js.map +0 -1
  332. package/dist/chunk-NAWZATKT.js +0 -478
  333. package/dist/chunk-NAWZATKT.js.map +0 -1
  334. package/dist/chunk-NLNDMWZC.js +0 -31
  335. package/dist/chunk-NLNDMWZC.js.map +0 -1
  336. package/dist/chunk-ORM7CHYZ.js +0 -1531
  337. package/dist/chunk-ORM7CHYZ.js.map +0 -1
  338. package/dist/chunk-OUHT5Z36.cjs +0 -393
  339. package/dist/chunk-OUHT5Z36.cjs.map +0 -1
  340. package/dist/chunk-PCZVMMWU.cjs +0 -74
  341. package/dist/chunk-PCZVMMWU.cjs.map +0 -1
  342. package/dist/chunk-RNKDIXDV.js +0 -336
  343. package/dist/chunk-RNKDIXDV.js.map +0 -1
  344. package/dist/chunk-SBUFNJVE.js +0 -258
  345. package/dist/chunk-SBUFNJVE.js.map +0 -1
  346. package/dist/chunk-TC6BTUSU.cjs +0 -1799
  347. package/dist/chunk-TC6BTUSU.cjs.map +0 -1
  348. package/dist/chunk-TPOK3UNI.js +0 -8355
  349. package/dist/chunk-TPOK3UNI.js.map +0 -1
  350. package/dist/chunk-UF6JG5SG.js +0 -312
  351. package/dist/chunk-UF6JG5SG.js.map +0 -1
  352. package/dist/chunk-UKQHXPGW.js +0 -30
  353. package/dist/chunk-UKQHXPGW.js.map +0 -1
  354. package/dist/chunk-V4XG5QF6.js +0 -1685
  355. package/dist/chunk-V4XG5QF6.js.map +0 -1
  356. package/dist/chunk-VEKIWQ3F.cjs +0 -39
  357. package/dist/chunk-VEKIWQ3F.cjs.map +0 -1
  358. package/dist/chunk-WMQRJTAO.js +0 -3266
  359. package/dist/chunk-WMQRJTAO.js.map +0 -1
  360. package/dist/chunk-X6K3HUOY.cjs +0 -86
  361. package/dist/chunk-X6K3HUOY.cjs.map +0 -1
  362. package/dist/chunk-XBTEO4OB.js +0 -391
  363. package/dist/chunk-XBTEO4OB.js.map +0 -1
  364. package/dist/chunk-XIYYHA65.cjs +0 -101
  365. package/dist/chunk-XIYYHA65.cjs.map +0 -1
  366. package/dist/chunk-YJHY7CMN.cjs +0 -1534
  367. package/dist/chunk-YJHY7CMN.cjs.map +0 -1
  368. package/dist/chunk-YLJ4XMA6.js +0 -33
  369. package/dist/chunk-YLJ4XMA6.js.map +0 -1
  370. package/dist/chunk-YNIWOYW6.js +0 -232
  371. package/dist/chunk-YNIWOYW6.js.map +0 -1
  372. package/dist/chunk-Z2XP767T.cjs +0 -35
  373. package/dist/chunk-Z2XP767T.cjs.map +0 -1
  374. package/dist/chunk-Z4X2RWOF.js +0 -37
  375. package/dist/chunk-Z4X2RWOF.js.map +0 -1
  376. package/dist/chunk-ZN6YYPIW.js +0 -67
  377. package/dist/chunk-ZN6YYPIW.js.map +0 -1
  378. package/dist/chunk-ZNFFTYWH.js +0 -1854
  379. package/dist/chunk-ZNFFTYWH.js.map +0 -1
  380. package/dist/variables.cjs +0 -17
  381. package/dist/variables.cjs.map +0 -1
  382. package/dist/variables.d.cts +0 -87
  383. package/dist/variables.d.ts +0 -87
  384. package/dist/variables.js +0 -4
  385. package/dist/variables.js.map +0 -1
@@ -1,1930 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkIT74O4BE_cjs = require('./chunk-IT74O4BE.cjs');
4
- var chunkMIGXCBXT_cjs = require('./chunk-MIGXCBXT.cjs');
5
-
6
- // src/decimal/Decimal.ts
7
- var DEFAULT_DIVISION_SCALE = 20;
8
- var POW10 = [1n];
9
- function pow10(n) {
10
- if (n < 0) {
11
- throw chunkMIGXCBXT_cjs.ErrorFactory.internal("DECIMAL_NEGATIVE_POWER", `pow10 needs a non-negative exponent, got ${n}`, { exponent: n });
12
- }
13
- for (let i = POW10.length; i <= n; i++) POW10[i] = POW10[i - 1] * 10n;
14
- return POW10[n];
15
- }
16
- function makeDecimal(coef, scale) {
17
- if (!Number.isInteger(scale) || scale < 0) {
18
- throw chunkMIGXCBXT_cjs.ErrorFactory.internal("DECIMAL_INVALID_SCALE", `A decimal scale must be a non-negative integer, got ${scale}`, { scale });
19
- }
20
- return { coef, scale };
21
- }
22
- function decimalFromInteger(n) {
23
- return { coef: typeof n === "bigint" ? n : BigInt(n), scale: 0 };
24
- }
25
- function decimalFromNumberIfExact(n) {
26
- if (!Number.isFinite(n) || !Number.isInteger(n)) return null;
27
- return decimalFromInteger(BigInt(n));
28
- }
29
- function decimalFromLiteral(text) {
30
- let s = text;
31
- let negative = false;
32
- if (s.startsWith("-")) {
33
- negative = true;
34
- s = s.slice(1);
35
- } else if (s.startsWith("+")) {
36
- s = s.slice(1);
37
- }
38
- const dot = s.indexOf(".");
39
- const intPart = dot < 0 ? s : s.slice(0, dot);
40
- const fracPart = dot < 0 ? "" : s.slice(dot + 1);
41
- const digits = intPart + fracPart || "0";
42
- if (!/^[0-9]+$/.test(digits)) {
43
- throw chunkMIGXCBXT_cjs.ErrorFactory.parsing("INVALID_DECIMAL_LITERAL", `Not a decimal literal: "${text}"`, { raw: text });
44
- }
45
- let coef = BigInt(digits);
46
- if (negative) coef = -coef;
47
- return { coef, scale: fracPart.length };
48
- }
49
- function align(a, b) {
50
- if (a.scale === b.scale) return { ca: a.coef, cb: b.coef, scale: a.scale };
51
- if (a.scale > b.scale) return { ca: a.coef, cb: b.coef * pow10(a.scale - b.scale), scale: a.scale };
52
- return { ca: a.coef * pow10(b.scale - a.scale), cb: b.coef, scale: b.scale };
53
- }
54
- function decimalAdd(a, b) {
55
- const { ca, cb, scale } = align(a, b);
56
- return { coef: ca + cb, scale };
57
- }
58
- function decimalSubtract(a, b) {
59
- const { ca, cb, scale } = align(a, b);
60
- return { coef: ca - cb, scale };
61
- }
62
- function decimalMultiply(a, b) {
63
- return { coef: a.coef * b.coef, scale: a.scale + b.scale };
64
- }
65
- function decimalNegate(a) {
66
- return { coef: -a.coef, scale: a.scale };
67
- }
68
- function decimalIsZero(a) {
69
- return a.coef === 0n;
70
- }
71
- function roundCoefToScale(coef, scale, targetScale) {
72
- if (targetScale >= scale) return coef * pow10(targetScale - scale);
73
- const divisor = pow10(scale - targetScale);
74
- const negative = coef < 0n;
75
- const magnitude = negative ? -coef : coef;
76
- let q = magnitude / divisor;
77
- const r = magnitude % divisor;
78
- if (r * 2n >= divisor) q += 1n;
79
- return negative ? -q : q;
80
- }
81
- function decimalRound(a, targetScale) {
82
- return { coef: roundCoefToScale(a.coef, a.scale, targetScale), scale: targetScale };
83
- }
84
- function decimalDivide(a, b, maxFractionDigits = DEFAULT_DIVISION_SCALE) {
85
- if (decimalIsZero(b)) {
86
- throw chunkMIGXCBXT_cjs.ErrorFactory.internal("DECIMAL_DIVISION_BY_ZERO", "decimalDivide was called with a zero divisor", {});
87
- }
88
- const s = maxFractionDigits;
89
- const numerator = a.coef * pow10(s + b.scale);
90
- const denominator = b.coef * pow10(a.scale);
91
- const negative = numerator < 0n !== denominator < 0n;
92
- const num = numerator < 0n ? -numerator : numerator;
93
- const den = denominator < 0n ? -denominator : denominator;
94
- let q = num / den;
95
- const r = num % den;
96
- if (r * 2n >= den) q += 1n;
97
- return { coef: negative ? -q : q, scale: s };
98
- }
99
- function decimalCompare(a, b) {
100
- const { ca, cb } = align(a, b);
101
- if (ca < cb) return -1;
102
- if (ca > cb) return 1;
103
- return 0;
104
- }
105
- function decimalToString(a) {
106
- const negative = a.coef < 0n;
107
- let digits = (negative ? -a.coef : a.coef).toString();
108
- if (a.scale === 0) return negative ? `-${digits}` : digits;
109
- if (digits.length <= a.scale) digits = digits.padStart(a.scale + 1, "0");
110
- const cut = digits.length - a.scale;
111
- const whole = digits.slice(0, cut);
112
- const frac = digits.slice(cut);
113
- return `${negative ? "-" : ""}${whole}.${frac}`;
114
- }
115
- function decimalToNumber(a) {
116
- return Number(decimalToString(a));
117
- }
118
- function decimalToFixed(a, fractionDigits) {
119
- const rounded = decimalRound(a, fractionDigits);
120
- const negative = rounded.coef < 0n && rounded.coef !== 0n;
121
- let digits = (rounded.coef < 0n ? -rounded.coef : rounded.coef).toString();
122
- if (fractionDigits === 0) return negative ? `-${digits}` : digits;
123
- if (digits.length <= fractionDigits) digits = digits.padStart(fractionDigits + 1, "0");
124
- const cut = digits.length - fractionDigits;
125
- const whole = digits.slice(0, cut);
126
- const frac = digits.slice(cut);
127
- return `${negative ? "-" : ""}${whole}.${frac}`;
128
- }
129
-
130
- // src/symbolic/Rational.ts
131
- var RATIONAL_ZERO = { n: 0n, d: 1n };
132
- var RATIONAL_ONE = { n: 1n, d: 1n };
133
- var RATIONAL_MINUS_ONE = { n: -1n, d: 1n };
134
- var RATIONAL_MAX_BITS = 4096;
135
- var MAX_MAGNITUDE = 1n << BigInt(RATIONAL_MAX_BITS);
136
- function bigintPow(base, exponent) {
137
- let result = 1n;
138
- let factor = base;
139
- let remaining = exponent;
140
- while (remaining > 0n) {
141
- if (remaining % 2n === 1n) result *= factor;
142
- factor *= factor;
143
- remaining /= 2n;
144
- }
145
- return result;
146
- }
147
- function gcd(a, b) {
148
- let x = a < 0n ? -a : a;
149
- let y = b < 0n ? -b : b;
150
- while (y !== 0n) {
151
- const remainder = x % y;
152
- x = y;
153
- y = remainder;
154
- }
155
- return x;
156
- }
157
- function guardMagnitude(n, d) {
158
- const magnitude = n < 0n ? -n : n;
159
- if (magnitude >= MAX_MAGNITUDE || d >= MAX_MAGNITUDE) {
160
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution(
161
- "SYMBOLIC_RATIONAL_OVERFLOW",
162
- `This calculation produced a fraction too large to represent exactly (over ${RATIONAL_MAX_BITS} bits).`,
163
- { limitBits: RATIONAL_MAX_BITS }
164
- );
165
- }
166
- }
167
- function normalize(n, d) {
168
- if (d === 0n) {
169
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
170
- }
171
- if (n === 0n) return RATIONAL_ZERO;
172
- let numerator = d < 0n ? -n : n;
173
- let denominator = d < 0n ? -d : d;
174
- const divisor = gcd(numerator, denominator);
175
- numerator /= divisor;
176
- denominator /= divisor;
177
- guardMagnitude(numerator, denominator);
178
- return { n: numerator, d: denominator };
179
- }
180
- function rational(numerator, denominator = 1n) {
181
- return normalize(numerator, denominator);
182
- }
183
- var DECIMAL_FORM = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
184
- function rationalFromNumber(value) {
185
- if (!Number.isFinite(value)) {
186
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution(
187
- "SYMBOLIC_NONFINITE_OPERAND",
188
- `"${String(value)}" has no exact value, so it cannot appear in a symbolic expression.`,
189
- { value: String(value) }
190
- );
191
- }
192
- if (Number.isInteger(value)) return normalize(BigInt(value), 1n);
193
- const parts = DECIMAL_FORM.exec(String(value));
194
- if (parts === null) {
195
- throw chunkMIGXCBXT_cjs.ErrorFactory.internal(
196
- "INTERNAL_RATIONAL_PARSE",
197
- `Internal error: could not read "${String(value)}" as a decimal number.`,
198
- { value: String(value) }
199
- );
200
- }
201
- const [, sign, integerDigits, fractionDigits = "", exponentDigits] = parts;
202
- let numerator = BigInt(integerDigits + fractionDigits);
203
- let denominator = bigintPow(10n, BigInt(fractionDigits.length));
204
- const exponent = exponentDigits === void 0 ? 0 : Number(exponentDigits);
205
- if (exponent > 0) numerator *= bigintPow(10n, BigInt(exponent));
206
- else if (exponent < 0) denominator *= bigintPow(10n, BigInt(-exponent));
207
- return normalize(sign === "-" ? -numerator : numerator, denominator);
208
- }
209
- function rationalToNumber(r) {
210
- if (r.d === 1n) return Number(r.n);
211
- const direct = Number(r.n) / Number(r.d);
212
- if (!Number.isNaN(direct)) return direct;
213
- const GUARD_BITS = 64n;
214
- return Number((r.n << GUARD_BITS) / r.d) / 2 ** 64;
215
- }
216
- function rationalAdd(a, b) {
217
- return normalize(a.n * b.d + b.n * a.d, a.d * b.d);
218
- }
219
- function rationalSub(a, b) {
220
- return normalize(a.n * b.d - b.n * a.d, a.d * b.d);
221
- }
222
- function rationalMul(a, b) {
223
- return normalize(a.n * b.n, a.d * b.d);
224
- }
225
- function rationalDiv(a, b) {
226
- if (b.n === 0n) {
227
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a symbolic expression.");
228
- }
229
- return normalize(a.n * b.d, a.d * b.n);
230
- }
231
- function rationalNeg(r) {
232
- return r.n === 0n ? RATIONAL_ZERO : { n: -r.n, d: r.d };
233
- }
234
- function rationalPow(base, exponent) {
235
- if (exponent === 0n) return RATIONAL_ONE;
236
- if (exponent < 0n) {
237
- if (base.n === 0n) {
238
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
239
- }
240
- const positive = -exponent;
241
- return normalize(bigintPow(base.d, positive), bigintPow(base.n, positive));
242
- }
243
- return normalize(bigintPow(base.n, exponent), bigintPow(base.d, exponent));
244
- }
245
- function rationalCompare(a, b) {
246
- const left = a.n * b.d;
247
- const right = b.n * a.d;
248
- if (left < right) return -1;
249
- if (left > right) return 1;
250
- return 0;
251
- }
252
- function isRationalZero(r) {
253
- return r.n === 0n;
254
- }
255
- function isRationalOne(r) {
256
- return r.n === 1n && r.d === 1n;
257
- }
258
- function isRationalMinusOne(r) {
259
- return r.n === -1n && r.d === 1n;
260
- }
261
- function isRationalInteger(r) {
262
- return r.d === 1n;
263
- }
264
- var MAX_DECIMAL_DIGITS = 10;
265
- var MAX_FRACTION_COMPONENT = 1000000n;
266
- function formatRational(r) {
267
- if (r.d === 1n) return String(r.n);
268
- let remaining = r.d;
269
- let twos = 0;
270
- let fives = 0;
271
- while (remaining % 2n === 0n) {
272
- remaining /= 2n;
273
- twos++;
274
- }
275
- while (remaining % 5n === 0n) {
276
- remaining /= 5n;
277
- fives++;
278
- }
279
- const terminates = remaining === 1n;
280
- const decimals = Math.max(twos, fives);
281
- if (!terminates || decimals > MAX_DECIMAL_DIGITS) {
282
- const magnitude = r.n < 0n ? -r.n : r.n;
283
- if (magnitude <= MAX_FRACTION_COMPONENT && r.d <= MAX_FRACTION_COMPONENT) return `${r.n}/${r.d}`;
284
- return String(Math.round(rationalToNumber(r) * 1e10) / 1e10);
285
- }
286
- const scaled = (r.n < 0n ? -r.n : r.n) * bigintPow(10n, BigInt(decimals)) / r.d;
287
- const digits = String(scaled).padStart(decimals + 1, "0");
288
- const whole = digits.slice(0, digits.length - decimals);
289
- const fraction = digits.slice(digits.length - decimals).replace(/0+$/, "");
290
- const sign = r.n < 0n ? "-" : "";
291
- return fraction.length === 0 ? `${sign}${whole}` : `${sign}${whole}.${fraction}`;
292
- }
293
-
294
- // src/symbolic/Complex.ts
295
- var COMPLEX_ZERO = { re: RATIONAL_ZERO, im: RATIONAL_ZERO };
296
- var COMPLEX_ONE = { re: RATIONAL_ONE, im: RATIONAL_ZERO };
297
- var COMPLEX_I = { re: RATIONAL_ZERO, im: RATIONAL_ONE };
298
- function complex(re, im = RATIONAL_ZERO) {
299
- return { re, im };
300
- }
301
- function isComplexZero(z) {
302
- return isRationalZero(z.re) && isRationalZero(z.im);
303
- }
304
- function complexAdd(a, b) {
305
- return { re: rationalAdd(a.re, b.re), im: rationalAdd(a.im, b.im) };
306
- }
307
- function complexSub(a, b) {
308
- return { re: rationalSub(a.re, b.re), im: rationalSub(a.im, b.im) };
309
- }
310
- function complexMul(a, b) {
311
- return {
312
- re: rationalSub(rationalMul(a.re, b.re), rationalMul(a.im, b.im)),
313
- im: rationalAdd(rationalMul(a.re, b.im), rationalMul(a.im, b.re))
314
- };
315
- }
316
- function complexDiv(a, b) {
317
- if (isComplexZero(b)) {
318
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Division by zero in a complex expression.");
319
- }
320
- const denominator = rationalAdd(rationalMul(b.re, b.re), rationalMul(b.im, b.im));
321
- return {
322
- re: rationalDiv(rationalAdd(rationalMul(a.re, b.re), rationalMul(a.im, b.im)), denominator),
323
- im: rationalDiv(rationalSub(rationalMul(a.im, b.re), rationalMul(a.re, b.im)), denominator)
324
- };
325
- }
326
- function complexNeg(z) {
327
- return { re: rationalNeg(z.re), im: rationalNeg(z.im) };
328
- }
329
- function complexConjugate(z) {
330
- return { re: z.re, im: rationalNeg(z.im) };
331
- }
332
- function complexNormSquared(z) {
333
- return rationalAdd(rationalMul(z.re, z.re), rationalMul(z.im, z.im));
334
- }
335
- function complexPow(base, exponent) {
336
- if (exponent === 0n) return COMPLEX_ONE;
337
- if (exponent < 0n) {
338
- if (isComplexZero(base)) {
339
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution("SYMBOLIC_DIVISION_BY_ZERO", "Zero raised to a negative power is undefined.");
340
- }
341
- return complexDiv(COMPLEX_ONE, complexPow(base, -exponent));
342
- }
343
- let result = COMPLEX_ONE;
344
- let factor = base;
345
- let remaining = exponent;
346
- while (remaining > 0n) {
347
- if (remaining % 2n === 1n) result = complexMul(result, factor);
348
- factor = complexMul(factor, factor);
349
- remaining /= 2n;
350
- }
351
- return result;
352
- }
353
- function complexEquals(a, b) {
354
- return a.re.n === b.re.n && a.re.d === b.re.d && a.im.n === b.im.n && a.im.d === b.im.d;
355
- }
356
- function formatComplex(z) {
357
- if (isRationalZero(z.im)) return formatRational(z.re);
358
- const magnitude = z.im.n < 0n ? rationalNeg(z.im) : z.im;
359
- const imaginary = isRationalOne(magnitude) ? "i" : `${formatRational(magnitude)}i`;
360
- if (isRationalZero(z.re)) return z.im.n < 0n ? `-${imaginary}` : imaginary;
361
- return z.im.n < 0n ? `${formatRational(z.re)}-${imaginary}` : `${formatRational(z.re)}+${imaginary}`;
362
- }
363
- function exactComplexSqrt(z) {
364
- if (isComplexZero(z)) return COMPLEX_ZERO;
365
- const modulus = exactRationalSqrt(complexNormSquared(z));
366
- if (modulus === null) return null;
367
- const two = { n: 2n, d: 1n };
368
- const realPart = exactRationalSqrt(rationalDiv(rationalAdd(modulus, z.re), two));
369
- if (realPart === null) return null;
370
- if (isRationalZero(realPart)) {
371
- const imaginaryPart2 = exactRationalSqrt(rationalDiv(rationalSub(modulus, z.re), two));
372
- return imaginaryPart2 === null ? null : { re: RATIONAL_ZERO, im: imaginaryPart2 };
373
- }
374
- const imaginaryPart = rationalDiv(z.im, rationalMul(two, realPart));
375
- return { re: realPart, im: imaginaryPart };
376
- }
377
- function exactRationalSqrt(value) {
378
- if (value.n < 0n) return null;
379
- const numerator = exactBigintSqrt(value.n);
380
- const denominator = exactBigintSqrt(value.d);
381
- return numerator === null || denominator === null ? null : { n: numerator, d: denominator };
382
- }
383
- function exactBigintSqrt(value) {
384
- if (value < 0n) return null;
385
- if (value < 2n) return value;
386
- let previous = value;
387
- let current = (value + 1n) / 2n;
388
- while (current < previous) {
389
- previous = current;
390
- current = (previous + value / previous) / 2n;
391
- }
392
- return previous * previous === value ? previous : null;
393
- }
394
-
395
- // src/symbolic/SymbolicNode.ts
396
- var SYMBOLIC_MAX_NODES = 1e4;
397
- function constNode(value) {
398
- return { kind: "const", value: typeof value === "number" ? rationalFromNumber(value) : value };
399
- }
400
- function varNode(name) {
401
- return { kind: "var", name };
402
- }
403
- function powNode(base, exponent) {
404
- return { kind: "pow", base, exponent };
405
- }
406
- function callNode(name, args) {
407
- return { kind: "call", name, args };
408
- }
409
- function symbolicKey(node) {
410
- switch (node.kind) {
411
- case "const":
412
- return `${node.value.n}/${node.value.d}`;
413
- case "complex":
414
- return `C(${node.value.re.n}/${node.value.re.d},${node.value.im.n}/${node.value.im.d})`;
415
- case "var":
416
- return `v:${node.name}`;
417
- case "neg":
418
- return `-(${symbolicKey(node.operand)})`;
419
- case "pow":
420
- return `^(${symbolicKey(node.base)},${symbolicKey(node.exponent)})`;
421
- case "call":
422
- return `${node.name}(${node.args.map(symbolicKey).join(",")})`;
423
- case "add":
424
- return `+(${symbolicKey(node.left)},${symbolicKey(node.right)})`;
425
- case "sub":
426
- return `-(${symbolicKey(node.left)},${symbolicKey(node.right)})`;
427
- case "mul":
428
- return `*(${symbolicKey(node.left)},${symbolicKey(node.right)})`;
429
- case "div":
430
- return `/(${symbolicKey(node.left)},${symbolicKey(node.right)})`;
431
- }
432
- }
433
- function nodesEqual(a, b) {
434
- if (a.kind !== b.kind) return false;
435
- switch (a.kind) {
436
- case "const": {
437
- const other = b;
438
- return a.value.n === other.value.n && a.value.d === other.value.d;
439
- }
440
- case "complex":
441
- return complexEquals(a.value, b.value);
442
- case "var":
443
- return a.name === b.name;
444
- case "neg":
445
- return nodesEqual(a.operand, b.operand);
446
- case "pow": {
447
- const other = b;
448
- return nodesEqual(a.base, other.base) && nodesEqual(a.exponent, other.exponent);
449
- }
450
- case "call": {
451
- const other = b;
452
- if (a.name !== other.name || a.args.length !== other.args.length) return false;
453
- return a.args.every((arg, i) => nodesEqual(arg, other.args[i]));
454
- }
455
- case "add":
456
- case "sub":
457
- case "mul":
458
- case "div": {
459
- const other = b;
460
- return nodesEqual(a.left, other.left) && nodesEqual(a.right, other.right);
461
- }
462
- }
463
- }
464
- function nodeCount(node, limit = Number.POSITIVE_INFINITY) {
465
- const pending = [node];
466
- let total = 0;
467
- while (pending.length > 0) {
468
- const current = pending.pop();
469
- total++;
470
- if (total > limit) return total;
471
- switch (current.kind) {
472
- case "const":
473
- case "complex":
474
- case "var":
475
- break;
476
- case "neg":
477
- pending.push(current.operand);
478
- break;
479
- case "pow":
480
- pending.push(current.base, current.exponent);
481
- break;
482
- case "call":
483
- for (const arg of current.args) pending.push(arg);
484
- break;
485
- case "add":
486
- case "sub":
487
- case "mul":
488
- case "div":
489
- pending.push(current.left, current.right);
490
- break;
491
- }
492
- }
493
- return total;
494
- }
495
- function freeVariables(node) {
496
- const names = /* @__PURE__ */ new Set();
497
- collectVariables(node, names);
498
- return names;
499
- }
500
- function collectVariables(node, into) {
501
- switch (node.kind) {
502
- case "const":
503
- case "complex":
504
- return;
505
- case "var":
506
- into.add(node.name);
507
- return;
508
- case "neg":
509
- collectVariables(node.operand, into);
510
- return;
511
- case "pow":
512
- collectVariables(node.base, into);
513
- collectVariables(node.exponent, into);
514
- return;
515
- case "call":
516
- for (const arg of node.args) collectVariables(arg, into);
517
- return;
518
- case "add":
519
- case "sub":
520
- case "mul":
521
- case "div":
522
- collectVariables(node.left, into);
523
- collectVariables(node.right, into);
524
- }
525
- }
526
- function substitute(node, variable, replacement) {
527
- switch (node.kind) {
528
- case "const":
529
- case "complex":
530
- return node;
531
- case "var":
532
- return node.name === variable ? replacement : node;
533
- case "neg":
534
- return { kind: "neg", operand: substitute(node.operand, variable, replacement) };
535
- case "pow":
536
- return {
537
- kind: "pow",
538
- base: substitute(node.base, variable, replacement),
539
- exponent: substitute(node.exponent, variable, replacement)
540
- };
541
- case "call":
542
- return { kind: "call", name: node.name, args: node.args.map((arg) => substitute(arg, variable, replacement)) };
543
- case "add":
544
- case "sub":
545
- case "mul":
546
- case "div":
547
- return {
548
- kind: node.kind,
549
- left: substitute(node.left, variable, replacement),
550
- right: substitute(node.right, variable, replacement)
551
- };
552
- }
553
- }
554
- function complexNode(value) {
555
- if (value.im.n === 0n) return { kind: "const", value: value.re };
556
- return { kind: "complex", value };
557
- }
558
-
559
- // src/symbolic/Polynomial.ts
560
- var EXPAND_MAX_POW_EXPONENT = 32;
561
- var POLYNOMIAL_MAX_TERMS = 2e3;
562
- var POLYNOMIAL_MAX_DEGREE = 64;
563
- function monomialToKey(monomial) {
564
- const names = [...monomial.keys()].sort();
565
- return names.map((name) => monomial.get(name) === 1 ? name : `${name}^${monomial.get(name)}`).join("*");
566
- }
567
- function monomialFromKey(key) {
568
- const monomial = /* @__PURE__ */ new Map();
569
- if (key === "") return monomial;
570
- for (const factor of key.split("*")) {
571
- const caret = factor.indexOf("^");
572
- if (caret === -1) monomial.set(factor, 1);
573
- else monomial.set(factor.slice(0, caret), Number(factor.slice(caret + 1)));
574
- }
575
- return monomial;
576
- }
577
- function monomialDegree(key) {
578
- let total = 0;
579
- for (const exponent of monomialFromKey(key).values()) total += exponent;
580
- return total;
581
- }
582
- function build(terms) {
583
- const kept = /* @__PURE__ */ new Map();
584
- const names = /* @__PURE__ */ new Set();
585
- for (const [key, coeff] of terms) {
586
- if (isRationalZero(coeff)) continue;
587
- if (monomialDegree(key) > POLYNOMIAL_MAX_DEGREE) return null;
588
- kept.set(key, coeff);
589
- for (const name of monomialFromKey(key).keys()) names.add(name);
590
- }
591
- if (kept.size > POLYNOMIAL_MAX_TERMS) return null;
592
- return { terms: kept, vars: [...names].sort() };
593
- }
594
- function constantPolynomial(value) {
595
- return isRationalZero(value) ? { terms: /* @__PURE__ */ new Map(), vars: [] } : { terms: /* @__PURE__ */ new Map([["", value]]), vars: [] };
596
- }
597
- function polyAdd(a, b) {
598
- const terms = new Map(a.terms);
599
- for (const [key, coeff] of b.terms) {
600
- const existing = terms.get(key);
601
- terms.set(key, existing === void 0 ? coeff : rationalAdd(existing, coeff));
602
- }
603
- return build(terms);
604
- }
605
- function polySub(a, b) {
606
- return polyAdd(a, polyScale(b, RATIONAL_MINUS_ONE));
607
- }
608
- function polyMul(a, b) {
609
- if (a.terms.size * b.terms.size > POLYNOMIAL_MAX_TERMS) return null;
610
- const terms = /* @__PURE__ */ new Map();
611
- for (const [leftKey, leftCoeff] of a.terms) {
612
- const leftMonomial = monomialFromKey(leftKey);
613
- for (const [rightKey, rightCoeff] of b.terms) {
614
- const combined = new Map(leftMonomial);
615
- for (const [name, exponent] of monomialFromKey(rightKey)) {
616
- combined.set(name, (combined.get(name) ?? 0) + exponent);
617
- }
618
- const key = monomialToKey(combined);
619
- const coeff = rationalMul(leftCoeff, rightCoeff);
620
- const existing = terms.get(key);
621
- terms.set(key, existing === void 0 ? coeff : rationalAdd(existing, coeff));
622
- }
623
- }
624
- return build(terms);
625
- }
626
- function polyPow(p, exponent) {
627
- if (exponent < 0 || !Number.isInteger(exponent) || exponent > EXPAND_MAX_POW_EXPONENT) return null;
628
- let result = constantPolynomial(RATIONAL_ONE);
629
- for (let i = 0; i < exponent; i++) {
630
- const next = polyMul(result, p);
631
- if (next === null) return null;
632
- result = next;
633
- }
634
- return result;
635
- }
636
- function polyScale(p, k) {
637
- if (isRationalZero(k)) return { terms: /* @__PURE__ */ new Map(), vars: [] };
638
- const terms = /* @__PURE__ */ new Map();
639
- for (const [key, coeff] of p.terms) terms.set(key, rationalMul(coeff, k));
640
- return { terms, vars: p.vars };
641
- }
642
- function polyDegree(p, variable) {
643
- let highest = 0;
644
- for (const key of p.terms.keys()) {
645
- const degree = variable === void 0 ? monomialDegree(key) : monomialFromKey(key).get(variable) ?? 0;
646
- if (degree > highest) highest = degree;
647
- }
648
- return highest;
649
- }
650
- function polyUnivariateVar(p) {
651
- return p.vars.length === 1 ? p.vars[0] : null;
652
- }
653
- function polyCoefficients(p, variable) {
654
- const degree = polyDegree(p, variable);
655
- const coefficients = new Array(degree + 1).fill(RATIONAL_ZERO);
656
- for (const [key, coeff] of p.terms) {
657
- coefficients[monomialFromKey(key).get(variable) ?? 0] = coeff;
658
- }
659
- return coefficients;
660
- }
661
- function toPolynomial(node, allowDistribution = true) {
662
- switch (node.kind) {
663
- case "const":
664
- return constantPolynomial(node.value);
665
- case "var":
666
- return { terms: /* @__PURE__ */ new Map([[node.name, RATIONAL_ONE]]), vars: [node.name] };
667
- case "neg": {
668
- const operand = toPolynomial(node.operand, allowDistribution);
669
- return operand === null ? null : polyScale(operand, RATIONAL_MINUS_ONE);
670
- }
671
- case "add": {
672
- const left = toPolynomial(node.left, allowDistribution);
673
- const right = left === null ? null : toPolynomial(node.right, allowDistribution);
674
- return left === null || right === null ? null : polyAdd(left, right);
675
- }
676
- case "sub": {
677
- const left = toPolynomial(node.left, allowDistribution);
678
- const right = left === null ? null : toPolynomial(node.right, allowDistribution);
679
- return left === null || right === null ? null : polySub(left, right);
680
- }
681
- case "mul": {
682
- const left = toPolynomial(node.left, allowDistribution);
683
- const right = left === null ? null : toPolynomial(node.right, allowDistribution);
684
- if (left === null || right === null) return null;
685
- if (!allowDistribution && (left.terms.size > 1 || right.terms.size > 1)) return null;
686
- return polyMul(left, right);
687
- }
688
- case "div": {
689
- const right = toPolynomial(node.right, allowDistribution);
690
- if (right === null || right.vars.length > 0) return null;
691
- const divisor = right.terms.get("") ?? RATIONAL_ZERO;
692
- if (isRationalZero(divisor)) return null;
693
- const left = toPolynomial(node.left, allowDistribution);
694
- return left === null ? null : polyScale(left, rationalDiv(RATIONAL_ONE, divisor));
695
- }
696
- case "pow": {
697
- if (node.exponent.kind !== "const" || !isRationalInteger(node.exponent.value)) return null;
698
- const exponent = Number(node.exponent.value.n);
699
- const base = toPolynomial(node.base, allowDistribution);
700
- if (base === null) return null;
701
- if (!allowDistribution && base.terms.size > 1) return null;
702
- return polyPow(base, exponent);
703
- }
704
- case "complex":
705
- return null;
706
- case "call":
707
- return null;
708
- }
709
- }
710
- function compareMonomials(a, b, vars) {
711
- const degreeDifference = monomialDegree(b) - monomialDegree(a);
712
- if (degreeDifference !== 0) return degreeDifference;
713
- const left = monomialFromKey(a);
714
- const right = monomialFromKey(b);
715
- for (const name of vars) {
716
- const difference = (right.get(name) ?? 0) - (left.get(name) ?? 0);
717
- if (difference !== 0) return difference;
718
- }
719
- return 0;
720
- }
721
- function monomialToNode(key) {
722
- const monomial = monomialFromKey(key);
723
- const names = [...monomial.keys()].sort();
724
- let result = null;
725
- for (const name of names) {
726
- const exponent = monomial.get(name);
727
- const factor = exponent === 1 ? varNode(name) : powNode(varNode(name), constNode({ n: BigInt(exponent), d: 1n }));
728
- result = result === null ? factor : { kind: "mul", left: result, right: factor };
729
- }
730
- return result ?? constNode(RATIONAL_ONE);
731
- }
732
- function termToNode(key, coeff) {
733
- if (key === "") return constNode(coeff);
734
- const magnitude = coeff.n < 0n ? rationalNeg(coeff) : coeff;
735
- const monomial = monomialToNode(key);
736
- const positive = isRationalOne(magnitude) ? monomial : { kind: "mul", left: constNode(magnitude), right: monomial };
737
- return coeff.n < 0n ? { kind: "neg", operand: positive } : positive;
738
- }
739
- function fromPolynomial(p) {
740
- const keys = [...p.terms.keys()].sort((a, b) => compareMonomials(a, b, p.vars));
741
- if (keys.length === 0) return constNode(RATIONAL_ZERO);
742
- if (p.terms.get(keys[0]).n < 0n) {
743
- const firstPositive = keys.findIndex((key) => p.terms.get(key).n > 0n);
744
- if (firstPositive > 0) keys.unshift(...keys.splice(firstPositive, 1));
745
- }
746
- let result = termToNode(keys[0], p.terms.get(keys[0]));
747
- for (let i = 1; i < keys.length; i++) {
748
- const coeff = p.terms.get(keys[i]);
749
- if (coeff.n < 0n) {
750
- result = { kind: "sub", left: result, right: termToNode(keys[i], rationalNeg(coeff)) };
751
- } else {
752
- result = { kind: "add", left: result, right: termToNode(keys[i], coeff) };
753
- }
754
- }
755
- return result;
756
- }
757
- function expandSymbolic(node) {
758
- const polynomial = toPolynomial(node);
759
- return polynomial === null ? node : fromPolynomial(polynomial);
760
- }
761
-
762
- // src/symbolic/Gcd.ts
763
- function trim(coefficients) {
764
- let last = coefficients.length - 1;
765
- while (last >= 0 && isRationalZero(coefficients[last])) last--;
766
- return coefficients.slice(0, last + 1);
767
- }
768
- function isZeroPolynomial(coefficients) {
769
- return coefficients.every(isRationalZero);
770
- }
771
- function polynomialDivide(dividend, divisor) {
772
- const numerator = trim([...dividend]);
773
- const denominator = trim([...divisor]);
774
- if (denominator.length === 0) throw new Error("polynomialDivide: division by the zero polynomial");
775
- const divisorDegree = denominator.length - 1;
776
- const leading = denominator[divisorDegree];
777
- const remainder = [...numerator];
778
- const quotient = new Array(Math.max(0, numerator.length - divisorDegree)).fill(RATIONAL_ZERO);
779
- for (let degree = remainder.length - 1; degree >= divisorDegree; degree--) {
780
- if (isRationalZero(remainder[degree])) continue;
781
- const factor = rationalDiv(remainder[degree], leading);
782
- const offset = degree - divisorDegree;
783
- quotient[offset] = factor;
784
- for (let i = 0; i <= divisorDegree; i++) {
785
- remainder[offset + i] = rationalSub(remainder[offset + i], rationalMul(factor, denominator[i]));
786
- }
787
- }
788
- return { quotient: trim(quotient), remainder: trim(remainder) };
789
- }
790
- function monic(coefficients) {
791
- const trimmed = trim(coefficients);
792
- if (trimmed.length === 0) return trimmed;
793
- const leading = trimmed[trimmed.length - 1];
794
- if (isRationalOne(leading)) return trimmed;
795
- return trimmed.map((coefficient) => rationalDiv(coefficient, leading));
796
- }
797
- function coefficientGcd(a, b) {
798
- let left = trim([...a]);
799
- let right = trim([...b]);
800
- while (right.length > 0) {
801
- const { remainder } = polynomialDivide(left, right);
802
- left = right;
803
- right = remainder;
804
- }
805
- return monic(left);
806
- }
807
- function polynomialGcd(a, b) {
808
- const variable = sharedVariable(a, b);
809
- if (variable === void 0) return null;
810
- if (variable === null) return toPolynomial({ kind: "const", value: RATIONAL_ONE });
811
- const gcd2 = coefficientGcd(polyCoefficients(a, variable), polyCoefficients(b, variable));
812
- return coefficientsToPolynomial(gcd2, variable);
813
- }
814
- function sharedVariable(a, b) {
815
- const names = /* @__PURE__ */ new Set([...a.vars, ...b.vars]);
816
- if (names.size === 0) return null;
817
- if (names.size > 1) return void 0;
818
- return [...names][0];
819
- }
820
- function coefficientsToPolynomial(coefficients, variable) {
821
- const terms = /* @__PURE__ */ new Map();
822
- coefficients.forEach((coefficient, power) => {
823
- if (isRationalZero(coefficient)) return;
824
- terms.set(power === 0 ? "" : power === 1 ? variable : `${variable}^${power}`, coefficient);
825
- });
826
- return { terms, vars: terms.size > 0 && coefficients.length > 1 ? [variable] : [] };
827
- }
828
- function cancelRational(numerator, denominator) {
829
- const gcd2 = polynomialGcd(numerator, denominator);
830
- if (gcd2 === null) return null;
831
- if (polyDegree(gcd2) === 0) return null;
832
- const variable = polyUnivariateVar(gcd2);
833
- if (variable === null) return null;
834
- const gcdCoefficients = polyCoefficients(gcd2, variable);
835
- const reducedNumerator = polynomialDivide(polyCoefficients(numerator, variable), gcdCoefficients);
836
- const reducedDenominator = polynomialDivide(polyCoefficients(denominator, variable), gcdCoefficients);
837
- return {
838
- numerator: coefficientsToPolynomial(reducedNumerator.quotient, variable),
839
- denominator: coefficientsToPolynomial(reducedDenominator.quotient, variable)
840
- };
841
- }
842
- function cancelSymbolic(node) {
843
- if (node.kind !== "div") return node;
844
- const numerator = toPolynomial(node.left);
845
- const denominator = toPolynomial(node.right);
846
- if (numerator === null || denominator === null) return node;
847
- const reduced = cancelRational(numerator, denominator);
848
- if (reduced === null) return node;
849
- return divideOutConstant(reduced.numerator, reduced.denominator, node);
850
- }
851
- function divideOutConstant(numerator, denominator, original) {
852
- if (polyDegree(denominator) === 0) {
853
- const constant = denominator.terms.get("") ?? RATIONAL_ONE;
854
- if (isRationalZero(constant)) return original;
855
- const scaled = /* @__PURE__ */ new Map();
856
- for (const [key, coefficient] of numerator.terms) scaled.set(key, rationalDiv(coefficient, constant));
857
- return fromPolynomial({ terms: scaled, vars: numerator.vars });
858
- }
859
- return { kind: "div", left: fromPolynomial(numerator), right: fromPolynomial(denominator) };
860
- }
861
- function squareFreePart(coefficients) {
862
- const trimmed = trim([...coefficients]);
863
- if (trimmed.length <= 1) return monic(trimmed);
864
- const derivative = [];
865
- for (let power = 1; power < trimmed.length; power++) {
866
- derivative.push(rationalMul(trimmed[power], { n: BigInt(power), d: 1n }));
867
- }
868
- const shared = coefficientGcd(trimmed, derivative);
869
- if (shared.length <= 1) return monic(trimmed);
870
- return monic(polynomialDivide(trimmed, shared).quotient);
871
- }
872
-
873
- // src/symbolic/Radicals.ts
874
- function exactIntegerSqrt(value) {
875
- if (value < 0n) return null;
876
- if (value < 2n) return value;
877
- let previous = value;
878
- let current = (value + 1n) / 2n;
879
- while (current < previous) {
880
- previous = current;
881
- current = (previous + value / previous) / 2n;
882
- }
883
- return previous * previous === value ? previous : null;
884
- }
885
- function exactIntegerCbrt(value) {
886
- const negative = value < 0n;
887
- const magnitude = negative ? -value : value;
888
- if (magnitude < 2n) return negative ? -magnitude : magnitude;
889
- let low = 1n;
890
- let high = magnitude;
891
- while (low <= high) {
892
- const middle = (low + high) / 2n;
893
- const cube = middle * middle * middle;
894
- if (cube === magnitude) return negative ? -middle : middle;
895
- if (cube < magnitude) low = middle + 1n;
896
- else high = middle - 1n;
897
- }
898
- return null;
899
- }
900
- function exactRationalSqrt2(value) {
901
- const numerator = exactIntegerSqrt(value.n);
902
- const denominator = exactIntegerSqrt(value.d);
903
- return numerator === null || denominator === null ? null : { n: numerator, d: denominator };
904
- }
905
- function surdNode(value) {
906
- const radicand = value.n * value.d;
907
- let extracted = 1n;
908
- let remaining = radicand;
909
- for (let factor = 2n; factor * factor <= remaining; factor++) {
910
- const square = factor * factor;
911
- while (remaining % square === 0n) {
912
- remaining /= square;
913
- extracted *= factor;
914
- }
915
- }
916
- const scale = rational(extracted, value.d);
917
- if (remaining === 1n) return constNode(scale);
918
- const root = { kind: "call", name: "sqrt", args: [constNode({ n: remaining, d: 1n })] };
919
- return scale.n === 1n && scale.d === 1n ? root : { kind: "mul", left: constNode(scale), right: root };
920
- }
921
- function signedSurdNode(value) {
922
- if (value.n >= 0n) return surdNode(value);
923
- return { kind: "call", name: "sqrt", args: [constNode(value)] };
924
- }
925
-
926
- // src/symbolic/Simplify.ts
927
- function flattenSum(node, negated, out, depth = 0) {
928
- if (depth >= MAX_SIMPLIFY_DEPTH) return false;
929
- switch (node.kind) {
930
- case "add":
931
- return flattenSum(node.left, negated, out, depth + 1) && flattenSum(node.right, negated, out, depth + 1);
932
- case "sub":
933
- return flattenSum(node.left, negated, out, depth + 1) && flattenSum(node.right, !negated, out, depth + 1);
934
- case "neg":
935
- return flattenSum(node.operand, !negated, out, depth + 1);
936
- case "const":
937
- out.push({ coeff: negated ? rationalNeg(node.value) : node.value, name: null });
938
- return true;
939
- case "var":
940
- out.push({ coeff: negated ? RATIONAL_MINUS_ONE : RATIONAL_ONE, name: node.name });
941
- return true;
942
- default:
943
- return false;
944
- }
945
- }
946
- function collectTerms(node) {
947
- const flat = [];
948
- if (!flattenSum(node, false, flat)) return node;
949
- const order = [];
950
- const coeffByName = /* @__PURE__ */ new Map();
951
- let constant = RATIONAL_ZERO;
952
- for (const term of flat) {
953
- if (term.name === null) {
954
- constant = rationalAdd(constant, term.coeff);
955
- continue;
956
- }
957
- const existing = coeffByName.get(term.name);
958
- if (existing === void 0) {
959
- order.push(term.name);
960
- coeffByName.set(term.name, term.coeff);
961
- } else {
962
- coeffByName.set(term.name, rationalAdd(existing, term.coeff));
963
- }
964
- }
965
- const termNodes = [];
966
- for (const name of order) {
967
- const coeff = coeffByName.get(name);
968
- if (isRationalZero(coeff)) continue;
969
- if (isRationalOne(coeff)) termNodes.push(varNode(name));
970
- else if (isRationalMinusOne(coeff)) termNodes.push({ kind: "neg", operand: varNode(name) });
971
- else termNodes.push({ kind: "mul", left: constNode(coeff), right: varNode(name) });
972
- }
973
- if (termNodes.length === 0) return constNode(constant);
974
- let result = termNodes[0];
975
- for (let i = 1; i < termNodes.length; i++) {
976
- result = { kind: "add", left: result, right: termNodes[i] };
977
- }
978
- if (!isRationalZero(constant)) {
979
- result = { kind: "add", left: result, right: constNode(constant) };
980
- }
981
- return result;
982
- }
983
- function collectSum(node) {
984
- const polynomial = toPolynomial(node, false);
985
- if (polynomial !== null) return fromPolynomial(polynomial);
986
- return collectTerms(node);
987
- }
988
- function rationalFloor(r) {
989
- const truncated = r.n / r.d;
990
- return r.n < 0n && truncated * r.d !== r.n ? truncated - 1n : truncated;
991
- }
992
- var MAX_FOLDED_FACTORIAL = 500n;
993
- function foldCall(name, args) {
994
- const first = args[0];
995
- switch (name) {
996
- case "abs":
997
- return args.length === 1 ? first.n < 0n ? rationalNeg(first) : first : null;
998
- case "sign":
999
- if (args.length !== 1) return null;
1000
- return first.n === 0n ? RATIONAL_ZERO : { n: first.n < 0n ? -1n : 1n, d: 1n };
1001
- case "floor":
1002
- return args.length === 1 ? { n: rationalFloor(first), d: 1n } : null;
1003
- case "ceil":
1004
- return args.length === 1 ? { n: -rationalFloor(rationalNeg(first)), d: 1n } : null;
1005
- case "trunc":
1006
- return args.length === 1 ? { n: first.n / first.d, d: 1n } : null;
1007
- case "round":
1008
- return args.length === 1 ? { n: rationalFloor(rationalAdd(first, { n: 1n, d: 2n })), d: 1n } : null;
1009
- case "sqrt": {
1010
- if (args.length !== 1 || first.n < 0n) return null;
1011
- const rootN = exactIntegerSqrt(first.n);
1012
- const rootD = exactIntegerSqrt(first.d);
1013
- return rootN === null || rootD === null ? null : { n: rootN, d: rootD };
1014
- }
1015
- case "cbrt": {
1016
- if (args.length !== 1) return null;
1017
- const rootN = exactIntegerCbrt(first.n);
1018
- const rootD = exactIntegerCbrt(first.d);
1019
- return rootN === null || rootD === null ? null : { n: rootN, d: rootD };
1020
- }
1021
- // Exact values at the points where these functions are rational. Every
1022
- // entry is exact, not rounded, which is what lets a Taylor series about
1023
- // the origin come out with exact coefficients. Deliberately narrow:
1024
- // `sin(1)` and `log(2)` are irrational and must stay symbolic.
1025
- case "sin":
1026
- case "tan":
1027
- case "asin":
1028
- case "atan":
1029
- case "sinh":
1030
- case "tanh":
1031
- return args.length === 1 && isRationalZero(first) ? RATIONAL_ZERO : null;
1032
- case "cos":
1033
- case "exp":
1034
- case "cosh":
1035
- return args.length === 1 && isRationalZero(first) ? RATIONAL_ONE : null;
1036
- case "log":
1037
- return args.length === 1 && isRationalOne(first) ? RATIONAL_ZERO : null;
1038
- case "acos":
1039
- return args.length === 1 && isRationalOne(first) ? RATIONAL_ZERO : null;
1040
- case "fact": {
1041
- if (args.length !== 1 || !isRationalInteger(first) || first.n < 0n || first.n > MAX_FOLDED_FACTORIAL) return null;
1042
- let total = 1n;
1043
- for (let i = 2n; i <= first.n; i++) total *= i;
1044
- return { n: total, d: 1n };
1045
- }
1046
- default:
1047
- return null;
1048
- }
1049
- }
1050
- function simplifySymbolic(node) {
1051
- if (nodeCount(node, SYMBOLIC_MAX_NODES) > SYMBOLIC_MAX_NODES) {
1052
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution(
1053
- "SYMBOLIC_NODE_LIMIT_EXCEEDED",
1054
- `This symbolic expression is too large to simplify (over ${SYMBOLIC_MAX_NODES} terms).`,
1055
- { limit: SYMBOLIC_MAX_NODES }
1056
- );
1057
- }
1058
- const depthOnEntry = walkDepth;
1059
- try {
1060
- return simplifyNode(node);
1061
- } finally {
1062
- walkDepth = depthOnEntry;
1063
- }
1064
- }
1065
- var MAX_SIMPLIFY_DEPTH = 900;
1066
- var walkDepth = 0;
1067
- function simplifyNode(node) {
1068
- if (walkDepth >= MAX_SIMPLIFY_DEPTH) return node;
1069
- walkDepth++;
1070
- const simplified = simplifyNodeAt(node);
1071
- walkDepth--;
1072
- return simplified;
1073
- }
1074
- function asComplex(node) {
1075
- if (node.kind === "complex") return node.value;
1076
- if (node.kind === "const") return complex(node.value);
1077
- return null;
1078
- }
1079
- function foldComplexBinary(kind, left, right) {
1080
- if (left.kind !== "complex" && right.kind !== "complex") return null;
1081
- const a = asComplex(left);
1082
- const b = asComplex(right);
1083
- if (a === null || b === null) return null;
1084
- switch (kind) {
1085
- case "add":
1086
- return complexNode(complexAdd(a, b));
1087
- case "sub":
1088
- return complexNode(complexSub(a, b));
1089
- case "mul":
1090
- return complexNode(complexMul(a, b));
1091
- case "div":
1092
- return isComplexZero(b) ? null : complexNode(complexDiv(a, b));
1093
- }
1094
- }
1095
- function foldComplexCall(name, args) {
1096
- if (args.length !== 1) return null;
1097
- const value = asComplex(args[0]);
1098
- if (value === null) return null;
1099
- switch (name) {
1100
- case "sqrt": {
1101
- const root = exactComplexSqrt(value);
1102
- if (root !== null) return complexNode(root);
1103
- if (isRationalZero(value.im) && value.re.n < 0n) {
1104
- return {
1105
- kind: "mul",
1106
- left: { kind: "call", name: "sqrt", args: [constNode(rationalNeg(value.re))] },
1107
- right: complexNode(COMPLEX_I)
1108
- };
1109
- }
1110
- return null;
1111
- }
1112
- case "conj":
1113
- return complexNode(complexConjugate(value));
1114
- case "re":
1115
- return constNode(value.re);
1116
- case "im":
1117
- return constNode(value.im);
1118
- case "abs": {
1119
- if (isRationalZero(value.im)) return null;
1120
- const modulus = exactComplexSqrt(complex(complexNormSquared(value)));
1121
- return modulus === null || !isRationalZero(modulus.im) ? null : constNode(modulus.re);
1122
- }
1123
- default:
1124
- return null;
1125
- }
1126
- }
1127
- function simplifyNodeAt(node) {
1128
- switch (node.kind) {
1129
- case "const":
1130
- case "complex":
1131
- case "var":
1132
- return node;
1133
- case "neg": {
1134
- const operand = simplifyNode(node.operand);
1135
- if (operand.kind === "const") return constNode(rationalNeg(operand.value));
1136
- if (operand.kind === "complex") return complexNode(complexNeg(operand.value));
1137
- if (operand.kind === "neg") return operand.operand;
1138
- return { kind: "neg", operand };
1139
- }
1140
- case "add": {
1141
- const left = simplifyNode(node.left);
1142
- const right = simplifyNode(node.right);
1143
- if (left.kind === "const" && right.kind === "const") return constNode(rationalAdd(left.value, right.value));
1144
- const foldedAdd = foldComplexBinary("add", left, right);
1145
- if (foldedAdd !== null) return foldedAdd;
1146
- if (left.kind === "const" && isRationalZero(left.value)) return right;
1147
- if (right.kind === "const" && isRationalZero(right.value)) return left;
1148
- return collectSum({ kind: "add", left, right });
1149
- }
1150
- case "sub": {
1151
- const left = simplifyNode(node.left);
1152
- const right = simplifyNode(node.right);
1153
- if (left.kind === "const" && right.kind === "const") return constNode(rationalSub(left.value, right.value));
1154
- const foldedSub = foldComplexBinary("sub", left, right);
1155
- if (foldedSub !== null) return foldedSub;
1156
- if (right.kind === "const" && isRationalZero(right.value)) return left;
1157
- if (left.kind === "const" && isRationalZero(left.value)) return simplifyNode({ kind: "neg", operand: right });
1158
- return collectSum({ kind: "sub", left, right });
1159
- }
1160
- case "mul": {
1161
- const left = simplifyNode(node.left);
1162
- const right = simplifyNode(node.right);
1163
- if (left.kind === "const" && right.kind === "const") return constNode(rationalMul(left.value, right.value));
1164
- const foldedMul = foldComplexBinary("mul", left, right);
1165
- if (foldedMul !== null) return foldedMul;
1166
- if (left.kind === "const" && isRationalZero(left.value) || right.kind === "const" && isRationalZero(right.value)) {
1167
- return constNode(RATIONAL_ZERO);
1168
- }
1169
- if (left.kind === "const" && isRationalOne(left.value)) return right;
1170
- if (right.kind === "const" && isRationalOne(right.value)) return left;
1171
- if (left.kind === "const" && isRationalMinusOne(left.value)) return simplifyNode({ kind: "neg", operand: right });
1172
- if (right.kind === "const" && isRationalMinusOne(right.value)) return simplifyNode({ kind: "neg", operand: left });
1173
- if (left.kind === "const" && right.kind === "mul" && right.left.kind === "const") {
1174
- return simplifyNode({ kind: "mul", left: constNode(rationalMul(left.value, right.left.value)), right: right.right });
1175
- }
1176
- if (right.kind === "const" && left.kind === "mul" && left.left.kind === "const") {
1177
- return simplifyNode({ kind: "mul", left: constNode(rationalMul(right.value, left.left.value)), right: left.right });
1178
- }
1179
- if (left.kind === "div" && left.left.kind === "const" && isRationalOne(left.left.value)) {
1180
- return simplifyNode({ kind: "div", left: right, right: left.right });
1181
- }
1182
- if (right.kind === "div" && right.left.kind === "const" && isRationalOne(right.left.value)) {
1183
- return simplifyNode({ kind: "div", left, right: right.right });
1184
- }
1185
- return { kind: "mul", left, right };
1186
- }
1187
- case "div": {
1188
- const left = simplifyNode(node.left);
1189
- const right = simplifyNode(node.right);
1190
- if (left.kind === "const" && right.kind === "const" && !isRationalZero(right.value)) {
1191
- return constNode(rationalDiv(left.value, right.value));
1192
- }
1193
- const foldedDiv = foldComplexBinary("div", left, right);
1194
- if (foldedDiv !== null) return foldedDiv;
1195
- if (right.kind === "const" && isRationalOne(right.value)) return left;
1196
- if (left.kind === "const" && isRationalZero(left.value)) return constNode(RATIONAL_ZERO);
1197
- if (left.kind === "mul") {
1198
- if (nodesEqual(left.left, right)) return left.right;
1199
- if (nodesEqual(left.right, right)) return left.left;
1200
- }
1201
- const cancelled = cancelSymbolic({ kind: "div", left, right });
1202
- if (cancelled.kind !== "div" || cancelled.left !== left || cancelled.right !== right) {
1203
- return simplifyNode(cancelled);
1204
- }
1205
- if (left.kind === "neg" && left.operand.kind === "mul") {
1206
- const product = left.operand;
1207
- if (nodesEqual(product.left, right)) return simplifyNode({ kind: "neg", operand: product.right });
1208
- if (nodesEqual(product.right, right)) return simplifyNode({ kind: "neg", operand: product.left });
1209
- }
1210
- return { kind: "div", left, right };
1211
- }
1212
- case "pow": {
1213
- const base = simplifyNode(node.base);
1214
- const exponent = simplifyNode(node.exponent);
1215
- if (exponent.kind === "const") {
1216
- if (isRationalZero(exponent.value)) return constNode(RATIONAL_ONE);
1217
- if (isRationalOne(exponent.value)) return base;
1218
- if (base.kind === "const" && isRationalInteger(exponent.value)) {
1219
- return constNode(rationalPow(base.value, exponent.value.n));
1220
- }
1221
- if (base.kind === "complex" && isRationalInteger(exponent.value)) {
1222
- return complexNode(complexPow(base.value, exponent.value.n));
1223
- }
1224
- }
1225
- if (base.kind === "const" && isRationalOne(base.value)) return constNode(RATIONAL_ONE);
1226
- if (base.kind === "const" && isRationalZero(base.value) && exponent.kind === "const" && exponent.value.n > 0n) {
1227
- return constNode(RATIONAL_ZERO);
1228
- }
1229
- if (base.kind === "pow" && base.exponent.kind === "const" && exponent.kind === "const" && isRationalInteger(base.exponent.value) && isRationalInteger(exponent.value)) {
1230
- return simplifyNode({
1231
- kind: "pow",
1232
- base: base.base,
1233
- exponent: constNode(rationalMul(base.exponent.value, exponent.value))
1234
- });
1235
- }
1236
- return { kind: "pow", base, exponent };
1237
- }
1238
- case "call": {
1239
- const args = node.args.map(simplifyNode);
1240
- if (args.every((arg) => arg.kind === "const")) {
1241
- const folded = foldCall(node.name, args.map((arg) => arg.value));
1242
- if (folded !== null) return constNode(folded);
1243
- }
1244
- const complexFolded = foldComplexCall(node.name, args);
1245
- if (complexFolded !== null) return complexFolded;
1246
- return { kind: "call", name: node.name, args };
1247
- }
1248
- }
1249
- }
1250
-
1251
- // src/symbolic/SymbolicFormat.ts
1252
- function tryExtractCoeffVar(node) {
1253
- if (node.left.kind === "const" && node.right.kind === "var") return { coeff: node.left.value, name: node.right.name };
1254
- if (node.right.kind === "const" && node.left.kind === "var") return { coeff: node.right.value, name: node.left.name };
1255
- return null;
1256
- }
1257
- function tryExtractCoeffPow(node) {
1258
- if (node.left.kind === "const" && node.right.kind === "pow") return { coeff: node.left.value, power: node.right };
1259
- if (node.right.kind === "const" && node.left.kind === "pow") return { coeff: node.right.value, power: node.left };
1260
- return null;
1261
- }
1262
- function isAtomic(node) {
1263
- if (node.kind === "var" || node.kind === "call") return true;
1264
- return node.kind === "const" && node.value.n >= 0n;
1265
- }
1266
- function formatCoefficient(coeff, text) {
1267
- if (coeff.n === 1n && coeff.d === 1n) return text;
1268
- if (coeff.n === -1n && coeff.d === 1n) return `-${text}`;
1269
- return `${formatRational(coeff)}${text}`;
1270
- }
1271
- var MAX_FORMAT_DEPTH = 600;
1272
- var ELIDED = "...";
1273
- function formatFactor(node, depth) {
1274
- if (depth >= MAX_FORMAT_DEPTH) return ELIDED;
1275
- switch (node.kind) {
1276
- case "const":
1277
- return formatRational(node.value);
1278
- case "complex":
1279
- return node.value.re.n !== 0n && node.value.im.n !== 0n ? `(${formatComplex(node.value)})` : formatComplex(node.value);
1280
- case "var":
1281
- return node.name;
1282
- case "add":
1283
- case "sub":
1284
- return `(${formatSum(node, depth)})`;
1285
- case "neg":
1286
- return `-${formatFactor(node.operand, depth + 1)}`;
1287
- case "call":
1288
- return `${node.name}(${node.args.map((arg) => formatSum(arg, depth + 1)).join(", ")})`;
1289
- case "pow": {
1290
- const base = isAtomic(node.base) ? formatFactor(node.base, depth + 1) : `(${formatSum(node.base, depth + 1)})`;
1291
- const exponent = isAtomic(node.exponent) ? formatFactor(node.exponent, depth + 1) : `(${formatSum(node.exponent, depth + 1)})`;
1292
- return `${base}^${exponent}`;
1293
- }
1294
- case "mul": {
1295
- const coeffVar = tryExtractCoeffVar(node);
1296
- if (coeffVar) return formatCoefficient(coeffVar.coeff, coeffVar.name);
1297
- const coeffPow = tryExtractCoeffPow(node);
1298
- if (coeffPow) return formatCoefficient(coeffPow.coeff, formatFactor(coeffPow.power, depth + 1));
1299
- if (node.left.kind === "const" && node.right.kind === "mul") {
1300
- const inner = formatFactor(node.right, depth + 1);
1301
- if (!/^[\d.]/.test(inner)) return formatCoefficient(node.left.value, inner);
1302
- }
1303
- return `${formatFactor(node.left, depth + 1)}*${formatFactor(node.right, depth + 1)}`;
1304
- }
1305
- case "div": {
1306
- const denominator = formatFactor(node.right, depth + 1);
1307
- const needsBrackets = node.right.kind === "mul" || node.right.kind === "div";
1308
- return `${formatFactor(node.left, depth + 1)}/${needsBrackets ? `(${denominator})` : denominator}`;
1309
- }
1310
- }
1311
- }
1312
- function collectDisplayTerms(node, negated, out, depth) {
1313
- if (depth >= MAX_FORMAT_DEPTH) {
1314
- out.push({ negated, text: ELIDED });
1315
- return;
1316
- }
1317
- switch (node.kind) {
1318
- case "add":
1319
- collectDisplayTerms(node.left, negated, out, depth + 1);
1320
- collectDisplayTerms(node.right, negated, out, depth + 1);
1321
- return;
1322
- case "sub":
1323
- collectDisplayTerms(node.left, negated, out, depth + 1);
1324
- collectDisplayTerms(node.right, !negated, out, depth + 1);
1325
- return;
1326
- case "neg":
1327
- collectDisplayTerms(node.operand, !negated, out, depth + 1);
1328
- return;
1329
- case "const": {
1330
- if (node.value.n === 0n) return;
1331
- const isNegative = node.value.n < 0n;
1332
- const magnitude = isNegative ? { n: -node.value.n, d: node.value.d } : node.value;
1333
- out.push({ negated: isNegative !== negated, text: formatRational(magnitude) });
1334
- return;
1335
- }
1336
- case "complex": {
1337
- const { re, im } = node.value;
1338
- if (re.n !== 0n) {
1339
- const negativeReal = re.n < 0n;
1340
- out.push({ negated: negativeReal !== negated, text: formatRational(negativeReal ? { n: -re.n, d: re.d } : re) });
1341
- }
1342
- if (im.n !== 0n) {
1343
- const negativeImaginary = im.n < 0n;
1344
- const magnitude = negativeImaginary ? { n: -im.n, d: im.d } : im;
1345
- const text = magnitude.n === 1n && magnitude.d === 1n ? "i" : `${formatRational(magnitude)}i`;
1346
- out.push({ negated: negativeImaginary !== negated, text });
1347
- }
1348
- return;
1349
- }
1350
- default: {
1351
- const text = formatFactor(node, depth);
1352
- const liftsSign = (node.kind === "mul" || node.kind === "div") && text.startsWith("-");
1353
- if (liftsSign) out.push({ negated: !negated, text: text.slice(1) });
1354
- else out.push({ negated, text });
1355
- }
1356
- }
1357
- }
1358
- function formatSymbolic(node) {
1359
- try {
1360
- return formatSum(node, 0);
1361
- } catch (thrown) {
1362
- if (thrown instanceof RangeError) return ELIDED;
1363
- throw thrown;
1364
- }
1365
- }
1366
- function formatSum(node, depth) {
1367
- const terms = [];
1368
- collectDisplayTerms(node, false, terms, depth);
1369
- if (terms.length === 0) return "0";
1370
- let out = "";
1371
- terms.forEach((term, index) => {
1372
- if (index === 0) out += term.negated ? `-${term.text}` : term.text;
1373
- else out += term.negated ? `-${term.text}` : `+${term.text}`;
1374
- });
1375
- return out;
1376
- }
1377
-
1378
- // src/vm/MatrixOps.ts
1379
- function matIndex(m, index) {
1380
- return m.data[index];
1381
- }
1382
- function matAt(m, row, col) {
1383
- return m.data[row + col * m.rows];
1384
- }
1385
- function inBounds(m, row, col) {
1386
- return row >= 0 && row < m.rows && col >= 0 && col < m.cols;
1387
- }
1388
- function sameShape(a, b) {
1389
- return a.rows === b.rows && a.cols === b.cols;
1390
- }
1391
- function isSquare(m) {
1392
- return m.rows === m.cols;
1393
- }
1394
- function entryToSymbolic(entry) {
1395
- if (typeof entry === "object" && entry !== null) return entry;
1396
- if (typeof entry === "boolean") return constNode(entry ? 1 : 0);
1397
- return constNode(entry);
1398
- }
1399
- function symbolicToEntry(node) {
1400
- const simplified = simplifySymbolic(node);
1401
- return simplified.kind === "const" ? rationalToNumber(simplified.value) : simplified;
1402
- }
1403
- function matrixEntryToValue(cell) {
1404
- if (typeof cell === "boolean") return chunkIT74O4BE_cjs.boolValue(cell);
1405
- if (typeof cell === "object" && cell !== null) return chunkIT74O4BE_cjs.symbolicValue(cell);
1406
- return chunkIT74O4BE_cjs.numberValue(cell);
1407
- }
1408
- function rowMajorToColumnMajor(rows, cols, rowMajorData) {
1409
- const data = new Array(rows * cols);
1410
- for (let r = 0; r < rows; r++) {
1411
- for (let c = 0; c < cols; c++) {
1412
- data[r + c * rows] = rowMajorData[r * cols + c];
1413
- }
1414
- }
1415
- return data;
1416
- }
1417
- function columnMajorToRowMajor(m) {
1418
- const data = new Array(m.rows * m.cols);
1419
- for (let r = 0; r < m.rows; r++) {
1420
- for (let c = 0; c < m.cols; c++) {
1421
- data[r * m.cols + c] = matAt(m, r, c);
1422
- }
1423
- }
1424
- return data;
1425
- }
1426
- function matrixMultiply(l, r) {
1427
- const lIsScalar = l.rows === 1 && l.cols === 1;
1428
- const rIsScalar = r.rows === 1 && r.cols === 1;
1429
- const useSymbolic = l.hasSymbolic || r.hasSymbolic;
1430
- if (lIsScalar || rIsScalar) {
1431
- const [scalarOperand, matrixOperand] = lIsScalar ? [l, r] : [r, l];
1432
- if (useSymbolic) {
1433
- const scalarNode = entryToSymbolic(scalarOperand.data[0]);
1434
- const result2 = matrixOperand.data.map((v) => symbolicToEntry(simplifySymbolic({ kind: "mul", left: entryToSymbolic(v), right: scalarNode })));
1435
- return chunkIT74O4BE_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result2);
1436
- }
1437
- const scalar = scalarOperand.data[0];
1438
- const result = matrixOperand.data.map((v) => v * scalar);
1439
- return chunkIT74O4BE_cjs.matrixValue(matrixOperand.rows, matrixOperand.cols, result);
1440
- }
1441
- if (l.cols !== r.rows) {
1442
- return chunkIT74O4BE_cjs.errorValue(
1443
- "DIMENSION_MISMATCH",
1444
- `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}).`
1445
- );
1446
- }
1447
- const resultRows = l.rows;
1448
- const resultCols = r.cols;
1449
- const data = chunkIT74O4BE_cjs.checkedArray(resultRows * resultCols, "matrix cells");
1450
- for (let row = 0; row < resultRows; row++) {
1451
- for (let col = 0; col < resultCols; col++) {
1452
- if (useSymbolic) {
1453
- let acc = constNode(0);
1454
- for (let k = 0; k < l.cols; k++) {
1455
- const term = { kind: "mul", left: entryToSymbolic(matAt(l, row, k)), right: entryToSymbolic(matAt(r, k, col)) };
1456
- acc = simplifySymbolic({ kind: "add", left: acc, right: term });
1457
- }
1458
- data[row + col * resultRows] = symbolicToEntry(acc);
1459
- } else {
1460
- let sum = 0;
1461
- for (let k = 0; k < l.cols; k++) {
1462
- sum += matAt(l, row, k) * matAt(r, k, col);
1463
- }
1464
- data[row + col * resultRows] = sum;
1465
- }
1466
- }
1467
- }
1468
- return chunkIT74O4BE_cjs.matrixValue(resultRows, resultCols, data);
1469
- }
1470
- function matrixPower(m, exponent) {
1471
- if (!isSquare(m)) {
1472
- return chunkIT74O4BE_cjs.errorValue("MATRIX_POWER_REQUIRES_SQUARE_MATRIX", `^: only a square matrix can be raised to a power (got ${m.rows}x${m.cols}).`);
1473
- }
1474
- if (!Number.isInteger(exponent) || exponent < 0) {
1475
- return chunkIT74O4BE_cjs.errorValue(
1476
- "MATRIX_POWER_REQUIRES_WHOLE_EXPONENT",
1477
- `^: a matrix can only be raised to a whole number of 0 or more (got ${exponent}); "^-1" means the inverse and "^T" the transpose.`
1478
- );
1479
- }
1480
- const n = m.rows;
1481
- const identity = new Array(n * n).fill(0);
1482
- for (let i = 0; i < n; i++) identity[i + i * n] = 1;
1483
- let accumulated = { rows: n, cols: n, data: identity, hasSymbolic: false };
1484
- let squared = m;
1485
- let remaining = exponent;
1486
- while (remaining > 0) {
1487
- if (remaining % 2 === 1) {
1488
- const product = matrixMultiply(accumulated, squared);
1489
- if (product.type === 13 /* Error */) return product;
1490
- accumulated = product.value;
1491
- }
1492
- remaining = Math.floor(remaining / 2);
1493
- if (remaining > 0) {
1494
- const doubled = matrixMultiply(squared, squared);
1495
- if (doubled.type === 13 /* Error */) return doubled;
1496
- squared = doubled.value;
1497
- }
1498
- }
1499
- return chunkIT74O4BE_cjs.matrixValue(accumulated.rows, accumulated.cols, accumulated.data);
1500
- }
1501
- function matrixCompare(l, r, cmp) {
1502
- if (!sameShape(l, r)) {
1503
- return chunkIT74O4BE_cjs.errorValue(
1504
- "DIMENSION_MISMATCH",
1505
- `Cannot compare matrices of different shapes: ${l.rows}x${l.cols} and ${r.rows}x${r.cols}`
1506
- );
1507
- }
1508
- const data = new Array(l.data.length);
1509
- for (let i = 0; i < l.data.length; i++) data[i] = cmp(l.data[i], r.data[i]);
1510
- return chunkIT74O4BE_cjs.matrixValue(l.rows, l.cols, data);
1511
- }
1512
- function transpose(m) {
1513
- const data = new Array(m.rows * m.cols);
1514
- for (let r = 0; r < m.cols; r++) {
1515
- for (let c = 0; c < m.rows; c++) {
1516
- data[r + c * m.cols] = matAt(m, c, r);
1517
- }
1518
- }
1519
- return chunkIT74O4BE_cjs.matrixValue(m.cols, m.rows, data);
1520
- }
1521
- function toWorkingRows(m) {
1522
- const rows = [];
1523
- for (let r = 0; r < m.rows; r++) {
1524
- const row = [];
1525
- for (let c = 0; c < m.cols; c++) row.push(matAt(m, r, c));
1526
- rows.push(row);
1527
- }
1528
- return rows;
1529
- }
1530
- var EXACT_DETERMINANT_DIMENSION_LIMIT = 12;
1531
- function toIntegerRows(m) {
1532
- if (m.rows > EXACT_DETERMINANT_DIMENSION_LIMIT) return null;
1533
- const rows = [];
1534
- for (let r = 0; r < m.rows; r++) {
1535
- const row = [];
1536
- for (let c = 0; c < m.cols; c++) {
1537
- const cell = matAt(m, r, c);
1538
- if (typeof cell !== "number" || !Number.isSafeInteger(cell)) return null;
1539
- row.push(BigInt(cell));
1540
- }
1541
- rows.push(row);
1542
- }
1543
- return rows;
1544
- }
1545
- function integerDeterminant(rows) {
1546
- const n = rows.length;
1547
- let previous = 1n;
1548
- let sign = 1n;
1549
- for (let k = 0; k < n - 1; k++) {
1550
- if (rows[k][k] === 0n) {
1551
- let candidate = -1;
1552
- for (let r = k + 1; r < n; r++) {
1553
- if (rows[r][k] !== 0n) {
1554
- candidate = r;
1555
- break;
1556
- }
1557
- }
1558
- if (candidate === -1) return 0n;
1559
- const swapped = rows[k];
1560
- rows[k] = rows[candidate];
1561
- rows[candidate] = swapped;
1562
- sign = -sign;
1563
- }
1564
- for (let i = k + 1; i < n; i++) {
1565
- for (let j = k + 1; j < n; j++) {
1566
- rows[i][j] = (rows[i][j] * rows[k][k] - rows[i][k] * rows[k][j]) / previous;
1567
- }
1568
- }
1569
- previous = rows[k][k];
1570
- }
1571
- return sign * rows[n - 1][n - 1];
1572
- }
1573
- function numericDeterminant(m) {
1574
- const integers = toIntegerRows(m);
1575
- if (integers !== null) return chunkIT74O4BE_cjs.numberValue(Number(integerDeterminant(integers)));
1576
- const n = m.rows;
1577
- const a = toWorkingRows(m);
1578
- let det = 1;
1579
- for (let col = 0; col < n; col++) {
1580
- let pivotRow = col;
1581
- let maxAbs = Math.abs(a[col][col]);
1582
- for (let r = col + 1; r < n; r++) {
1583
- if (Math.abs(a[r][col]) > maxAbs) {
1584
- maxAbs = Math.abs(a[r][col]);
1585
- pivotRow = r;
1586
- }
1587
- }
1588
- if (maxAbs === 0) return chunkIT74O4BE_cjs.numberValue(0);
1589
- if (pivotRow !== col) {
1590
- const tmp = a[col];
1591
- a[col] = a[pivotRow];
1592
- a[pivotRow] = tmp;
1593
- det = -det;
1594
- }
1595
- det *= a[col][col];
1596
- for (let r = col + 1; r < n; r++) {
1597
- const factor = a[r][col] / a[col][col];
1598
- if (factor === 0) continue;
1599
- for (let c = col; c < n; c++) a[r][c] -= factor * a[col][c];
1600
- }
1601
- }
1602
- return chunkIT74O4BE_cjs.numberValue(det);
1603
- }
1604
- function symbolicDeterminant(m) {
1605
- const n = m.rows;
1606
- const a = [];
1607
- for (let r = 0; r < n; r++) {
1608
- const row = [];
1609
- for (let c = 0; c < n; c++) row.push(entryToSymbolic(matAt(m, r, c)));
1610
- a.push(row);
1611
- }
1612
- let det = constNode(1);
1613
- for (let col = 0; col < n; col++) {
1614
- const pivot = simplifySymbolic(a[col][col]);
1615
- if (pivot.kind === "const" && isRationalZero(pivot.value)) return chunkIT74O4BE_cjs.numberValue(0);
1616
- det = simplifySymbolic({ kind: "mul", left: det, right: pivot });
1617
- for (let r = col + 1; r < n; r++) {
1618
- const factor = simplifySymbolic({ kind: "div", left: a[r][col], right: pivot });
1619
- for (let c = col; c < n; c++) {
1620
- a[r][c] = simplifySymbolic({ kind: "sub", left: a[r][c], right: { kind: "mul", left: factor, right: a[col][c] } });
1621
- }
1622
- }
1623
- }
1624
- return det.kind === "const" ? chunkIT74O4BE_cjs.numberValue(rationalToNumber(det.value)) : chunkIT74O4BE_cjs.symbolicValue(det);
1625
- }
1626
- function determinant(m) {
1627
- if (!isSquare(m)) {
1628
- return chunkIT74O4BE_cjs.errorValue("DETERMINANT_REQUIRES_SQUARE_MATRIX", `det: matrix must be square (got ${m.rows}x${m.cols}).`);
1629
- }
1630
- return m.hasSymbolic ? symbolicDeterminant(m) : numericDeterminant(m);
1631
- }
1632
- function numericInverse(m) {
1633
- const n = m.rows;
1634
- const a = toWorkingRows(m);
1635
- for (let r = 0; r < n; r++) {
1636
- for (let c = 0; c < n; c++) a[r].push(c === r ? 1 : 0);
1637
- }
1638
- for (let col = 0; col < n; col++) {
1639
- let pivotRow = col;
1640
- let maxAbs = Math.abs(a[col][col]);
1641
- for (let r = col + 1; r < n; r++) {
1642
- if (Math.abs(a[r][col]) > maxAbs) {
1643
- maxAbs = Math.abs(a[r][col]);
1644
- pivotRow = r;
1645
- }
1646
- }
1647
- if (maxAbs < 1e-10) {
1648
- return chunkIT74O4BE_cjs.errorValue("SINGULAR_MATRIX", `inv: a ${n}x${n} matrix with a zero (or near-zero) pivot column is not invertible.`);
1649
- }
1650
- if (pivotRow !== col) {
1651
- const tmp = a[col];
1652
- a[col] = a[pivotRow];
1653
- a[pivotRow] = tmp;
1654
- }
1655
- const pivot = a[col][col];
1656
- for (let c = 0; c < 2 * n; c++) a[col][c] /= pivot;
1657
- for (let r = 0; r < n; r++) {
1658
- if (r === col) continue;
1659
- const factor = a[r][col];
1660
- if (factor === 0) continue;
1661
- for (let c = 0; c < 2 * n; c++) a[r][c] -= factor * a[col][c];
1662
- }
1663
- }
1664
- const data = new Array(n * n);
1665
- for (let r = 0; r < n; r++) {
1666
- for (let c = 0; c < n; c++) data[r + c * n] = a[r][n + c];
1667
- }
1668
- return chunkIT74O4BE_cjs.matrixValue(n, n, data);
1669
- }
1670
- var SYMBOLIC_INVERSE_DIMENSION_LIMIT = 9;
1671
- function symbolicInverse(m) {
1672
- const n = m.rows;
1673
- if (n >= SYMBOLIC_INVERSE_DIMENSION_LIMIT) {
1674
- return chunkIT74O4BE_cjs.errorValue(
1675
- "SYMBOLIC_INVERSE_DIMENSION_LIMIT",
1676
- `Symbolic matrix inversion is limited to matrices smaller than ${SYMBOLIC_INVERSE_DIMENSION_LIMIT}x${SYMBOLIC_INVERSE_DIMENSION_LIMIT} (got ${n}x${n}).`
1677
- );
1678
- }
1679
- const a = [];
1680
- for (let r = 0; r < n; r++) {
1681
- const row = [];
1682
- for (let c = 0; c < n; c++) row.push(entryToSymbolic(matAt(m, r, c)));
1683
- for (let c = 0; c < n; c++) row.push(constNode(c === r ? 1 : 0));
1684
- a.push(row);
1685
- }
1686
- for (let col = 0; col < n; col++) {
1687
- const pivot = simplifySymbolic(a[col][col]);
1688
- if (pivot.kind === "const" && isRationalZero(pivot.value)) {
1689
- return chunkIT74O4BE_cjs.errorValue(
1690
- "SYMBOLIC_SINGULAR_OR_UNSUPPORTED_PIVOT",
1691
- `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.`
1692
- );
1693
- }
1694
- for (let r = 0; r < n; r++) {
1695
- if (r === col) continue;
1696
- const factor = simplifySymbolic({ kind: "div", left: a[r][col], right: pivot });
1697
- if (factor.kind === "const" && isRationalZero(factor.value)) continue;
1698
- for (let c = 0; c < 2 * n; c++) {
1699
- a[r][c] = simplifySymbolic({ kind: "sub", left: a[r][c], right: { kind: "mul", left: factor, right: a[col][c] } });
1700
- }
1701
- }
1702
- for (let c = 0; c < 2 * n; c++) {
1703
- a[col][c] = simplifySymbolic({ kind: "div", left: a[col][c], right: pivot });
1704
- }
1705
- }
1706
- const data = new Array(n * n);
1707
- for (let r = 0; r < n; r++) {
1708
- for (let c = 0; c < n; c++) data[r + c * n] = symbolicToEntry(a[r][n + c]);
1709
- }
1710
- return chunkIT74O4BE_cjs.matrixValue(n, n, data);
1711
- }
1712
- function inverse(m) {
1713
- if (!isSquare(m)) {
1714
- return chunkIT74O4BE_cjs.errorValue("INVERSE_REQUIRES_SQUARE_MATRIX", `inv: matrix must be square (got ${m.rows}x${m.cols}).`);
1715
- }
1716
- return m.hasSymbolic ? symbolicInverse(m) : numericInverse(m);
1717
- }
1718
- function tooLarge(length, maxElements) {
1719
- return chunkIT74O4BE_cjs.errorValue(
1720
- "COLLECTION_TOO_LARGE",
1721
- `This collection has ${length} elements, past the limit of ${maxElements} (see the engine's vm.maxCollectionSize setting).`
1722
- );
1723
- }
1724
- function collectionToValues(v, maxElements = Number.POSITIVE_INFINITY) {
1725
- const faulted = chunkIT74O4BE_cjs.faultedOperand(v);
1726
- if (faulted) return faulted;
1727
- if (v.type === 7 /* Matrix */) {
1728
- const m = v.value;
1729
- if (m.data.length > maxElements) return tooLarge(m.data.length, maxElements);
1730
- return m.data.map(matrixEntryToValue);
1731
- }
1732
- if (v.type === 8 /* Range */) {
1733
- const r = v.value;
1734
- const length = r.max - r.min + 1;
1735
- if (length > maxElements) return tooLarge(length, maxElements);
1736
- const out = new Array(length);
1737
- for (let i = 0; i < length; i++) out[i] = chunkIT74O4BE_cjs.numberValue(r.min + i);
1738
- return out;
1739
- }
1740
- return chunkIT74O4BE_cjs.errorValue(
1741
- "MAP_REDUCE_REQUIRES_COLLECTION",
1742
- `map/reduce requires a Matrix or Range collection (e.g. "[1,2,3]" or "0:3").`
1743
- );
1744
- }
1745
-
1746
- // src/uom/CurrencyAliases.ts
1747
- var CURRENCY_SYMBOL_ALIASES = {
1748
- "$": "USD",
1749
- "\xA3": "GBP",
1750
- "\u20AC": "EUR",
1751
- // ¥ is genuinely ambiguous between JPY and CNY in real-world usage, JPY
1752
- // is the conventional default (matches Numi/most calculator apps' own
1753
- // choice); a user wanting CNY specifically can still type "CNY" directly.
1754
- "\xA5": "JPY",
1755
- "\u20BD": "RUB",
1756
- "\u20A9": "KRW",
1757
- "\u20B9": "INR",
1758
- "\u20BA": "TRY",
1759
- "\u20B4": "UAH",
1760
- "\u20AA": "ILS",
1761
- "\u20AB": "VND",
1762
- "\u20A6": "NGN",
1763
- "\u20B1": "PHP"
1764
- };
1765
- var CURRENCY_WORD_ALIASES = {
1766
- dollar: "USD",
1767
- dollars: "USD",
1768
- euro: "EUR",
1769
- euros: "EUR",
1770
- yen: "JPY",
1771
- ruble: "RUB",
1772
- rubles: "RUB",
1773
- rouble: "RUB",
1774
- roubles: "RUB",
1775
- won: "KRW",
1776
- rupee: "INR",
1777
- rupees: "INR",
1778
- yuan: "CNY",
1779
- renminbi: "CNY",
1780
- franc: "CHF",
1781
- francs: "CHF",
1782
- rand: "ZAR",
1783
- krona: "SEK",
1784
- kronor: "SEK",
1785
- krone: "NOK",
1786
- kroner: "NOK",
1787
- real: "BRL",
1788
- reais: "BRL",
1789
- peso: "MXN",
1790
- pesos: "MXN",
1791
- shekel: "ILS",
1792
- shekels: "ILS",
1793
- lira: "TRY",
1794
- hryvnia: "UAH",
1795
- hryvnias: "UAH",
1796
- zloty: "PLN",
1797
- zlotys: "PLN",
1798
- forint: "HUF",
1799
- koruna: "CZK",
1800
- dirham: "AED",
1801
- dirhams: "AED",
1802
- riyal: "SAR",
1803
- riyals: "SAR",
1804
- rial: "SAR",
1805
- rials: "SAR",
1806
- ringgit: "MYR",
1807
- rupiah: "IDR",
1808
- baht: "THB",
1809
- dong: "VND",
1810
- naira: "NGN"
1811
- };
1812
- function resolveCurrencyAlias(text) {
1813
- return CURRENCY_SYMBOL_ALIASES[text] ?? CURRENCY_WORD_ALIASES[text.toLowerCase()];
1814
- }
1815
- var CURRENCY_DISPLAY = {
1816
- USD: { symbol: "$", position: "prefix", spaced: false },
1817
- AUD: { symbol: "$", position: "prefix", spaced: false },
1818
- CAD: { symbol: "$", position: "prefix", spaced: false },
1819
- NZD: { symbol: "$", position: "prefix", spaced: false },
1820
- HKD: { symbol: "$", position: "prefix", spaced: false },
1821
- SGD: { symbol: "$", position: "prefix", spaced: false },
1822
- MXN: { symbol: "$", position: "prefix", spaced: false },
1823
- GBP: { symbol: "\xA3", position: "prefix", spaced: false },
1824
- // English-language convention (€100.00), many EU locales instead suffix
1825
- // with a space ("100,00 €"); this engine's default locale is "en", so
1826
- // the English convention was chosen. A locale-aware override would be a
1827
- // reasonable future extension, not attempted here.
1828
- EUR: { symbol: "\u20AC", position: "prefix", spaced: false },
1829
- JPY: { symbol: "\xA5", position: "prefix", spaced: false },
1830
- CNY: { symbol: "\xA5", position: "prefix", spaced: false },
1831
- KRW: { symbol: "\u20A9", position: "prefix", spaced: false },
1832
- INR: { symbol: "\u20B9", position: "prefix", spaced: false },
1833
- // Russian convention places the ruble sign AFTER the amount, with a space.
1834
- RUB: { symbol: "\u20BD", position: "suffix", spaced: true },
1835
- TRY: { symbol: "\u20BA", position: "prefix", spaced: false },
1836
- UAH: { symbol: "\u20B4", position: "suffix", spaced: true },
1837
- ILS: { symbol: "\u20AA", position: "prefix", spaced: false },
1838
- // Vietnamese convention: no space, symbol after the amount.
1839
- VND: { symbol: "\u20AB", position: "suffix", spaced: false },
1840
- NGN: { symbol: "\u20A6", position: "prefix", spaced: false },
1841
- PHP: { symbol: "\u20B1", position: "prefix", spaced: false },
1842
- BRL: { symbol: "R$", position: "prefix", spaced: false },
1843
- ZAR: { symbol: "R", position: "prefix", spaced: false },
1844
- // Scandinavian convention: amount then "kr", space-separated.
1845
- SEK: { symbol: "kr", position: "suffix", spaced: true },
1846
- NOK: { symbol: "kr", position: "suffix", spaced: true },
1847
- DKK: { symbol: "kr", position: "suffix", spaced: true },
1848
- PLN: { symbol: "z\u0142", position: "suffix", spaced: true },
1849
- CHF: { symbol: "Fr", position: "suffix", spaced: true },
1850
- HUF: { symbol: "Ft", position: "suffix", spaced: true },
1851
- CZK: { symbol: "K\u010D", position: "suffix", spaced: true }
1852
- };
1853
-
1854
- exports.COMPLEX_I = COMPLEX_I;
1855
- exports.CURRENCY_DISPLAY = CURRENCY_DISPLAY;
1856
- exports.RATIONAL_ONE = RATIONAL_ONE;
1857
- exports.RATIONAL_ZERO = RATIONAL_ZERO;
1858
- exports.callNode = callNode;
1859
- exports.cancelSymbolic = cancelSymbolic;
1860
- exports.coefficientGcd = coefficientGcd;
1861
- exports.collectionToValues = collectionToValues;
1862
- exports.columnMajorToRowMajor = columnMajorToRowMajor;
1863
- exports.compareMonomials = compareMonomials;
1864
- exports.complex = complex;
1865
- exports.complexNode = complexNode;
1866
- exports.constNode = constNode;
1867
- exports.decimalAdd = decimalAdd;
1868
- exports.decimalCompare = decimalCompare;
1869
- exports.decimalDivide = decimalDivide;
1870
- exports.decimalFromInteger = decimalFromInteger;
1871
- exports.decimalFromLiteral = decimalFromLiteral;
1872
- exports.decimalFromNumberIfExact = decimalFromNumberIfExact;
1873
- exports.decimalIsZero = decimalIsZero;
1874
- exports.decimalMultiply = decimalMultiply;
1875
- exports.decimalNegate = decimalNegate;
1876
- exports.decimalRound = decimalRound;
1877
- exports.decimalSubtract = decimalSubtract;
1878
- exports.decimalToFixed = decimalToFixed;
1879
- exports.decimalToNumber = decimalToNumber;
1880
- exports.determinant = determinant;
1881
- exports.exactIntegerCbrt = exactIntegerCbrt;
1882
- exports.exactIntegerSqrt = exactIntegerSqrt;
1883
- exports.exactRationalSqrt = exactRationalSqrt2;
1884
- exports.expandSymbolic = expandSymbolic;
1885
- exports.formatSymbolic = formatSymbolic;
1886
- exports.freeVariables = freeVariables;
1887
- exports.fromPolynomial = fromPolynomial;
1888
- exports.inBounds = inBounds;
1889
- exports.inverse = inverse;
1890
- exports.isRationalOne = isRationalOne;
1891
- exports.isRationalZero = isRationalZero;
1892
- exports.isZeroPolynomial = isZeroPolynomial;
1893
- exports.makeDecimal = makeDecimal;
1894
- exports.matAt = matAt;
1895
- exports.matIndex = matIndex;
1896
- exports.matrixCompare = matrixCompare;
1897
- exports.matrixEntryToValue = matrixEntryToValue;
1898
- exports.matrixMultiply = matrixMultiply;
1899
- exports.matrixPower = matrixPower;
1900
- exports.monomialFromKey = monomialFromKey;
1901
- exports.monomialToKey = monomialToKey;
1902
- exports.polyCoefficients = polyCoefficients;
1903
- exports.polyDegree = polyDegree;
1904
- exports.polyUnivariateVar = polyUnivariateVar;
1905
- exports.polynomialDivide = polynomialDivide;
1906
- exports.powNode = powNode;
1907
- exports.rational = rational;
1908
- exports.rationalAdd = rationalAdd;
1909
- exports.rationalCompare = rationalCompare;
1910
- exports.rationalDiv = rationalDiv;
1911
- exports.rationalFromNumber = rationalFromNumber;
1912
- exports.rationalMul = rationalMul;
1913
- exports.rationalNeg = rationalNeg;
1914
- exports.rationalSub = rationalSub;
1915
- exports.rationalToNumber = rationalToNumber;
1916
- exports.resolveCurrencyAlias = resolveCurrencyAlias;
1917
- exports.rowMajorToColumnMajor = rowMajorToColumnMajor;
1918
- exports.sameShape = sameShape;
1919
- exports.signedSurdNode = signedSurdNode;
1920
- exports.simplifySymbolic = simplifySymbolic;
1921
- exports.squareFreePart = squareFreePart;
1922
- exports.substitute = substitute;
1923
- exports.surdNode = surdNode;
1924
- exports.symbolicKey = symbolicKey;
1925
- exports.symbolicToEntry = symbolicToEntry;
1926
- exports.toPolynomial = toPolynomial;
1927
- exports.transpose = transpose;
1928
- exports.varNode = varNode;
1929
- //# sourceMappingURL=chunk-A2DZ5BEJ.cjs.map
1930
- //# sourceMappingURL=chunk-A2DZ5BEJ.cjs.map