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,69 @@
1
+ import { Expression } from '../expression/Expression';
2
+ import { Vector } from '../vector/Vector';
3
+ import { Polynomial } from './Polynomial';
4
+ import type { ExpressionInput } from '../../types';
5
+ /**
6
+ * Returns the degree of a polynomial expression.
7
+ *
8
+ * @remarks
9
+ * With no variable, `deg(p)` returns the total degree: the largest sum of powers in any
10
+ * term. With a variable, `deg(p, x)` returns the largest power of `x`, treating the other
11
+ * variables as coefficients. If the input cannot be converted to a polynomial, the call
12
+ * remains symbolic instead of throwing.
13
+ *
14
+ * @param x - Expression-like input or polynomial to inspect.
15
+ * @param variable - Optional variable whose degree should be returned.
16
+ * @returns A numeric expression for polynomial input, otherwise an unevaluated `deg(...)` call.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * deg('x^2*y^3+x').text(); // "5"
21
+ * deg('x^2*y^3+x', 'x').text(); // "2"
22
+ * deg('x^2*y^3+x', 'y').text(); // "3"
23
+ * ```
24
+ */
25
+ export declare function deg(x: ExpressionInput | Polynomial, variable?: ExpressionInput): Expression;
26
+ /**
27
+ * Returns the exact numeric content of polynomial expression input.
28
+ *
29
+ * @remarks
30
+ * Content means the greatest common divisor of the polynomial's numeric coefficients.
31
+ * For example, the content of `6*x^2+15*x*y-3*y` is `3`. This function does not choose
32
+ * a main variable or compute a polynomial-valued GCD of symbolic coefficient expressions.
33
+ * If expression conversion fails, the operation remains symbolic as `content(input)`.
34
+ *
35
+ * @param x - Expression-like input or polynomial to inspect.
36
+ * @returns A numeric expression for converted input, otherwise an unevaluated symbolic
37
+ * `content` call.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * content('6*x^2+15*x-3').text(); // "3"
42
+ * ```
43
+ */
44
+ export declare function content(x: ExpressionInput | Polynomial): Expression;
45
+ /**
46
+ * Returns the quotient and remainder of polynomial division.
47
+ *
48
+ * @remarks
49
+ * This is the parser-facing compatibility behavior historically exposed as `div(a,b)`.
50
+ * It delegates to the existing polynomial division implementation. When more than one
51
+ * variable is present, Nerdamer treats the input as a multivariable polynomial rather than
52
+ * silently choosing one variable and treating the others as coefficients. If either input
53
+ * is not polynomial-like, the legacy fallback is preserved as `[0, dividend]`. Once both
54
+ * inputs are polynomial, failures from the division engine are allowed to propagate.
55
+ */
56
+ export declare function div(dividend: ExpressionInput, divisor: ExpressionInput): Vector;
57
+ /**
58
+ * Divides two expressions using polynomial quotient/remainder reconstruction when possible.
59
+ *
60
+ * @remarks
61
+ * This restores the parser-facing compatibility behavior historically exposed as
62
+ * `divide(a,b)`: a successful polynomial division is returned as
63
+ * `quotient + remainder/divisor`, so the result is a reusable symbolic expression. When
64
+ * more than one variable is present, Nerdamer treats the input as a multivariable polynomial
65
+ * rather than silently choosing a main variable. Inputs outside the polynomial domain fall
66
+ * back to ordinary symbolic division. Once both inputs are polynomial, failures from the
67
+ * division engine are allowed to propagate.
68
+ */
69
+ export declare function divide(dividend: ExpressionInput, divisor: ExpressionInput): Expression;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deg = deg;
4
+ exports.content = content;
5
+ exports.div = div;
6
+ exports.divide = divide;
7
+ const Expression_1 = require("../expression/Expression");
8
+ const shortcuts_1 = require("../expression/shortcuts");
9
+ const utils_1 = require("../expression/utils");
10
+ const constants_1 = require("../parser/constants");
11
+ const Vector_1 = require("../vector/Vector");
12
+ const Polynomial_1 = require("./Polynomial");
13
+ const utils_2 = require("./utils");
14
+ /**
15
+ * Returns the degree of a polynomial expression.
16
+ *
17
+ * @remarks
18
+ * With no variable, `deg(p)` returns the total degree: the largest sum of powers in any
19
+ * term. With a variable, `deg(p, x)` returns the largest power of `x`, treating the other
20
+ * variables as coefficients. If the input cannot be converted to a polynomial, the call
21
+ * remains symbolic instead of throwing.
22
+ *
23
+ * @param x - Expression-like input or polynomial to inspect.
24
+ * @param variable - Optional variable whose degree should be returned.
25
+ * @returns A numeric expression for polynomial input, otherwise an unevaluated `deg(...)` call.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * deg('x^2*y^3+x').text(); // "5"
30
+ * deg('x^2*y^3+x', 'x').text(); // "2"
31
+ * deg('x^2*y^3+x', 'y').text(); // "3"
32
+ * ```
33
+ */
34
+ function deg(x, variable) {
35
+ let variableExpression;
36
+ let variableName;
37
+ if (variable !== undefined) {
38
+ variableExpression = Expression_1.Expression.create(variable);
39
+ variableName = (0, utils_1.assertPlainVariableAndGetString)(variableExpression);
40
+ }
41
+ let retval = undefined;
42
+ try {
43
+ const polynomial = Polynomial_1.Polynomial.isPolynomial(x) ? x : new Polynomial_1.Polynomial(x);
44
+ retval = Expression_1.Expression.create(polynomial.deg(variableName));
45
+ }
46
+ catch { }
47
+ const input = Polynomial_1.Polynomial.isPolynomial(x) ? x.getExpression() : x;
48
+ const args = variableExpression === undefined ? [input] : [input, variableExpression];
49
+ return retval ?? Expression_1.Expression.toFunction(constants_1.DEG, args);
50
+ }
51
+ /**
52
+ * Returns the exact numeric content of polynomial expression input.
53
+ *
54
+ * @remarks
55
+ * Content means the greatest common divisor of the polynomial's numeric coefficients.
56
+ * For example, the content of `6*x^2+15*x*y-3*y` is `3`. This function does not choose
57
+ * a main variable or compute a polynomial-valued GCD of symbolic coefficient expressions.
58
+ * If expression conversion fails, the operation remains symbolic as `content(input)`.
59
+ *
60
+ * @param x - Expression-like input or polynomial to inspect.
61
+ * @returns A numeric expression for converted input, otherwise an unevaluated symbolic
62
+ * `content` call.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * content('6*x^2+15*x-3').text(); // "3"
67
+ * ```
68
+ */
69
+ function content(x) {
70
+ let retval = undefined;
71
+ try {
72
+ const polynomial = Polynomial_1.Polynomial.isPolynomial(x) ? x : new Polynomial_1.Polynomial(x);
73
+ retval = Expression_1.Expression.create(polynomial.content());
74
+ }
75
+ catch { }
76
+ return retval ?? Expression_1.Expression.toFunction(constants_1.CONTENT, [Polynomial_1.Polynomial.isPolynomial(x) ? x.getExpression() : x]);
77
+ }
78
+ /**
79
+ * Returns the quotient and remainder of polynomial division.
80
+ *
81
+ * @remarks
82
+ * This is the parser-facing compatibility behavior historically exposed as `div(a,b)`.
83
+ * It delegates to the existing polynomial division implementation. When more than one
84
+ * variable is present, Nerdamer treats the input as a multivariable polynomial rather than
85
+ * silently choosing one variable and treating the others as coefficients. If either input
86
+ * is not polynomial-like, the legacy fallback is preserved as `[0, dividend]`. Once both
87
+ * inputs are polynomial, failures from the division engine are allowed to propagate.
88
+ */
89
+ function div(dividend, divisor) {
90
+ const numerator = Expression_1.Expression.create(dividend);
91
+ const denominator = Expression_1.Expression.create(divisor);
92
+ let retval;
93
+ if (numerator.isPolynomialLike() && denominator.isPolynomialLike()) {
94
+ const [quotient, remainder] = (0, utils_2.divide)(numerator, denominator);
95
+ retval = new Vector_1.Vector([quotient, remainder]);
96
+ }
97
+ else {
98
+ retval = new Vector_1.Vector([(0, shortcuts_1.zero)(), numerator]);
99
+ }
100
+ return retval;
101
+ }
102
+ /**
103
+ * Divides two expressions using polynomial quotient/remainder reconstruction when possible.
104
+ *
105
+ * @remarks
106
+ * This restores the parser-facing compatibility behavior historically exposed as
107
+ * `divide(a,b)`: a successful polynomial division is returned as
108
+ * `quotient + remainder/divisor`, so the result is a reusable symbolic expression. When
109
+ * more than one variable is present, Nerdamer treats the input as a multivariable polynomial
110
+ * rather than silently choosing a main variable. Inputs outside the polynomial domain fall
111
+ * back to ordinary symbolic division. Once both inputs are polynomial, failures from the
112
+ * division engine are allowed to propagate.
113
+ */
114
+ function divide(dividend, divisor) {
115
+ const numerator = Expression_1.Expression.create(dividend);
116
+ const denominator = Expression_1.Expression.create(divisor);
117
+ let retval;
118
+ if (numerator.isPolynomialLike() && denominator.isPolynomialLike()) {
119
+ const [quotient, remainder] = (0, utils_2.divide)(numerator, denominator);
120
+ retval = quotient.plus(remainder.div(denominator));
121
+ }
122
+ else {
123
+ retval = numerator.div(denominator);
124
+ }
125
+ return retval;
126
+ }
@@ -0,0 +1,62 @@
1
+ import { Polynomial } from './Polynomial';
2
+ import type { Expression } from '../expression/Expression';
3
+ import type { Ordering, PolyType } from './Polynomial';
4
+ /**
5
+ * Divides a polynomial by given list of divisors
6
+ * See - Ideals Varieties and Algorithms 4th ed. p.81
7
+ *
8
+ * @param Fs The array of divisors
9
+ * @param g The dividend
10
+ * @param ordering The ordering to be used (optional).
11
+ * @returns
12
+ */
13
+ export declare function polyDiv(Fs: PolyType[], g: PolyType, ordering?: Ordering, variables?: string[]): [Expression[], Expression];
14
+ /**
15
+ * Divides one polynomial by another
16
+ *
17
+ * @param f The dividend
18
+ * @param g The divisor
19
+ * @param ordering The ordering to be used (optional).
20
+ * @returns [The quotient, The remainder]
21
+ */
22
+ export declare function divide(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Expression[];
23
+ /**
24
+ * Computes the S-Polynomial given two polynomials
25
+ *
26
+ * @param f
27
+ * @param g
28
+ * @param ordering
29
+ * @param variables
30
+ * @returns
31
+ */
32
+ export declare function S(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Polynomial;
33
+ /**
34
+ * Combines all the variables of a set of polynomials
35
+ *
36
+ * @param F
37
+ * @returns
38
+ */
39
+ export declare function combinePolynomialVariables(F: Polynomial[]): string[];
40
+ /**
41
+ * Calculates the polynomial modulus of two polynomials as f mod g
42
+ *
43
+ * @param f
44
+ * @param g
45
+ * @param ordering
46
+ * @param variables
47
+ * @returns
48
+ */
49
+ export declare function polyMod(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Polynomial;
50
+ export declare function maxCommonVariableOccurrence(f: PolyType, g: PolyType): string | undefined;
51
+ /**
52
+ * Convert number to polynomial form.
53
+ * e.g. polynomialFromNumber (89, 1) = [8, 9] = 8*x+9
54
+ * e.g. polynomialFromNumber (89, 2) = [1, -1, -1] = x^2-x-1
55
+ * Try (x+4)(x+5)
56
+ *
57
+ * @param n The number
58
+ * @param p The power of the lead monomial
59
+ * @param base The base to use for the polynomial. Default = 10
60
+ * @returns
61
+ */
62
+ export declare function polynomialFromNumber(n: number, p: number, base?: number, startingCoeff?: number, endingCoeff?: number): number[];
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyDiv = polyDiv;
4
+ exports.divide = divide;
5
+ exports.S = S;
6
+ exports.combinePolynomialVariables = combinePolynomialVariables;
7
+ exports.polyMod = polyMod;
8
+ exports.maxCommonVariableOccurrence = maxCommonVariableOccurrence;
9
+ exports.polynomialFromNumber = polynomialFromNumber;
10
+ const utils_1 = require("../../functions/utils");
11
+ const shortcuts_1 = require("../expression/shortcuts");
12
+ const Polynomial_1 = require("./Polynomial");
13
+ function normalizePolynomialInputs(inputs, ordering, variables) {
14
+ const provisional = inputs.map(input => Polynomial_1.Polynomial.toPolynomial(input, ordering, variables));
15
+ if (variables !== undefined) {
16
+ return {
17
+ polynomials: provisional,
18
+ variables,
19
+ };
20
+ }
21
+ const resolvedVariables = combinePolynomialVariables(provisional);
22
+ if (resolvedVariables.length === 0) {
23
+ return {
24
+ polynomials: provisional,
25
+ variables: undefined,
26
+ };
27
+ }
28
+ return {
29
+ polynomials: inputs.map(input => Polynomial_1.Polynomial.toPolynomial(input, ordering, resolvedVariables)),
30
+ variables: resolvedVariables,
31
+ };
32
+ }
33
+ /**
34
+ * Divides a polynomial by given list of divisors
35
+ * See - Ideals Varieties and Algorithms 4th ed. p.81
36
+ *
37
+ * @param Fs The array of divisors
38
+ * @param g The dividend
39
+ * @param ordering The ordering to be used (optional).
40
+ * @returns
41
+ */
42
+ function polyDiv(Fs, g, ordering, variables) {
43
+ const { polynomials } = normalizePolynomialInputs([...Fs, g], ordering, variables);
44
+ const F = polynomials.slice(0, Fs.length);
45
+ let p = polynomials[Fs.length].order(ordering);
46
+ // The collection of q's to be returned
47
+ const qArray = Fs.map(() => {
48
+ return (0, shortcuts_1.zero)();
49
+ });
50
+ let r = (0, shortcuts_1.zero)();
51
+ let iter = 0;
52
+ const maxIter = Fs.length * 1000;
53
+ // Begin
54
+ while (!p.isZero()) {
55
+ if (iter++ > maxIter) {
56
+ throw new Error('Maximum iterations reached');
57
+ }
58
+ let divisionOccurred = false;
59
+ const s = F.length;
60
+ let i = 0; // Use zero since TS arrays are zero based
61
+ while (i < s && !divisionOccurred) {
62
+ const fi = F[i];
63
+ const fiLT = fi.LT();
64
+ const pLT = p.LT();
65
+ if (fiLT.divides(pLT)) {
66
+ const q = pLT.div(fiLT);
67
+ qArray[i] = qArray[i].plus(q.getExpression());
68
+ // Guarantees a reduction at each step
69
+ p = p.minus(fi.times(q)).order(ordering);
70
+ divisionOccurred = true;
71
+ }
72
+ else {
73
+ i++;
74
+ }
75
+ }
76
+ const pLT = p.LT();
77
+ if (!divisionOccurred) {
78
+ r = r.plus(pLT.getExpression());
79
+ p = p.minus(pLT).order(ordering);
80
+ }
81
+ }
82
+ return [qArray, r];
83
+ }
84
+ /**
85
+ * Divides one polynomial by another
86
+ *
87
+ * @param f The dividend
88
+ * @param g The divisor
89
+ * @param ordering The ordering to be used (optional).
90
+ * @returns [The quotient, The remainder]
91
+ */
92
+ function divide(f, g, ordering, variables) {
93
+ const [quo, rem] = polyDiv([g], f, ordering, variables);
94
+ return [quo[0], rem];
95
+ }
96
+ /**
97
+ * Computes the S-Polynomial given two polynomials
98
+ *
99
+ * @param f
100
+ * @param g
101
+ * @param ordering
102
+ * @param variables
103
+ * @returns
104
+ */
105
+ function S(f, g, ordering, variables) {
106
+ const { polynomials: [p, q], } = normalizePolynomialInputs([f, g], ordering, variables);
107
+ const pLT = p.LT();
108
+ const qLT = q.LT();
109
+ const xg = pLT.LCM(qLT);
110
+ return p.times(xg.div(pLT)).minus(q.times(xg.div(qLT)));
111
+ }
112
+ /**
113
+ * Combines all the variables of a set of polynomials
114
+ *
115
+ * @param F
116
+ * @returns
117
+ */
118
+ function combinePolynomialVariables(F) {
119
+ let variables = [];
120
+ F.forEach(f => {
121
+ variables = (0, utils_1.arrayAddUnique)(variables, f.variables);
122
+ });
123
+ variables.sort();
124
+ return variables;
125
+ }
126
+ /**
127
+ * Calculates the polynomial modulus of two polynomials as f mod g
128
+ *
129
+ * @param f
130
+ * @param g
131
+ * @param ordering
132
+ * @param variables
133
+ * @returns
134
+ */
135
+ function polyMod(f, g, ordering, variables) {
136
+ const { variables: resolvedVariables } = normalizePolynomialInputs([f, g], ordering, variables);
137
+ const [, rem] = divide(f, g, ordering, resolvedVariables);
138
+ return Polynomial_1.Polynomial.toPolynomial(rem, ordering, resolvedVariables).order(ordering);
139
+ }
140
+ function maxCommonVariableOccurrence(f, g) {
141
+ const a = Polynomial_1.Polynomial.toPolynomial(f).maxVariableFrequency();
142
+ const b = Polynomial_1.Polynomial.toPolynomial(g).maxVariableFrequency();
143
+ // At this point any variable will do as long as it occurs in both a and b
144
+ for (const x in a) {
145
+ if (x in b) {
146
+ return x;
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Convert number to polynomial form.
152
+ * e.g. polynomialFromNumber (89, 1) = [8, 9] = 8*x+9
153
+ * e.g. polynomialFromNumber (89, 2) = [1, -1, -1] = x^2-x-1
154
+ * Try (x+4)(x+5)
155
+ *
156
+ * @param n The number
157
+ * @param p The power of the lead monomial
158
+ * @param base The base to use for the polynomial. Default = 10
159
+ * @returns
160
+ */
161
+ function polynomialFromNumber(n, p, base = 10, startingCoeff, endingCoeff) {
162
+ const remainder = function (a, b) {
163
+ if (a === 0) {
164
+ return 0;
165
+ }
166
+ return Math.abs(a) < Math.abs(b) ? -(b % a) : a % b;
167
+ };
168
+ const coeffs = [];
169
+ for (let i = p; i >= 0; i--) {
170
+ // Calculate the base
171
+ const m = base ** i;
172
+ // console.log(`m: ${m}, n: ${n}`)
173
+ // Get the mod. This will be negative if the
174
+ const rem = remainder(n, m);
175
+ const d = n - rem;
176
+ const coeff = d / m;
177
+ if (i === p && (coeff < 1 || startingCoeff !== undefined)) {
178
+ const c = startingCoeff || 1;
179
+ coeffs.push(c);
180
+ n -= c * m;
181
+ continue;
182
+ }
183
+ // Avoid fractions as coefficients
184
+ if (Math.abs(d) < Math.abs(m)) {
185
+ coeffs.push(0);
186
+ }
187
+ else {
188
+ // console.log(`d: ${d}, rem: ${rem}, n: ${n}, coeff: ${coeff}`)
189
+ // Push the coefficient
190
+ coeffs.push(coeff);
191
+ // Point to the remainder as the new number
192
+ n = rem;
193
+ }
194
+ }
195
+ // Adjust if the ending coeff is provided. If it cannot be adjusted then the current
196
+ // constant will be used
197
+ if (endingCoeff !== undefined) {
198
+ const lastIndex = coeffs.length - 1;
199
+ const newCoeff = coeffs[lastIndex] - endingCoeff;
200
+ if (newCoeff % base === 0) {
201
+ coeffs[lastIndex] = endingCoeff;
202
+ coeffs[lastIndex - 1] += newCoeff / base;
203
+ }
204
+ }
205
+ return coeffs.reverse();
206
+ }