nerdamer 1.1.13 → 2.0.0-rc.1

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 (341) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +293 -312
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +7 -0
  5. package/dist/parser.js +2 -0
  6. package/dist/parser.js.LICENSE.txt +7 -0
  7. package/docs-data/parser-functions.json +1960 -0
  8. package/index.d.ts +10 -426
  9. package/output/algebra/adapters.d.ts +33 -0
  10. package/output/algebra/adapters.js +109 -0
  11. package/output/algebra/algorithms/arith.d.ts +84 -0
  12. package/output/algebra/algorithms/arith.js +323 -0
  13. package/output/algebra/algorithms/factor.d.ts +3 -0
  14. package/output/algebra/algorithms/factor.js +5 -0
  15. package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
  16. package/output/algebra/algorithms/factorMultivariate.js +2393 -0
  17. package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
  18. package/output/algebra/algorithms/factorUnivariate.js +1072 -0
  19. package/output/algebra/algorithms/gcd.d.ts +22 -0
  20. package/output/algebra/algorithms/gcd.js +690 -0
  21. package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
  22. package/output/algebra/algorithms/groebnerBase.js +1166 -0
  23. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
  24. package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
  25. package/output/algebra/algorithms/poly.d.ts +228 -0
  26. package/output/algebra/algorithms/poly.js +1299 -0
  27. package/output/algebra/algorithms/rational.d.ts +17 -0
  28. package/output/algebra/algorithms/rational.js +115 -0
  29. package/output/algebra/factor/factor.d.ts +62 -0
  30. package/output/algebra/factor/factor.js +158 -0
  31. package/output/algebra/gcd/gcd.d.ts +29 -0
  32. package/output/algebra/gcd/gcd.js +141 -0
  33. package/output/algebra/groebner.d.ts +21 -0
  34. package/output/algebra/groebner.js +42 -0
  35. package/output/algebra/partfrac.d.ts +19 -0
  36. package/output/algebra/partfrac.js +398 -0
  37. package/output/algebra/polynomialize.d.ts +20 -0
  38. package/output/algebra/polynomialize.js +24 -0
  39. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  40. package/output/algebra/simplify/complexsimp.js +24 -0
  41. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  42. package/output/algebra/simplify/factorCommon.js +136 -0
  43. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  44. package/output/algebra/simplify/funcsimp.js +633 -0
  45. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  46. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  47. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  48. package/output/algebra/simplify/ratsimp.js +140 -0
  49. package/output/algebra/simplify/simplify.d.ts +25 -0
  50. package/output/algebra/simplify/simplify.js +228 -0
  51. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  52. package/output/algebra/simplify/trigreduce.js +424 -0
  53. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  54. package/output/algebra/simplify/trigrewrite.js +156 -0
  55. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  56. package/output/algebra/simplify/trigsimp.js +369 -0
  57. package/output/algebra/simplify/utils.d.ts +32 -0
  58. package/output/algebra/simplify/utils.js +56 -0
  59. package/output/algebra/utils.d.ts +32 -0
  60. package/output/algebra/utils.js +48 -0
  61. package/output/api/advanced.d.ts +7 -0
  62. package/output/api/advanced.js +18 -0
  63. package/output/api/algebra.d.ts +17 -0
  64. package/output/api/algebra.js +32 -0
  65. package/output/api/assumptions.d.ts +4 -0
  66. package/output/api/assumptions.js +11 -0
  67. package/output/api/calculus.d.ts +9 -0
  68. package/output/api/calculus.js +21 -0
  69. package/output/api/core.d.ts +17 -0
  70. package/output/api/core.js +41 -0
  71. package/output/api/debug.d.ts +16 -0
  72. package/output/api/debug.js +23 -0
  73. package/output/api/parser.d.ts +85 -0
  74. package/output/api/parser.js +16 -0
  75. package/output/api/solve.d.ts +10 -0
  76. package/output/api/solve.js +16 -0
  77. package/output/api/structures.d.ts +10 -0
  78. package/output/api/structures.js +22 -0
  79. package/output/calculus/derivative/diff.d.ts +30 -0
  80. package/output/calculus/derivative/diff.js +238 -0
  81. package/output/calculus/fresnel.d.ts +16 -0
  82. package/output/calculus/fresnel.js +39 -0
  83. package/output/calculus/integrate/byParts.d.ts +18 -0
  84. package/output/calculus/integrate/byParts.js +339 -0
  85. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  86. package/output/calculus/integrate/bySubstitution.js +411 -0
  87. package/output/calculus/integrate/integrate.d.ts +38 -0
  88. package/output/calculus/integrate/integrate.js +652 -0
  89. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  90. package/output/calculus/integrate/integrationTable.js +914 -0
  91. package/output/calculus/integrate/utils.d.ts +28 -0
  92. package/output/calculus/integrate/utils.js +96 -0
  93. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  94. package/output/calculus/laplace/ilaplace.js +192 -0
  95. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  96. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  97. package/output/calculus/laplace/laplace.d.ts +22 -0
  98. package/output/calculus/laplace/laplace.js +109 -0
  99. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  100. package/output/calculus/laplace/laplaceTable.js +187 -0
  101. package/output/calculus/limit/limit.d.ts +35 -0
  102. package/output/calculus/limit/limit.js +1183 -0
  103. package/output/calculus/limit/limitsTable.d.ts +2 -0
  104. package/output/calculus/limit/limitsTable.js +7 -0
  105. package/output/core/Settings.d.ts +32 -0
  106. package/output/core/Settings.js +68 -0
  107. package/output/core/adapters.d.ts +18 -0
  108. package/output/core/adapters.js +40 -0
  109. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  110. package/output/core/classes/assumption/Assumption.js +605 -0
  111. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  112. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  113. package/output/core/classes/assumption/assume.d.ts +90 -0
  114. package/output/core/classes/assumption/assume.js +145 -0
  115. package/output/core/classes/collection/Collection.d.ts +107 -0
  116. package/output/core/classes/collection/Collection.js +231 -0
  117. package/output/core/classes/complex/Complex.d.ts +99 -0
  118. package/output/core/classes/complex/Complex.js +135 -0
  119. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  120. package/output/core/classes/decimalSet/DecimalSet.js +453 -0
  121. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  122. package/output/core/classes/dictionary/Dictionary.js +213 -0
  123. package/output/core/classes/equation/Equation.d.ts +256 -0
  124. package/output/core/classes/equation/Equation.js +350 -0
  125. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  126. package/output/core/classes/expression/CoeffObject.js +198 -0
  127. package/output/core/classes/expression/Expression.d.ts +1674 -0
  128. package/output/core/classes/expression/Expression.js +2332 -0
  129. package/output/core/classes/expression/analysis.d.ts +25 -0
  130. package/output/core/classes/expression/analysis.js +218 -0
  131. package/output/core/classes/expression/collect.d.ts +9 -0
  132. package/output/core/classes/expression/collect.js +49 -0
  133. package/output/core/classes/expression/format.d.ts +45 -0
  134. package/output/core/classes/expression/format.js +217 -0
  135. package/output/core/classes/expression/products.d.ts +23 -0
  136. package/output/core/classes/expression/products.js +115 -0
  137. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  138. package/output/core/classes/expression/shortcuts.js +129 -0
  139. package/output/core/classes/expression/traversal.d.ts +31 -0
  140. package/output/core/classes/expression/traversal.js +216 -0
  141. package/output/core/classes/expression/trig.d.ts +25 -0
  142. package/output/core/classes/expression/trig.js +40 -0
  143. package/output/core/classes/expression/utils.d.ts +52 -0
  144. package/output/core/classes/expression/utils.js +189 -0
  145. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  146. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  147. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  148. package/output/core/classes/matrix/Matrix.js +889 -0
  149. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  150. package/output/core/classes/matrix/Sylvester.js +54 -0
  151. package/output/core/classes/matrix/functions.d.ts +26 -0
  152. package/output/core/classes/matrix/functions.js +52 -0
  153. package/output/core/classes/matrix/utils.d.ts +9 -0
  154. package/output/core/classes/matrix/utils.js +22 -0
  155. package/output/core/classes/parser/Parser.d.ts +480 -0
  156. package/output/core/classes/parser/Parser.js +1812 -0
  157. package/output/core/classes/parser/Token.d.ts +58 -0
  158. package/output/core/classes/parser/Token.js +137 -0
  159. package/output/core/classes/parser/constants.d.ts +160 -0
  160. package/output/core/classes/parser/constants.js +227 -0
  161. package/output/core/classes/parser/helpers.d.ts +21 -0
  162. package/output/core/classes/parser/helpers.js +42 -0
  163. package/output/core/classes/parser/operations/add.d.ts +15 -0
  164. package/output/core/classes/parser/operations/add.js +238 -0
  165. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  166. package/output/core/classes/parser/operations/comma.js +11 -0
  167. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  168. package/output/core/classes/parser/operations/compare.js +461 -0
  169. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  170. package/output/core/classes/parser/operations/divide.js +72 -0
  171. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  172. package/output/core/classes/parser/operations/functions.js +430 -0
  173. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  174. package/output/core/classes/parser/operations/multiply.js +321 -0
  175. package/output/core/classes/parser/operations/power.d.ts +48 -0
  176. package/output/core/classes/parser/operations/power.js +673 -0
  177. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  178. package/output/core/classes/parser/operations/subtract.js +35 -0
  179. package/output/core/classes/parser/preprocess.d.ts +14 -0
  180. package/output/core/classes/parser/preprocess.js +259 -0
  181. package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
  182. package/output/core/classes/parser/scripting/controlFlow.js +355 -0
  183. package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
  184. package/output/core/classes/parser/scripting/evaluate.js +112 -0
  185. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  186. package/output/core/classes/parser/scripting/functions.js +59 -0
  187. package/output/core/classes/parser/scripting/scope.d.ts +35 -0
  188. package/output/core/classes/parser/scripting/scope.js +155 -0
  189. package/output/core/classes/parser/types.d.ts +125 -0
  190. package/output/core/classes/parser/types.js +2 -0
  191. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  192. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  193. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  194. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  195. package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
  196. package/output/core/classes/polynomial/Polynomial.js +1149 -0
  197. package/output/core/classes/polynomial/Term.d.ts +222 -0
  198. package/output/core/classes/polynomial/Term.js +430 -0
  199. package/output/core/classes/polynomial/functions.d.ts +69 -0
  200. package/output/core/classes/polynomial/functions.js +126 -0
  201. package/output/core/classes/polynomial/utils.d.ts +62 -0
  202. package/output/core/classes/polynomial/utils.js +206 -0
  203. package/output/core/classes/rational/Rational.d.ts +504 -0
  204. package/output/core/classes/rational/Rational.js +779 -0
  205. package/output/core/classes/seq/SEQ.d.ts +13 -0
  206. package/output/core/classes/seq/SEQ.js +137 -0
  207. package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
  208. package/output/core/classes/valuesSet/ValuesSet.js +381 -0
  209. package/output/core/classes/vector/Vector.d.ts +222 -0
  210. package/output/core/classes/vector/Vector.js +497 -0
  211. package/output/core/classes/vector/functions.d.ts +28 -0
  212. package/output/core/classes/vector/functions.js +47 -0
  213. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  214. package/output/core/common/classes/MathematicalAggregate.js +140 -0
  215. package/output/core/common/classes/Scope.d.ts +62 -0
  216. package/output/core/common/classes/Scope.js +122 -0
  217. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  218. package/output/core/common/classes/StructuredEntity.js +151 -0
  219. package/output/core/common/common.d.ts +63 -0
  220. package/output/core/common/common.js +279 -0
  221. package/output/core/common/functions/functions.d.ts +14 -0
  222. package/output/core/common/functions/functions.js +33 -0
  223. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  224. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  225. package/output/core/converters/BaseConverter.d.ts +97 -0
  226. package/output/core/converters/BaseConverter.js +405 -0
  227. package/output/core/converters/Converter.d.ts +111 -0
  228. package/output/core/converters/Converter.js +802 -0
  229. package/output/core/converters/Pattern.d.ts +71 -0
  230. package/output/core/converters/Pattern.js +302 -0
  231. package/output/core/dispatch.d.ts +34 -0
  232. package/output/core/dispatch.js +304 -0
  233. package/output/core/errors.d.ts +531 -0
  234. package/output/core/errors.js +621 -0
  235. package/output/core/functions/bigint/bigint.d.ts +121 -0
  236. package/output/core/functions/bigint/bigint.js +392 -0
  237. package/output/core/functions/bigint/primeFactor.d.ts +49 -0
  238. package/output/core/functions/bigint/primeFactor.js +267 -0
  239. package/output/core/functions/bigint/primes.d.ts +1 -0
  240. package/output/core/functions/bigint/primes.js +11 -0
  241. package/output/core/functions/build/definitions.d.ts +12 -0
  242. package/output/core/functions/build/definitions.js +133 -0
  243. package/output/core/functions/build/index.d.ts +32 -0
  244. package/output/core/functions/build/index.js +136 -0
  245. package/output/core/functions/complex.d.ts +90 -0
  246. package/output/core/functions/complex.js +482 -0
  247. package/output/core/functions/decimal.d.ts +24 -0
  248. package/output/core/functions/decimal.js +664 -0
  249. package/output/core/functions/expand/expand.d.ts +42 -0
  250. package/output/core/functions/expand/expand.js +376 -0
  251. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  252. package/output/core/functions/fresnelNumeric.js +123 -0
  253. package/output/core/functions/numeric.d.ts +140 -0
  254. package/output/core/functions/numeric.js +790 -0
  255. package/output/core/functions/rationalNormalization.d.ts +11 -0
  256. package/output/core/functions/rationalNormalization.js +117 -0
  257. package/output/core/functions/setFunction.d.ts +19 -0
  258. package/output/core/functions/setFunction.js +75 -0
  259. package/output/core/functions/string.d.ts +26 -0
  260. package/output/core/functions/string.js +101 -0
  261. package/output/core/functions/subst.d.ts +90 -0
  262. package/output/core/functions/subst.js +498 -0
  263. package/output/core/functions/utils.d.ts +24 -0
  264. package/output/core/functions/utils.js +51 -0
  265. package/output/core/types.d.ts +48 -0
  266. package/output/core/types.js +2 -0
  267. package/output/index.d.ts +339 -0
  268. package/output/index.js +715 -0
  269. package/output/math/defint/defintDecimal.d.ts +37 -0
  270. package/output/math/defint/defintDecimal.js +320 -0
  271. package/output/math/defint/defintNative.d.ts +57 -0
  272. package/output/math/defint/defintNative.js +292 -0
  273. package/output/math/geometry.d.ts +8 -0
  274. package/output/math/geometry.js +32 -0
  275. package/output/math/math.d.ts +655 -0
  276. package/output/math/math.js +1811 -0
  277. package/output/math/trig.d.ts +518 -0
  278. package/output/math/trig.js +1444 -0
  279. package/output/math/trunc.d.ts +19 -0
  280. package/output/math/trunc.js +36 -0
  281. package/output/math/utils.d.ts +60 -0
  282. package/output/math/utils.js +180 -0
  283. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  284. package/output/solve/classes/DecimalMatrix.js +86 -0
  285. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  286. package/output/solve/classes/FunctionSolver.js +433 -0
  287. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  288. package/output/solve/classes/MultivariateSolver.js +240 -0
  289. package/output/solve/classes/PolynomialSolver.d.ts +85 -0
  290. package/output/solve/classes/PolynomialSolver.js +292 -0
  291. package/output/solve/classes/SolutionSet.d.ts +153 -0
  292. package/output/solve/classes/SolutionSet.js +357 -0
  293. package/output/solve/classes/Solver.d.ts +17 -0
  294. package/output/solve/classes/Solver.js +132 -0
  295. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  296. package/output/solve/classes/SymbolicSolver.js +601 -0
  297. package/output/solve/linsolve.d.ts +51 -0
  298. package/output/solve/linsolve.js +225 -0
  299. package/output/solve/solve.d.ts +34 -0
  300. package/output/solve/solve.js +260 -0
  301. package/output/solve/solveSystem.d.ts +31 -0
  302. package/output/solve/solveSystem.js +290 -0
  303. package/output/solve/utils.d.ts +9 -0
  304. package/output/solve/utils.js +62 -0
  305. package/output/utils/array.d.ts +42 -0
  306. package/output/utils/array.js +98 -0
  307. package/output/utils/debug.d.ts +131 -0
  308. package/output/utils/debug.js +295 -0
  309. package/output/utils/decimal.d.ts +3 -0
  310. package/output/utils/decimal.js +16 -0
  311. package/output/utils/numeric.d.ts +14 -0
  312. package/output/utils/numeric.js +51 -0
  313. package/output/utils/object.d.ts +26 -0
  314. package/output/utils/object.js +56 -0
  315. package/package.json +213 -57
  316. package/.travis.yml +0 -3
  317. package/Algebra.js +0 -4568
  318. package/BREAKING_CHANGES.md +0 -5
  319. package/CODE_OF_CONDUCT.md +0 -46
  320. package/CONTRIBUTING.md +0 -14
  321. package/Calculus.js +0 -2675
  322. package/Extra.js +0 -622
  323. package/Solve.js +0 -1783
  324. package/all.js +0 -16
  325. package/all.min.js +0 -1
  326. package/gulpfile.js +0 -16
  327. package/index.html +0 -158
  328. package/license.txt +0 -19
  329. package/nerdamer.core.js +0 -12510
  330. package/spec/LaTeX.spec.js +0 -302
  331. package/spec/TeXConvert.spec.js +0 -8
  332. package/spec/algebra.spec.js +0 -287
  333. package/spec/basic_parser.spec.js +0 -134
  334. package/spec/build.spec.js +0 -131
  335. package/spec/calculus.spec.js +0 -183
  336. package/spec/core.spec.js +0 -2970
  337. package/spec/extra.spec.js +0 -54
  338. package/spec/solve.spec.js +0 -126
  339. package/spec/support/jasmine.json +0 -11
  340. package/spec/support/utils.js +0 -42
  341. package/spec/text.spec.js +0 -132
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Sparse multivariate polynomial over integer coefficients.
3
+ *
4
+ * @remarks
5
+ * Monomials are stored in a mutable map from canonical exponent keys to `bigint`
6
+ * coefficients. Variable indices, rather than names, define the polynomial ring; every
7
+ * polynomial combined by an algorithm must use the same index-to-name mapping.
8
+ * Exponents are expected to be non-negative integers, but construction helpers do not
9
+ * validate that requirement.
10
+ *
11
+ * The constructor copies the supplied map, so {@link MultiPoly.clone} has independent
12
+ * term storage. The public {@link MultiPoly.terms} property, on the other hand, exposes
13
+ * the live map. Direct edits must use canonical keys and remove zero coefficients;
14
+ * {@link MultiPoly.setCoeff} is the safer choice for ordinary updates.
15
+ *
16
+ * This is the exact representation used by the advanced Groebner layer. It does not
17
+ * represent rational coefficients directly; expression-facing adapters clear
18
+ * denominators before conversion.
19
+ */
20
+ export declare class MultiPoly {
21
+ /** Live term map keyed by canonical monomial strings. */
22
+ terms: Map<string, bigint>;
23
+ /**
24
+ * Creates a polynomial by copying the supplied term map.
25
+ *
26
+ * @param terms - Initial canonical-monomial-key to integer-coefficient map.
27
+ */
28
+ constructor(terms?: Map<string, bigint>);
29
+ /**
30
+ * Creates a constant polynomial, omitting storage for zero.
31
+ *
32
+ * @param c - Integer constant.
33
+ */
34
+ static constant(c: bigint): MultiPoly;
35
+ /**
36
+ * Creates the monomial `coeff * x₀^e₀ * x₁^e₁ * ...`.
37
+ *
38
+ * @param coeff - Integer coefficient.
39
+ * @param exponents - Exponents indexed by variable number.
40
+ */
41
+ static monomial(coeff: bigint, exponents: number[]): MultiPoly;
42
+ /**
43
+ * Creates the constant polynomial one.
44
+ */
45
+ static one(): MultiPoly;
46
+ /**
47
+ * Creates the single-variable polynomial `xᵢ`.
48
+ *
49
+ * @param varIndex - Variable index to raise to the first power.
50
+ */
51
+ static variable(varIndex: number): MultiPoly;
52
+ /**
53
+ * Creates the zero polynomial with empty term storage.
54
+ */
55
+ static zero(): MultiPoly;
56
+ /**
57
+ * Creates an independent copy of the term map.
58
+ */
59
+ clone(): MultiPoly;
60
+ /**
61
+ * Returns the constant coefficient, or zero when absent.
62
+ */
63
+ constantTerm(): bigint;
64
+ /**
65
+ * Returns the greatest exponent of one variable.
66
+ *
67
+ * @param varIndex - Variable index to inspect.
68
+ * @returns `-1` for zero; otherwise a non-negative degree.
69
+ */
70
+ degree(varIndex: number): number;
71
+ /**
72
+ * Returns a monomial coefficient from dense exponents.
73
+ *
74
+ * @param exponents - Exponents indexed by variable number.
75
+ * @returns The stored coefficient, or zero when absent.
76
+ */
77
+ getCoeff(exponents: number[]): bigint;
78
+ /**
79
+ * Tests whether this polynomial is zero or contains only a constant term.
80
+ */
81
+ isConstant(): boolean;
82
+ /**
83
+ * Tests whether the term map is empty.
84
+ */
85
+ isZero(): boolean;
86
+ /**
87
+ * Extracts the coefficient of the highest power of one variable.
88
+ *
89
+ * The selected variable is removed from those leading terms, so the coefficient is
90
+ * itself returned as a new polynomial in the remaining variables.
91
+ *
92
+ * @param varIndex - Variable whose greatest power is selected and removed.
93
+ * @returns A new polynomial in the remaining variables.
94
+ */
95
+ leadingCoeff(varIndex: number): MultiPoly;
96
+ /**
97
+ * Sets or removes a monomial coefficient in place.
98
+ *
99
+ * @param exponents - Dense exponents indexed by variable number.
100
+ * @param coeff - Integer coefficient; zero removes the monomial.
101
+ */
102
+ setCoeff(exponents: number[], coeff: bigint): void;
103
+ /**
104
+ * Formats this polynomial using caller-supplied variable names.
105
+ *
106
+ * @param varNames - Names aligned with variable indices; missing names fall back to `xN`.
107
+ * @returns Deterministic text ordered by descending total degree and canonical key.
108
+ */
109
+ text(varNames: string[]): string;
110
+ /**
111
+ * Returns the maximum sum of exponents among all monomials.
112
+ *
113
+ * @returns `-1` for the zero polynomial.
114
+ */
115
+ totalDegree(): number;
116
+ /**
117
+ * Removes zero-coefficient entries from the live term map in place.
118
+ */
119
+ trim(): void;
120
+ /**
121
+ * Collects variable indices with at least one nonzero exponent.
122
+ *
123
+ * @returns A new set of variable indices.
124
+ */
125
+ variables(): Set<number>;
126
+ }
127
+ /**
128
+ * Canonical monomial key utilities.
129
+ *
130
+ * Key format: "v:e,v:e,..." with strictly increasing v and e>0.
131
+ * The empty string "" represents the constant monomial.
132
+ */
133
+ export type Exponents = Map<number, number>;
134
+ /** Convert exponent map to canonical key. */
135
+ export declare function expToKey(exp: Exponents): string;
136
+ /** Parse a canonical key back to an exponent map. */
137
+ export declare function keyToExp(key: string): Exponents;
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiPoly = void 0;
4
+ exports.expToKey = expToKey;
5
+ exports.keyToExp = keyToExp;
6
+ /**
7
+ * Sparse multivariate polynomial over integer coefficients.
8
+ *
9
+ * @remarks
10
+ * Monomials are stored in a mutable map from canonical exponent keys to `bigint`
11
+ * coefficients. Variable indices, rather than names, define the polynomial ring; every
12
+ * polynomial combined by an algorithm must use the same index-to-name mapping.
13
+ * Exponents are expected to be non-negative integers, but construction helpers do not
14
+ * validate that requirement.
15
+ *
16
+ * The constructor copies the supplied map, so {@link MultiPoly.clone} has independent
17
+ * term storage. The public {@link MultiPoly.terms} property, on the other hand, exposes
18
+ * the live map. Direct edits must use canonical keys and remove zero coefficients;
19
+ * {@link MultiPoly.setCoeff} is the safer choice for ordinary updates.
20
+ *
21
+ * This is the exact representation used by the advanced Groebner layer. It does not
22
+ * represent rational coefficients directly; expression-facing adapters clear
23
+ * denominators before conversion.
24
+ */
25
+ class MultiPoly {
26
+ /** Live term map keyed by canonical monomial strings. */
27
+ terms;
28
+ /**
29
+ * Creates a polynomial by copying the supplied term map.
30
+ *
31
+ * @param terms - Initial canonical-monomial-key to integer-coefficient map.
32
+ */
33
+ constructor(terms) {
34
+ this.terms = terms ? new Map(terms) : new Map();
35
+ }
36
+ /**
37
+ * Creates a constant polynomial, omitting storage for zero.
38
+ *
39
+ * @param c - Integer constant.
40
+ */
41
+ static constant(c) {
42
+ const p = new MultiPoly();
43
+ if (c !== 0n) {
44
+ p.terms.set('', c);
45
+ }
46
+ return p;
47
+ }
48
+ /**
49
+ * Creates the monomial `coeff * x₀^e₀ * x₁^e₁ * ...`.
50
+ *
51
+ * @param coeff - Integer coefficient.
52
+ * @param exponents - Exponents indexed by variable number.
53
+ */
54
+ static monomial(coeff, exponents) {
55
+ const p = new MultiPoly();
56
+ if (coeff === 0n) {
57
+ return p;
58
+ }
59
+ const exp = new Map();
60
+ for (let i = 0; i < exponents.length; i++) {
61
+ if (exponents[i] !== 0) {
62
+ exp.set(i, exponents[i]);
63
+ }
64
+ }
65
+ p.terms.set(expToKey(exp), coeff);
66
+ return p;
67
+ }
68
+ /**
69
+ * Creates the constant polynomial one.
70
+ */
71
+ static one() {
72
+ return MultiPoly.constant(1n);
73
+ }
74
+ /**
75
+ * Creates the single-variable polynomial `xᵢ`.
76
+ *
77
+ * @param varIndex - Variable index to raise to the first power.
78
+ */
79
+ static variable(varIndex) {
80
+ const p = new MultiPoly();
81
+ const exp = new Map([[varIndex, 1]]);
82
+ p.terms.set(expToKey(exp), 1n);
83
+ return p;
84
+ }
85
+ /**
86
+ * Creates the zero polynomial with empty term storage.
87
+ */
88
+ static zero() {
89
+ return new MultiPoly();
90
+ }
91
+ /**
92
+ * Creates an independent copy of the term map.
93
+ */
94
+ clone() {
95
+ return new MultiPoly(new Map(this.terms));
96
+ }
97
+ /**
98
+ * Returns the constant coefficient, or zero when absent.
99
+ */
100
+ constantTerm() {
101
+ return this.terms.get('') ?? 0n;
102
+ }
103
+ /**
104
+ * Returns the greatest exponent of one variable.
105
+ *
106
+ * @param varIndex - Variable index to inspect.
107
+ * @returns `-1` for zero; otherwise a non-negative degree.
108
+ */
109
+ degree(varIndex) {
110
+ let maxDeg = -1;
111
+ for (const key of this.terms.keys()) {
112
+ const exp = keyToExp(key);
113
+ const d = exp.get(varIndex) ?? 0;
114
+ if (d > maxDeg) {
115
+ maxDeg = d;
116
+ }
117
+ }
118
+ return this.terms.size === 0 ? -1 : maxDeg;
119
+ }
120
+ /**
121
+ * Returns a monomial coefficient from dense exponents.
122
+ *
123
+ * @param exponents - Exponents indexed by variable number.
124
+ * @returns The stored coefficient, or zero when absent.
125
+ */
126
+ getCoeff(exponents) {
127
+ const exp = new Map();
128
+ for (let i = 0; i < exponents.length; i++) {
129
+ if (exponents[i] !== 0) {
130
+ exp.set(i, exponents[i]);
131
+ }
132
+ }
133
+ return this.terms.get(expToKey(exp)) ?? 0n;
134
+ }
135
+ /**
136
+ * Tests whether this polynomial is zero or contains only a constant term.
137
+ */
138
+ isConstant() {
139
+ if (this.terms.size === 0) {
140
+ return true;
141
+ }
142
+ if (this.terms.size === 1 && this.terms.has('')) {
143
+ return true;
144
+ }
145
+ return false;
146
+ }
147
+ /**
148
+ * Tests whether the term map is empty.
149
+ */
150
+ isZero() {
151
+ return this.terms.size === 0;
152
+ }
153
+ /**
154
+ * Extracts the coefficient of the highest power of one variable.
155
+ *
156
+ * The selected variable is removed from those leading terms, so the coefficient is
157
+ * itself returned as a new polynomial in the remaining variables.
158
+ *
159
+ * @param varIndex - Variable whose greatest power is selected and removed.
160
+ * @returns A new polynomial in the remaining variables.
161
+ */
162
+ leadingCoeff(varIndex) {
163
+ const deg = this.degree(varIndex);
164
+ if (deg < 0) {
165
+ return MultiPoly.zero();
166
+ }
167
+ const result = new MultiPoly();
168
+ for (const [key, coeff] of this.terms) {
169
+ const exp = keyToExp(key);
170
+ if ((exp.get(varIndex) ?? 0) === deg) {
171
+ // Remove varIndex from exponents
172
+ const newExp = new Map(exp);
173
+ newExp.delete(varIndex);
174
+ result.terms.set(expToKey(newExp), coeff);
175
+ }
176
+ }
177
+ return result;
178
+ }
179
+ /**
180
+ * Sets or removes a monomial coefficient in place.
181
+ *
182
+ * @param exponents - Dense exponents indexed by variable number.
183
+ * @param coeff - Integer coefficient; zero removes the monomial.
184
+ */
185
+ setCoeff(exponents, coeff) {
186
+ const exp = new Map();
187
+ for (let i = 0; i < exponents.length; i++) {
188
+ if (exponents[i] !== 0) {
189
+ exp.set(i, exponents[i]);
190
+ }
191
+ }
192
+ const key = expToKey(exp);
193
+ if (coeff === 0n) {
194
+ this.terms.delete(key);
195
+ }
196
+ else {
197
+ this.terms.set(key, coeff);
198
+ }
199
+ }
200
+ /**
201
+ * Formats this polynomial using caller-supplied variable names.
202
+ *
203
+ * @param varNames - Names aligned with variable indices; missing names fall back to `xN`.
204
+ * @returns Deterministic text ordered by descending total degree and canonical key.
205
+ */
206
+ text(varNames) {
207
+ if (this.terms.size === 0) {
208
+ return '0';
209
+ }
210
+ const names = varNames;
211
+ const termStrs = [];
212
+ // Sort terms for consistent output
213
+ const sortedTerms = Array.from(this.terms.entries()).sort(([keyA], [keyB]) => compareKeyTotalDegDescThenLex(keyA, keyB));
214
+ for (const [key, coeff] of sortedTerms) {
215
+ const exp = keyToExp(key);
216
+ let termStr = '';
217
+ // Handle coefficient
218
+ const absCoeff = coeff < 0n ? -coeff : coeff;
219
+ const sign = coeff < 0n ? '-' : '+';
220
+ if (exp.size === 0) {
221
+ // Constant term
222
+ termStr = absCoeff.toString();
223
+ }
224
+ else {
225
+ // Has variables
226
+ if (absCoeff !== 1n) {
227
+ termStr = absCoeff.toString();
228
+ }
229
+ for (const [v, e] of Array.from(exp.entries()).sort((a, b) => a[0] - b[0])) {
230
+ const varName = v < names.length ? names[v] : `x${v}`;
231
+ if (e === 1) {
232
+ termStr += varName;
233
+ }
234
+ else {
235
+ termStr += `${varName}^${e}`;
236
+ }
237
+ }
238
+ if (termStr === '') {
239
+ termStr = '1';
240
+ }
241
+ }
242
+ termStrs.push((termStrs.length === 0 ? (sign === '+' ? '' : '-') : ` ${sign} `) + termStr);
243
+ }
244
+ return termStrs.join('') || '0';
245
+ }
246
+ /**
247
+ * Returns the maximum sum of exponents among all monomials.
248
+ *
249
+ * @returns `-1` for the zero polynomial.
250
+ */
251
+ totalDegree() {
252
+ let maxTotal = -1;
253
+ for (const key of this.terms.keys()) {
254
+ const exp = keyToExp(key);
255
+ let total = 0;
256
+ for (const e of exp.values()) {
257
+ total += e;
258
+ }
259
+ if (total > maxTotal) {
260
+ maxTotal = total;
261
+ }
262
+ }
263
+ return this.terms.size === 0 ? -1 : maxTotal;
264
+ }
265
+ /**
266
+ * Removes zero-coefficient entries from the live term map in place.
267
+ */
268
+ trim() {
269
+ for (const [k, c] of this.terms.entries()) {
270
+ if (c === 0n) {
271
+ this.terms.delete(k);
272
+ }
273
+ }
274
+ }
275
+ /**
276
+ * Collects variable indices with at least one nonzero exponent.
277
+ *
278
+ * @returns A new set of variable indices.
279
+ */
280
+ variables() {
281
+ const vars = new Set();
282
+ for (const key of this.terms.keys()) {
283
+ const exp = keyToExp(key);
284
+ for (const v of exp.keys()) {
285
+ vars.add(v);
286
+ }
287
+ }
288
+ return vars;
289
+ }
290
+ }
291
+ exports.MultiPoly = MultiPoly;
292
+ /** Convert exponent map to canonical key. */
293
+ // NOTE: These helpers keep the `Impl` suffix used by the internal layout.
294
+ // The structural tests enforce that the public wrappers live in monomial-key.ts.
295
+ function expToKey(exp) {
296
+ const entries = Array.from(exp.entries())
297
+ .filter(([, e]) => e !== 0)
298
+ .sort((a, b) => a[0] - b[0]);
299
+ if (entries.length === 0) {
300
+ return '';
301
+ }
302
+ return entries.map(([v, e]) => `${v}:${e}`).join(',');
303
+ }
304
+ /** Parse a canonical key back to an exponent map. */
305
+ function keyToExp(key) {
306
+ const exp = new Map();
307
+ if (key === '') {
308
+ return exp;
309
+ }
310
+ for (const part of key.split(',')) {
311
+ const [vStr, eStr] = part.split(':');
312
+ const v = Number(vStr);
313
+ const e = Number(eStr);
314
+ if (!Number.isFinite(v) || !Number.isFinite(e)) {
315
+ throw new Error(`keyToExpImpl: invalid monomial key '${key}'`);
316
+ }
317
+ if (e !== 0) {
318
+ exp.set(v, e);
319
+ }
320
+ }
321
+ return exp;
322
+ }
323
+ /**
324
+ * Sort callback: total degree descending, then lex by key string.
325
+ * Matches the current ordering used by MultiPoly.toString().
326
+ */
327
+ function compareKeyTotalDegDescThenLex(a, b) {
328
+ const da = keyTotalDegree(a);
329
+ const db = keyTotalDegree(b);
330
+ if (da !== db) {
331
+ return db - da;
332
+ }
333
+ return a.localeCompare(b);
334
+ }
335
+ /** Total degree of a monomial key (sum of all exponents). */
336
+ function keyTotalDegree(key) {
337
+ if (key === '') {
338
+ return 0;
339
+ }
340
+ let s = 0;
341
+ for (const part of key.split(',')) {
342
+ const [, eStr] = part.split(':');
343
+ s += Number(eStr);
344
+ }
345
+ return s;
346
+ }