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,500 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Expression } from '../expression/Expression';
3
+ import { POLYNOMIAL } from '../parser/constants';
4
+ import { Rational } from '../rational/Rational';
5
+ import { Term } from './Term';
6
+ import type { ExpressionInput, NerdamerInput } from '../../types';
7
+ /** Monomial ordering labels understood by {@link Polynomial.order}. */
8
+ export type Ordering = 'none' | 'deg' | 'lex' | 'revlex' | 'grlex' | 'grevlex' | 'byvar';
9
+ /** Inputs accepted by polynomial conversion helpers. */
10
+ export type PolyType = string | Polynomial | Expression;
11
+ /** Internal expression-valued power map retained for compatibility. */
12
+ export type TermPowerObject = Record<string, Expression>;
13
+ export type VariableFrequency = {
14
+ variable: string;
15
+ count: number;
16
+ deg: number;
17
+ };
18
+ /** Exact values accepted when evaluating a polynomial. */
19
+ export type EvalInputType = number | bigint | Rational;
20
+ /**
21
+ * Represents a polynomial as ordered {@link Term} objects with symbolic coefficients.
22
+ *
23
+ * @remarks
24
+ * Construction accepts polynomial-like expression input, expands bracketed or powered
25
+ * sums when necessary, and collects coefficients using either the supplied variable
26
+ * order or the expression's alphabetically sorted variables. Negative variable powers
27
+ * and other non-polynomial forms are rejected.
28
+ *
29
+ * The object is mutable: ordering methods sort {@link Polynomial.terms} in place, and
30
+ * `gcdFree(..., true)` edits term coefficients and powers. Arithmetic methods such as
31
+ * {@link Polynomial.plus}, {@link Polynomial.minus}, and {@link Polynomial.times}
32
+ * normally return new polynomials. Public arrays and terms expose mutable internal
33
+ * references; callers that edit them directly must preserve ordering and keep cached
34
+ * term data consistent.
35
+ *
36
+ * Coefficients are stored as `Expression` values. Operations such as
37
+ * {@link Polynomial.evaluate} convert supplied values to {@link Rational} and use exact
38
+ * rational arithmetic; {@link Polynomial.at} and numeric array conversions instead use
39
+ * JavaScript numbers and may lose precision.
40
+ *
41
+ * Supported orderings include lexicographic, reverse lexicographic, graded
42
+ * lexicographic, and graded reverse lexicographic order. Univariate polynomials always
43
+ * use descending degree order regardless of the requested multivariate ordering.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const polynomial = new Polynomial('x^2 + 2*x + 1', ['x']);
48
+ *
49
+ * polynomial.deg(); // 2
50
+ * polynomial.toArray().map(String); // ["1", "2", "1"]
51
+ * polynomial.evaluateToRational({ x: 2 }).toString(); // "5"
52
+ * ```
53
+ */
54
+ export declare class Polynomial {
55
+ /** Default ordering chosen for newly parsed multivariate polynomials. */
56
+ static defaultOrdering: Ordering;
57
+ /** Runtime tag used by Nerdamer's polynomial type guard. */
58
+ dataType: typeof POLYNOMIAL;
59
+ /** Expression retained from construction or the most recent explicit rebuild. */
60
+ expression: Expression;
61
+ /** Whether the polynomial's variable list contains more than one variable. */
62
+ isMultivariate: boolean;
63
+ /** Current monomial ordering of {@link terms}. */
64
+ ordering: Ordering;
65
+ /** Terms in their current monomial order. The array is mutable. */
66
+ terms: Term[];
67
+ /** Variable order used to interpret term multidegrees. The array is mutable. */
68
+ variables: string[];
69
+ /**
70
+ * Constructs a polynomial from expression input or deep-copies another polynomial.
71
+ *
72
+ * @param p - Polynomial-like input or an existing polynomial to copy.
73
+ * @param vars - Variable names in the order used for multidegrees and monomial comparison.
74
+ * When omitted, variables are collected and sorted alphabetically.
75
+ * @param ordering - Requested monomial ordering for parsed multivariate input.
76
+ * @throws {@link core!PolynomialError} Thrown when the parsed expression is not polynomial-like.
77
+ * @throws {@link core!UnsupportedOperationError} Thrown when input cannot be converted to
78
+ * an expression supported by the polynomial representation.
79
+ */
80
+ constructor(p: ExpressionInput | Polynomial, vars?: string[], ordering?: Ordering);
81
+ /**
82
+ * Constructs a polynomial from dense ascending-power coefficients.
83
+ *
84
+ * @remarks
85
+ * Entry `arr[i]` becomes the coefficient of power `i`. When multiple variable names
86
+ * are supplied, their product is treated as one repeated base; this is not a general
87
+ * multidimensional coefficient tensor.
88
+ *
89
+ * @param arr - Coefficients ordered from constant term upward.
90
+ * @param vars - Variable names forming the polynomial base.
91
+ */
92
+ static fromArray(arr: NerdamerInput[], vars: string[]): Polynomial;
93
+ /** Reconstructs dense coefficients through the normal constructor when powers overlap coefficients. */
94
+ private static fromArrayCanonicalized;
95
+ /**
96
+ * Sorts by graded lexicographic order. The abs(power) is first compared and then
97
+ * revlex is used to break ties.
98
+ *
99
+ * @param a - First term to compare.
100
+ * @param b - Second term to compare.
101
+ * @returns A comparator value suitable for `Array.sort`.
102
+ */
103
+ static grevlex(a: Term, b: Term): number;
104
+ /**
105
+ * Sorts by graded lexicographic order. The abs(power) is first compared and then
106
+ * lex is used to break ties.
107
+ *
108
+ * @param a - First term to compare.
109
+ * @param b - Second term to compare.
110
+ * @returns A comparator value suitable for `Array.sort`.
111
+ */
112
+ static grlex(a: Term, b: Term): 1 | -1;
113
+ /**
114
+ * Checks if the given object is a Polynomial
115
+ *
116
+ * @param obj - Value to test.
117
+ * @returns Whether `obj` carries Nerdamer's polynomial discriminator.
118
+ */
119
+ static isPolynomial(obj: unknown): obj is Polynomial;
120
+ /**
121
+ * Sorts by lexicographic order. The power tuples are subtracted and the first
122
+ * non-negative value from the left is used to sort. Note that variables are
123
+ * first sorted in alphabetical order.
124
+ *
125
+ * @param a - First term to compare.
126
+ * @param b - Second term to compare.
127
+ * @returns A comparator value suitable for `Array.sort`.
128
+ */
129
+ static lex(a: Term, b: Term): 1 | -1;
130
+ /**
131
+ * Sorts an array given a specific ordering using their LT
132
+ *
133
+ * @param polyArray - Polynomials to reorder. The array itself is sorted in place.
134
+ * @param ordering - Monomial ordering used for each polynomial and its leading term.
135
+ * @returns The same sorted array after each polynomial has also been reordered.
136
+ */
137
+ static polyArraySort(polyArray: Polynomial[], ordering?: Ordering): Polynomial[];
138
+ /**
139
+ * Converts a Rational to a string suitable for polynomial construction.
140
+ * Handles both integers and fractions.
141
+ *
142
+ * @param r - Rational value to convert.
143
+ * @returns Parser text preserving an integer or fraction exactly.
144
+ */
145
+ private static rationalToString;
146
+ /**
147
+ * Sorts by reverse lexicographic order. The power tuples are subtracted and the first
148
+ * non-negative value from the right is used to sort
149
+ *
150
+ * @param a - First term to compare.
151
+ * @param b - Second term to compare.
152
+ * @returns A comparator value suitable for `Array.sort`.
153
+ */
154
+ static revlex(a: Term, b: Term): number;
155
+ /**
156
+ * Fetches the expression from the given object.
157
+ *
158
+ * @param p - Polynomial, expression, or parser text to convert.
159
+ * @returns The polynomial's stored expression reference, or the parsed expression for
160
+ * non-polynomial input.
161
+ */
162
+ static toExpression(p: PolyType): Expression;
163
+ /**
164
+ * Converts a string to a Polynomial. If a polynomial is provided, it's returned untouched.
165
+ * If a polynomial is provided and no ordering, then the polynomial's ordering will be used.
166
+ * If no ordering is provided for all others then the Polynomial.defaultOrdering will be used.
167
+ *
168
+ * @param p - Value to convert.
169
+ * @param ordering - Ordering to apply. Passing an existing polynomial may reorder it in place.
170
+ * @param variables - Variable order used only when constructing a new polynomial.
171
+ * @returns The existing polynomial or a newly constructed one.
172
+ */
173
+ static toPolynomial(p: PolyType, ordering?: Ordering, variables?: string[]): Polynomial;
174
+ /**
175
+ * Creates a copy and adds or subtracts every supplied term.
176
+ *
177
+ * @param x - Term or polynomial whose terms should be combined.
178
+ * @param action - Whether matching coefficients are added or subtracted.
179
+ * @returns A new combined polynomial.
180
+ */
181
+ private append;
182
+ /**
183
+ * Adds or removes a term from the terms array of the polynomial
184
+ *
185
+ * @param t - Term to combine or append.
186
+ * @param action - Coefficient operation for a matching term.
187
+ */
188
+ private appendTerm;
189
+ private monomialGCDTerm;
190
+ private updateExpression;
191
+ /**
192
+ * Numerically evaluates the univariate polynomial at a given point
193
+ * @param n - JavaScript number at which to evaluate the sole variable.
194
+ * @returns A JavaScript-number approximation.
195
+ * @throws {@link core!UnsupportedOperationError} Thrown for multivariate polynomials.
196
+ */
197
+ at(n: number): number;
198
+ /**
199
+ * Collects coefficients by power or multidegree.
200
+ *
201
+ * @param variable - Optional single main variable. When omitted, keys use all
202
+ * polynomial variables in their stored order.
203
+ * @returns A mutable coefficient object whose expressions are derived from this polynomial.
204
+ */
205
+ coeffs(variable?: string): import("../expression/CoeffObject").CoeffObject;
206
+ /**
207
+ * Returns the positive variable powers shared by every term.
208
+ *
209
+ * @returns A new variable-to-minimum-power record; variables absent from any term are omitted.
210
+ */
211
+ commonTermVariables(): {
212
+ [variable: string]: number;
213
+ };
214
+ /**
215
+ * Returns the coefficient of the trailing constant term.
216
+ *
217
+ * @returns The stored coefficient reference when a constant term is present, otherwise
218
+ * a new zero expression.
219
+ */
220
+ constantTerm(): Expression;
221
+ /**
222
+ * Returns the content of the polynomial (GCD of all coefficients).
223
+ * Does not rely on the Expression class.
224
+ *
225
+ * @returns A new exact rational greatest common divisor of the numeric coefficients.
226
+ */
227
+ content(): Rational;
228
+ /**
229
+ * Returns the degree of the polynomial.
230
+ *
231
+ * With no variable, this is the total degree: the largest sum of powers in any term.
232
+ * When a variable is supplied, this is the largest power of that variable across all
233
+ * terms, with every other variable treated as part of the coefficient.
234
+ *
235
+ * @param variable - Optional variable whose degree should be returned.
236
+ * @returns The total degree, or the degree with respect to `variable`.
237
+ */
238
+ deg(variable?: string): number;
239
+ /**
240
+ * Performs a derivative with respect to a variable using Term-based operations.
241
+ * Does not rely on the Expression class for differentiation.
242
+ *
243
+ * @param v - Variable to differentiate; defaults to the first stored variable.
244
+ * @param n - Non-negative derivative order.
245
+ * @returns A newly constructed polynomial; order zero returns a deep copy.
246
+ */
247
+ diff(v?: string, n?: number): Polynomial;
248
+ /**
249
+ * Divides this polynomial by another polynomial.
250
+ *
251
+ * @param p - Divisor polynomial.
252
+ * @returns A two-element array containing quotient and remainder as new polynomials.
253
+ */
254
+ div(p: Polynomial): Polynomial[];
255
+ /**
256
+ * Checks to see if a polynomial divides the given polynomial
257
+ *
258
+ * @param p - Polynomial whose leading term is tested as the dividend.
259
+ * @returns Whether this polynomial's leading term divides `p`'s leading term. This is
260
+ * a monomial divisibility test, not proof that the complete polynomial divides `p`.
261
+ */
262
+ divides(p: Polynomial): boolean;
263
+ /**
264
+ * Checks if two polynomials are equal
265
+ *
266
+ * @param p - Polynomial to compare.
267
+ * @returns Whether subtracting `p` produces the zero polynomial.
268
+ */
269
+ eq(p: Polynomial): boolean;
270
+ /**
271
+ * Evaluates the polynomial at given values using Term-based operations.
272
+ * Supports partial evaluation (substituting some variables while keeping others symbolic).
273
+ * Does not rely on the Expression class for computation.
274
+ *
275
+ * @param values - Variable names mapped to exact rational-compatible values.
276
+ * @returns A new partially evaluated polynomial; unmentioned variables remain symbolic.
277
+ */
278
+ evaluate(values: {
279
+ [variable: string]: EvalInputType;
280
+ }): Polynomial;
281
+ /**
282
+ * Numerically evaluates the polynomial at given values.
283
+ * All variables must be provided values.
284
+ *
285
+ * @param values - Values for every variable stored by the polynomial.
286
+ * @returns The exact rational result.
287
+ * @throws {@link core!UnsupportedOperationError} Thrown when any stored variable is missing.
288
+ */
289
+ evaluateToRational(values: {
290
+ [variable: string]: EvalInputType;
291
+ }): Rational;
292
+ /**
293
+ * Divides all terms by their exact numeric content and optionally their common monomial.
294
+ *
295
+ * @param reduceVariables - Also subtract the minimum shared positive power of each variable.
296
+ * @param mutate - Modify and return this polynomial instead of a deep copy.
297
+ * @returns The normalized target polynomial.
298
+ */
299
+ gcdFree(reduceVariables?: boolean, mutate?: boolean): Polynomial;
300
+ /**
301
+ * Returns the expression retained by the polynomial.
302
+ *
303
+ * @remarks
304
+ * This is an internal reference, not a copy. The term array is the operative
305
+ * representation for many methods, and direct term mutation is not guaranteed to
306
+ * rebuild this stored expression automatically.
307
+ */
308
+ getExpression(): Expression;
309
+ /**
310
+ * Sorts the terms by graded lexicographic order
311
+ * grevlex first compares their powers. If their powers are equal then it breaks ties using {@link revlex} reverse lexicographic order.
312
+ *
313
+ * @returns This polynomial after sorting its terms in place.
314
+ */
315
+ grevlexSort(): this;
316
+ /**
317
+ * Sorts the terms by graded lexicographic order
318
+ * grlex first compares their powers. If their powers are equal then it breaks ties using {@link lex} lexicographic order.
319
+ *
320
+ * @returns This polynomial after sorting its terms in place.
321
+ */
322
+ grlexSort(): this;
323
+ /**
324
+ * Tests whether the polynomial consists of one constant term.
325
+ *
326
+ * @returns `true` only for the one-term constant representation.
327
+ */
328
+ isConstant(): boolean;
329
+ /**
330
+ * Tests whether this polynomial has no terms or a zero leading term.
331
+ *
332
+ * @returns Whether the current term representation is zero.
333
+ */
334
+ isZero(): boolean;
335
+ /**
336
+ * Returns the leading coefficient under the current ordering.
337
+ *
338
+ * @returns The leading term's internal coefficient reference.
339
+ */
340
+ LC(): Expression;
341
+ /**
342
+ * Sorts the terms by {@link lex} lexicographic order
343
+ *
344
+ * @returns This polynomial after sorting its terms in place.
345
+ */
346
+ lexSort(): this;
347
+ /**
348
+ * Returns the leading monomial with unit coefficient.
349
+ *
350
+ * @returns A new term with copied powers and variables.
351
+ */
352
+ LM(): Term;
353
+ /**
354
+ * Returns the leading term under the current ordering.
355
+ *
356
+ * @returns The internal first term reference.
357
+ */
358
+ LT(): Term;
359
+ /**
360
+ * Gets the maximum variable occurrence in the polynomial. If two or more variables have
361
+ * an equal number of occurrences then they will be included in the set
362
+ *
363
+ * @returns A new record containing every variable tied for the greatest term-occurrence count.
364
+ * @example
365
+ * ```ts
366
+ * new Polynomial('q^3*a+2*q^2*a').maxVariableFrequency();
367
+ * // { a: { variable: 'a', count: 2, deg: 2 },
368
+ * // q: { variable: 'q', count: 2, deg: 5 } }
369
+ * ```
370
+ */
371
+ maxVariableFrequency(): Record<string | number, VariableFrequency>;
372
+ /**
373
+ * Subtracts a Polynomial or a Term
374
+ *
375
+ * @param x - Term or polynomial to subtract.
376
+ * @returns A new polynomial. Both operands are left unchanged.
377
+ */
378
+ minus(x: Term | Polynomial): Polynomial;
379
+ /**
380
+ * Reduces each collected coefficient modulo `n`.
381
+ *
382
+ * @remarks
383
+ * The polynomial itself is not modified. The returned coefficient object is derived from
384
+ * the current polynomial and stores the reduced coefficient expressions at the same power
385
+ * keys.
386
+ *
387
+ * @param n - Modulus passed to the symbolic `mod` operation.
388
+ * @returns A coefficient object containing the coefficient remainders.
389
+ */
390
+ mod(n: ExpressionInput): import("../expression/CoeffObject").CoeffObject;
391
+ /**
392
+ * Returns a copy with the leading nonconstant coefficient normalized to one.
393
+ *
394
+ * Constant polynomials are copied without coefficient normalization.
395
+ *
396
+ * @returns A new polynomial with a unit leading coefficient when normalization applies.
397
+ */
398
+ monic(): Polynomial;
399
+ /**
400
+ * Returns the leading term's multidegree under the current ordering.
401
+ *
402
+ * @returns The leading term's cached internal multidegree array.
403
+ */
404
+ multideg(): number[] | undefined;
405
+ /**
406
+ * Gets all the numeric coefficients in the polynomial as Rationals.
407
+ *
408
+ * @returns New array containing each term coefficient's internal rational multiplier.
409
+ */
410
+ numericCoeffs(): Rational[];
411
+ /**
412
+ * Reorders the polynomial in the requested ordering if it's not already in that particular ordering.
413
+ *
414
+ * @param ordering - Requested multivariate ordering. Univariate input is always degree-sorted.
415
+ * @returns This polynomial after sorting its term array in place.
416
+ */
417
+ order(ordering?: Ordering): this;
418
+ /**
419
+ * Adds a Polynomial or a Term.
420
+ *
421
+ * @param x - Term or polynomial to add.
422
+ * @returns A new polynomial. Both operands are left unchanged.
423
+ */
424
+ plus(x: Term | Polynomial): Polynomial;
425
+ /**
426
+ * Raises the polynomial to a power.
427
+ *
428
+ * @param p - Exponent accepted by symbolic expression powers.
429
+ * @returns A new polynomial parsed from the powered expression.
430
+ * @throws {@link core!PolynomialError} Thrown when the powered result is not polynomial-like.
431
+ */
432
+ pow(p: ExpressionInput): Polynomial;
433
+ /**
434
+ * Sorts the terms by {@link revlex} reverse lexicographic order
435
+ *
436
+ * @returns This polynomial after sorting its terms in place.
437
+ */
438
+ revlexSort(): this;
439
+ /**
440
+ * Sorts the terms in the standard form of decreasing powers.
441
+ */
442
+ sort(): this;
443
+ stripMonomialGCD(other: Polynomial): {
444
+ mGCD: Polynomial;
445
+ p: Polynomial;
446
+ q: Polynomial;
447
+ };
448
+ /**
449
+ * Formats the current ordered terms as canonical parser text.
450
+ *
451
+ * @returns `"0"` for an empty/zero term representation, otherwise the joined term text.
452
+ */
453
+ text(): string;
454
+ /**
455
+ * Multiplies this polynomial by a term or polynomial.
456
+ *
457
+ * @param x - Multiplier.
458
+ * @returns A new polynomial. Term multiplication copies this polynomial before
459
+ * updating its terms; polynomial multiplication rebuilds from symbolic expressions.
460
+ */
461
+ times(x: Term | Polynomial): Polynomial;
462
+ /**
463
+ * Converts univariate coefficients to a dense ascending-power array.
464
+ *
465
+ * @param asNumbers - Convert each coefficient through JavaScript `Number`.
466
+ * @param variable - Optional variable to collect as the dense power index.
467
+ * @returns New coefficient array with missing powers filled by zero expressions.
468
+ */
469
+ toArray(asNumbers: false, variable?: string): Expression[];
470
+ toArray(asNumbers: true, variable?: string): number[];
471
+ toArray(): Expression[];
472
+ /**
473
+ * Converts dense coefficients to numerator `bigint` values.
474
+ *
475
+ * @param assertInZ - Reject coefficients whose denominator is not one.
476
+ * @param variable - Optional variable to collect as the dense power index.
477
+ * @returns New ascending-power array of coefficient numerators.
478
+ * @throws Error Thrown when `assertInZ` is true and a coefficient is non-integral.
479
+ */
480
+ toBigIntArray(assertInZ?: boolean, variable?: string): bigint[];
481
+ /**
482
+ * Converts dense coefficients to new `Decimal` values using their expression text.
483
+ *
484
+ * @returns An ascending-power decimal coefficient array.
485
+ */
486
+ toDecimalArray(): Decimal[];
487
+ /**
488
+ * Returns the polynomial in a form for easy debugging.
489
+ *
490
+ * @returns The same canonical term text as {@link Polynomial.text}.
491
+ */
492
+ toString(): string;
493
+ /**
494
+ * Counts each variable's term occurrences and accumulated degree.
495
+ *
496
+ * @returns A new record keyed by variable. Each entry reports its name, number of
497
+ * nonzero-power terms, and sum of powers across those terms.
498
+ */
499
+ variableFrequency(): Record<string, VariableFrequency>;
500
+ }