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,350 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Equation = void 0;
4
+ const common_1 = require("../../common/common");
5
+ const errors_1 = require("../../errors");
6
+ const Expression_1 = require("../expression/Expression");
7
+ const shortcuts_1 = require("../expression/shortcuts");
8
+ const constants_1 = require("../parser/constants");
9
+ /**
10
+ * Represents a symbolic equality between two expression sides.
11
+ *
12
+ * @remarks
13
+ * An `Equation` stores its left- and right-hand sides as public {@link Expression}
14
+ * references. The constructor does not copy those expressions, so mutating a supplied
15
+ * expression later, or mutating {@link Equation.LHS} or {@link Equation.RHS} directly,
16
+ * changes the equation. Use {@link Equation.copy} when an independent equation is needed.
17
+ *
18
+ * Arithmetic methods apply an operation to both sides, but that does not by itself prove
19
+ * that the transformed equation has exactly the same solution set. For example, multiplying
20
+ * or dividing by an expression whose value may be zero requires additional domain reasoning.
21
+ * Solver-facing code should account for those mathematical conditions.
22
+ *
23
+ * Absolute value is not supported as an equation rewrite because applying it
24
+ * independently to both sides can change the solution set. {@link Equation.abs} remains only
25
+ * as a compatibility member of the general parser-entity surface and always throws. Callers
26
+ * performing a non-equivalent transformation can use {@link Equation.each} explicitly.
27
+ *
28
+ * Equation comparisons reduce each equation to its residual `LHS - RHS` and then use the
29
+ * corresponding {@link Expression} comparison. They compare those residual expressions;
30
+ * they do not establish logical or solution-set equivalence between arbitrary equations.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const equation = new Equation(Expression.create('x + 1'), Expression.create(3));
35
+ * equation.text(); // "1+x=3"
36
+ * equation.toLHS().text(); // "-2+x=0"
37
+ * ```
38
+ */
39
+ class Equation {
40
+ /** Parser entity tag used to identify equation values. */
41
+ dataType = constants_1.EQUATION;
42
+ /** Indicates that equations are not elementwise enumerable parser aggregates. */
43
+ isEnumerable = false;
44
+ /** Mutable left-hand side expression stored by this equation. */
45
+ LHS;
46
+ /**
47
+ * Optional parser-entity precision metadata.
48
+ *
49
+ * `Equation` itself does not currently use this value when performing equation
50
+ * operations or formatting its sides.
51
+ */
52
+ precision;
53
+ /** Mutable right-hand side expression stored by this equation. */
54
+ RHS;
55
+ /**
56
+ * Creates an equation from two expression objects.
57
+ *
58
+ * @remarks
59
+ * The supplied expressions are stored by reference rather than copied. This preserves
60
+ * object identity but also means subsequent mutation of either expression is visible
61
+ * through the equation.
62
+ *
63
+ * @param lhs - Expression to store on the left-hand side.
64
+ * @param rhs - Expression to store on the right-hand side.
65
+ */
66
+ constructor(lhs, rhs) {
67
+ this.LHS = lhs;
68
+ this.RHS = rhs;
69
+ }
70
+ /**
71
+ * Tests whether a value carries Nerdamer's equation parser-entity tag.
72
+ *
73
+ * @remarks
74
+ * This is a tag-based type guard rather than an `instanceof` check. It therefore
75
+ * recognizes compatible equation objects by their `dataType` value.
76
+ *
77
+ * @param obj - Value to inspect.
78
+ * @returns `true` when the value is tagged as an equation.
79
+ */
80
+ static isEquation(obj) {
81
+ return (0, common_1.isNerdamerNativeType)(obj, constants_1.EQUATION);
82
+ }
83
+ /**
84
+ * Rejects absolute value as an equation transformation.
85
+ *
86
+ * @remarks
87
+ * Replacing `a = b` with `|a| = |b|` is not generally solution-set preserving. This
88
+ * method remains on `Equation` so the general {@link ParserEntity} surface can retain
89
+ * its historical `abs()` member without reintroducing the unsafe transformation.
90
+ *
91
+ * Use {@link Equation.each} explicitly to transform
92
+ * each side and accepts responsibility for the changed equation semantics.
93
+ *
94
+ * @throws {@link core!UnsupportedOperationError} Always; absolute value is not a supported
95
+ * equation operation.
96
+ * @deprecated Absolute value is not supported for equations.
97
+ */
98
+ abs() {
99
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
100
+ }
101
+ /**
102
+ * Legacy alias for {@link Equation.plus}.
103
+ *
104
+ * @param x - Value to add to both sides.
105
+ * @returns A new equation; the current equation is not modified.
106
+ */
107
+ add(x) {
108
+ return this.plus(x);
109
+ }
110
+ /**
111
+ * Creates an independent copy of this equation and both expression sides.
112
+ *
113
+ * @returns A new equation whose left- and right-hand expressions are deep copies.
114
+ */
115
+ copy() {
116
+ return new Equation(this.LHS.copy(), this.RHS.copy());
117
+ }
118
+ /**
119
+ * Divides both sides by the same nonzero number.
120
+ *
121
+ * A symbolic divisor is rejected because Nerdamer cannot assume that it is nonzero for
122
+ * every solution of the equation.
123
+ *
124
+ * @param x - Nonzero numeric value by which both sides are divided.
125
+ * @returns A new equation; the current equation is not modified.
126
+ * @throws {@link core!UnsupportedOperationError} If `x` is zero or is not numeric.
127
+ */
128
+ div(x) {
129
+ if (Equation.isEquation(x)) {
130
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
131
+ }
132
+ const expr = Expression_1.Expression.create(x);
133
+ if (!expr.isNUM() || expr.isZero()) {
134
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
135
+ }
136
+ return new Equation(this.LHS.div(expr), this.RHS.div(expr));
137
+ }
138
+ /**
139
+ * Applies a callback to the two equation sides and rebuilds the equation from its results.
140
+ *
141
+ * @remarks
142
+ * The callback receives the stored left- and right-hand {@link Expression} references
143
+ * directly, with indices `0` and `1` respectively. Returned expressions are stored by
144
+ * reference in a new equation. The callback can therefore mutate the original equation
145
+ * if it mutates either argument before returning.
146
+ *
147
+ * Both callback results must be expressions. Other parser entities are rejected after
148
+ * the callback has run.
149
+ *
150
+ * @param fn - Transformation applied to the left and right sides.
151
+ * @returns A new equation containing the callback results.
152
+ * @throws {@link core!UnexpectedDataType}
153
+ * Thrown when either callback result is not an {@link Expression}.
154
+ */
155
+ each(fn) {
156
+ const lhs = fn(this.LHS, 0);
157
+ const rhs = fn(this.RHS, 1);
158
+ if (Expression_1.Expression.isExpression(lhs) && Expression_1.Expression.isExpression(rhs)) {
159
+ return new Equation(lhs, rhs);
160
+ }
161
+ const receivedTypes = `${constants_1.dataTypes[lhs.dataType] || typeof lhs} & ${constants_1.dataTypes[rhs.dataType] || typeof rhs}`;
162
+ throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: receivedTypes }));
163
+ }
164
+ /**
165
+ * Compares this equation with another equation by comparing their residual expressions.
166
+ *
167
+ * @remarks
168
+ * Each equation is copied and rewritten as `LHS - RHS = 0`, then the two residual
169
+ * expressions are compared with {@link Expression.eq}. Equations with the same
170
+ * solution set are not necessarily equal by this method; for example, scaling an
171
+ * equation by a nonzero constant changes its residual expression.
172
+ *
173
+ * @param eq - Parser entity to compare with this equation.
174
+ * @returns `true` when `eq` is an equation and the two residual expressions compare equal.
175
+ */
176
+ eq(eq) {
177
+ if (!Equation.isEquation(eq)) {
178
+ return false;
179
+ }
180
+ return this.toLHS().LHS.eq(eq.toLHS().LHS);
181
+ }
182
+ /**
183
+ * Numerically re-evaluates both equation sides.
184
+ *
185
+ * @returns A new equation containing evaluated copies of the two sides.
186
+ */
187
+ evaluate() {
188
+ return this.copy().each(e => e.evaluate());
189
+ }
190
+ /**
191
+ * Expands both sides of a copied equation.
192
+ *
193
+ * @returns A new equation containing the expanded left- and right-hand sides.
194
+ */
195
+ expand() {
196
+ const retval = this.copy().each(e => e.expand());
197
+ return retval;
198
+ }
199
+ /**
200
+ * Orders this equation against another equation by comparing their residual expressions.
201
+ *
202
+ * @remarks
203
+ * Both equations are rewritten as `LHS - RHS = 0`, and the resulting expressions are
204
+ * compared with {@link Expression.gt}. This is an ordering of residual expressions,
205
+ * not a statement that one equation or solution set is logically greater than another.
206
+ *
207
+ * @param eq - Parser entity to compare with this equation.
208
+ * @returns `true` when `eq` is an equation and this residual compares greater.
209
+ */
210
+ gt(eq) {
211
+ if (!Equation.isEquation(eq)) {
212
+ return false;
213
+ }
214
+ return this.toLHS().LHS.gt(eq.toLHS().LHS);
215
+ }
216
+ /**
217
+ * Residual-expression comparison corresponding to `>=`.
218
+ *
219
+ * @param x - Parser entity to compare with this equation.
220
+ * @returns `true` when {@link Equation.gt} or {@link Equation.eq} succeeds.
221
+ */
222
+ gte(x) {
223
+ return this.gt(x) || this.eq(x);
224
+ }
225
+ /**
226
+ * Orders this equation against another equation by comparing their residual expressions.
227
+ *
228
+ * @remarks
229
+ * Both equations are rewritten as `LHS - RHS = 0`, and the resulting expressions are
230
+ * compared with {@link Expression.lt}. This is an ordering of residual expressions,
231
+ * not a statement that one equation or solution set is logically less than another.
232
+ *
233
+ * @param eq - Parser entity to compare with this equation.
234
+ * @returns `true` when `eq` is an equation and this residual compares less.
235
+ */
236
+ lt(eq) {
237
+ if (!Equation.isEquation(eq)) {
238
+ return false;
239
+ }
240
+ return this.toLHS().LHS.lt(eq.toLHS().LHS);
241
+ }
242
+ /**
243
+ * Residual-expression comparison corresponding to `<=`.
244
+ *
245
+ * @param x - Parser entity to compare with this equation.
246
+ * @returns `true` when {@link Equation.lt} or {@link Equation.eq} succeeds.
247
+ */
248
+ lte(x) {
249
+ return this.lt(x) || this.eq(x);
250
+ }
251
+ /**
252
+ * Subtracts the same value from both sides.
253
+ *
254
+ * @param x - Value to subtract from the left- and right-hand sides.
255
+ * @returns A new equation; the current equation is not modified.
256
+ */
257
+ minus(x) {
258
+ if (Equation.isEquation(x)) {
259
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
260
+ }
261
+ const expr = Expression_1.Expression.create(x);
262
+ return this.each(e => e.minus(expr));
263
+ }
264
+ /**
265
+ * Legacy alias for {@link Equation.times}.
266
+ *
267
+ * @param x - Nonzero numeric value by which both sides are multiplied.
268
+ * @returns This equation after mutation.
269
+ */
270
+ multiply(x) {
271
+ return this.times(x);
272
+ }
273
+ /**
274
+ * Adds the same value to both sides.
275
+ *
276
+ * @param x - Value to add to the left- and right-hand sides.
277
+ * @returns A new equation; the current equation is not modified.
278
+ */
279
+ plus(x) {
280
+ if (Equation.isEquation(x)) {
281
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
282
+ }
283
+ const expr = Expression_1.Expression.create(x);
284
+ return this.each(e => e.plus(expr));
285
+ }
286
+ /**
287
+ * Legacy alias for {@link Equation.minus}.
288
+ *
289
+ * @param x - Value to subtract from both sides.
290
+ * @returns A new equation; the current equation is not modified.
291
+ */
292
+ subtract(x) {
293
+ return this.minus(x);
294
+ }
295
+ /**
296
+ * Returns the canonical text form `LHS=RHS`.
297
+ *
298
+ * @returns The two side representations joined by `=`.
299
+ */
300
+ text() {
301
+ return `${this.LHS.text()}=${this.RHS.text()}`;
302
+ }
303
+ /**
304
+ * Multiplies both sides by the same nonzero number.
305
+ *
306
+ * A symbolic multiplier is rejected because it may be zero for some solutions and add
307
+ * solutions that were not present in the original equation.
308
+ *
309
+ * @param x - Nonzero numeric value by which both sides are multiplied.
310
+ * @returns This equation after mutation.
311
+ * @throws {@link core!UnsupportedOperationError} If `x` is zero or is not numeric.
312
+ */
313
+ times(x) {
314
+ if (Equation.isEquation(x)) {
315
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
316
+ }
317
+ const expr = Expression_1.Expression.create(x);
318
+ if (!expr.isNUM() || expr.isZero()) {
319
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
320
+ }
321
+ this.LHS = this.LHS.times(expr);
322
+ this.RHS = this.RHS.times(expr);
323
+ return this;
324
+ }
325
+ /**
326
+ * Rewrites this equation as an equivalent residual form with zero on the right.
327
+ *
328
+ * @remarks
329
+ * The equation and both sides are copied before `RHS` is subtracted from `LHS`, so the
330
+ * current equation is not modified. The result has the form `LHS - RHS = 0` and is used
331
+ * by solver preparation and the equation comparison methods.
332
+ *
333
+ * @returns A new equation with the residual expression on the left and zero on the right.
334
+ */
335
+ toLHS() {
336
+ const eq = this.copy();
337
+ eq.LHS = eq.LHS.minus(eq.RHS);
338
+ eq.RHS = (0, shortcuts_1.zero)();
339
+ return eq;
340
+ }
341
+ /**
342
+ * Returns the same canonical equation text as {@link Equation.text}.
343
+ *
344
+ * @returns The equation text representation.
345
+ */
346
+ toString() {
347
+ return this.text();
348
+ }
349
+ }
350
+ exports.Equation = Equation;
@@ -0,0 +1,100 @@
1
+ import { Polynomial } from '../polynomial/Polynomial';
2
+ import { Vector } from '../vector/Vector';
3
+ import { Expression } from './Expression';
4
+ /**
5
+ * Stores coefficients indexed by the power or multidegree collected from an expression.
6
+ *
7
+ * @remarks
8
+ * {@link Expression.coeffs} and {@link Polynomial.coeffs} use string keys. A
9
+ * univariate coefficient uses a key such as `"2"`; multivariate collection uses a
10
+ * comma-separated degree tuple such as `"1,0"`, in the same order as
11
+ * {@link CoeffObject.variables}.
12
+ *
13
+ * The object is mutable. The constructor retains the supplied `variables` array, and
14
+ * the public `coeffs` record exposes the stored expression references directly.
15
+ * Methods such as {@link CoeffObject.toArray} are intended for univariate numeric power
16
+ * keys; a multidegree key cannot be represented by that dense array form.
17
+ */
18
+ export declare class CoeffObject {
19
+ /** Mutable coefficient expressions keyed by power or comma-separated multidegree. */
20
+ coeffs: {
21
+ [key: string]: Expression;
22
+ };
23
+ /** Variables whose order defines the degree keys in {@link coeffs}. */
24
+ variables: string[];
25
+ /**
26
+ * Creates an empty coefficient collection for the requested variable order.
27
+ *
28
+ * @param variables - Variables used to interpret coefficient degree keys. The array
29
+ * is retained by reference.
30
+ */
31
+ constructor(variables: string[]);
32
+ /** Rebuilds the stored degree keys and coefficients as independent polynomial terms. */
33
+ private buildTerms;
34
+ /**
35
+ * Adds an expression to the coefficient stored at a degree key.
36
+ *
37
+ * A new key retains `value` by reference. An existing key is replaced with the
38
+ * expression returned by symbolic addition.
39
+ *
40
+ * @param key - Power or comma-separated multidegree key.
41
+ * @param value - Coefficient contribution to accumulate.
42
+ */
43
+ add(key: string, value: Expression): void;
44
+ /**
45
+ * Visits each stored coefficient and its degree key.
46
+ *
47
+ * @param fn - Callback receiving the stored expression reference and key.
48
+ * @returns This coefficient object for chaining.
49
+ */
50
+ each(fn: (e: Expression, p: string) => void): this;
51
+ /**
52
+ * Returns the stored coefficient for a power or multidegree key.
53
+ *
54
+ * @param p - Key to look up.
55
+ * @returns The internal expression reference, or `undefined` when the key is absent.
56
+ */
57
+ getPower(p: string | number): Expression;
58
+ /**
59
+ * Tests whether a power or multidegree key is present, including an explicit zero.
60
+ *
61
+ * @param p - Key to test.
62
+ */
63
+ hasPower(p: string | number): boolean;
64
+ /** Returns the greatest numeric power key, or `NaN` when any key is non-numeric. */
65
+ max(): number;
66
+ /**
67
+ * Formats the sparse coefficient record for inspection.
68
+ *
69
+ * @param formatted - Add line breaks and indentation between entries.
70
+ */
71
+ text(formatted?: boolean): string;
72
+ toArray(): Expression[];
73
+ toArray(asNumber: false): Expression[];
74
+ toArray(asNumber: true): number[];
75
+ /** Reconstructs the stored coefficients as a native symbolic expression. */
76
+ toExpression(): Expression;
77
+ /**
78
+ * Builds parser text representing the stored coefficient terms.
79
+ *
80
+ * Each degree key is interpreted using the configured variable order, including
81
+ * comma-separated multidegrees such as `"2,1"` for `x^2*y`.
82
+ */
83
+ toParsableString(): string;
84
+ /**
85
+ * Reconstructs the coefficients as a {@link Polynomial} without reparsing ordinary terms.
86
+ *
87
+ * Coefficients that contain one of the configured polynomial variables are passed through
88
+ * the normal constructor so overlapping coefficient and monomial powers are canonicalized.
89
+ *
90
+ * @returns A new polynomial with independent terms and a synchronized expression.
91
+ */
92
+ toPolynomial(): Polynomial;
93
+ toString(): string;
94
+ /**
95
+ * Converts univariate coefficients to a dense {@link Vector} ordered by ascending power.
96
+ *
97
+ * Missing powers are represented by zero expressions.
98
+ */
99
+ toVector(): Vector;
100
+ }
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoeffObject = void 0;
4
+ const errors_1 = require("../../errors");
5
+ const Polynomial_1 = require("../polynomial/Polynomial");
6
+ const Term_1 = require("../polynomial/Term");
7
+ const Vector_1 = require("../vector/Vector");
8
+ const Expression_1 = require("./Expression");
9
+ const shortcuts_1 = require("./shortcuts");
10
+ /**
11
+ * Stores coefficients indexed by the power or multidegree collected from an expression.
12
+ *
13
+ * @remarks
14
+ * {@link Expression.coeffs} and {@link Polynomial.coeffs} use string keys. A
15
+ * univariate coefficient uses a key such as `"2"`; multivariate collection uses a
16
+ * comma-separated degree tuple such as `"1,0"`, in the same order as
17
+ * {@link CoeffObject.variables}.
18
+ *
19
+ * The object is mutable. The constructor retains the supplied `variables` array, and
20
+ * the public `coeffs` record exposes the stored expression references directly.
21
+ * Methods such as {@link CoeffObject.toArray} are intended for univariate numeric power
22
+ * keys; a multidegree key cannot be represented by that dense array form.
23
+ */
24
+ class CoeffObject {
25
+ /** Mutable coefficient expressions keyed by power or comma-separated multidegree. */
26
+ coeffs = {};
27
+ /** Variables whose order defines the degree keys in {@link coeffs}. */
28
+ variables;
29
+ /**
30
+ * Creates an empty coefficient collection for the requested variable order.
31
+ *
32
+ * @param variables - Variables used to interpret coefficient degree keys. The array
33
+ * is retained by reference.
34
+ */
35
+ constructor(variables) {
36
+ this.variables = variables;
37
+ }
38
+ /** Rebuilds the stored degree keys and coefficients as independent polynomial terms. */
39
+ buildTerms() {
40
+ const retval = [];
41
+ for (const powers in this.coeffs) {
42
+ retval.push(new Term_1.Term(new Expression_1.Expression(this.coeffs[powers]), powers, this.variables));
43
+ }
44
+ return retval;
45
+ }
46
+ /**
47
+ * Adds an expression to the coefficient stored at a degree key.
48
+ *
49
+ * A new key retains `value` by reference. An existing key is replaced with the
50
+ * expression returned by symbolic addition.
51
+ *
52
+ * @param key - Power or comma-separated multidegree key.
53
+ * @param value - Coefficient contribution to accumulate.
54
+ */
55
+ add(key, value) {
56
+ const e = this.coeffs[key];
57
+ this.coeffs[key] = e ? e.plus(value) : value;
58
+ }
59
+ /**
60
+ * Visits each stored coefficient and its degree key.
61
+ *
62
+ * @param fn - Callback receiving the stored expression reference and key.
63
+ * @returns This coefficient object for chaining.
64
+ */
65
+ each(fn) {
66
+ for (const x in this.coeffs) {
67
+ fn(this.coeffs[x], x);
68
+ }
69
+ return this;
70
+ }
71
+ /**
72
+ * Returns the stored coefficient for a power or multidegree key.
73
+ *
74
+ * @param p - Key to look up.
75
+ * @returns The internal expression reference, or `undefined` when the key is absent.
76
+ */
77
+ getPower(p) {
78
+ return this.coeffs[p];
79
+ }
80
+ /**
81
+ * Tests whether a power or multidegree key is present, including an explicit zero.
82
+ *
83
+ * @param p - Key to test.
84
+ */
85
+ hasPower(p) {
86
+ return p in this.coeffs;
87
+ }
88
+ /** Returns the greatest numeric power key, or `NaN` when any key is non-numeric. */
89
+ max() {
90
+ const powers = Object.keys(this.coeffs).map(x => {
91
+ return Number(x);
92
+ });
93
+ return Math.max(...powers);
94
+ }
95
+ /**
96
+ * Formats the sparse coefficient record for inspection.
97
+ *
98
+ * @param formatted - Add line breaks and indentation between entries.
99
+ */
100
+ text(formatted = false) {
101
+ const n = formatted ? '\n' : '';
102
+ const t = formatted ? ' ' : '';
103
+ const values = [];
104
+ const d = `, ` + n;
105
+ for (const x in this.coeffs) {
106
+ values.push(`${t}${x}: ${this.coeffs[x]}`);
107
+ }
108
+ return `{ ${n}${values.join(d)} ${n}}`;
109
+ }
110
+ /**
111
+ * Converts univariate coefficients to a dense array indexed by power.
112
+ *
113
+ * Missing powers are filled with new zero expressions. With `asNumber: true`, each
114
+ * coefficient is converted using JavaScript numeric conversion, which may lose exact
115
+ * precision. The method does not remove or copy coefficients already stored here.
116
+ *
117
+ * @param asNumber - Return JavaScript numbers instead of expressions.
118
+ * @throws {@link NaNError} Thrown when a key, such as a multidegree tuple, cannot be
119
+ * interpreted as a numeric univariate power.
120
+ */
121
+ toArray(asNumber = false) {
122
+ const max = this.max();
123
+ const coeffs = [];
124
+ if (isNaN(max)) {
125
+ throw new errors_1.NaNError((0, errors_1.message)('cannotCreateArrayFromNaN'));
126
+ }
127
+ for (let i = 0; i <= max; i++) {
128
+ let coeff = this.coeffs[i];
129
+ // Fill voids with zero
130
+ if (!coeff) {
131
+ coeff = (0, shortcuts_1.zero)();
132
+ }
133
+ coeffs[i] = asNumber ? Number(coeff) : coeff;
134
+ }
135
+ return coeffs;
136
+ }
137
+ /** Reconstructs the stored coefficients as a native symbolic expression. */
138
+ toExpression() {
139
+ let retval = (0, shortcuts_1.zero)();
140
+ for (const term of this.buildTerms()) {
141
+ if (!term.isZero()) {
142
+ retval = retval.plus(term.getExpression());
143
+ }
144
+ }
145
+ return retval;
146
+ }
147
+ /**
148
+ * Builds parser text representing the stored coefficient terms.
149
+ *
150
+ * Each degree key is interpreted using the configured variable order, including
151
+ * comma-separated multidegrees such as `"2,1"` for `x^2*y`.
152
+ */
153
+ toParsableString() {
154
+ const terms = [];
155
+ for (const term of this.buildTerms()) {
156
+ if (!term.isZero()) {
157
+ terms.push(term.text(this.variables));
158
+ }
159
+ }
160
+ return terms.join('+').replace(/\+-/g, '-');
161
+ }
162
+ /**
163
+ * Reconstructs the coefficients as a {@link Polynomial} without reparsing ordinary terms.
164
+ *
165
+ * Coefficients that contain one of the configured polynomial variables are passed through
166
+ * the normal constructor so overlapping coefficient and monomial powers are canonicalized.
167
+ *
168
+ * @returns A new polynomial with independent terms and a synchronized expression.
169
+ */
170
+ toPolynomial() {
171
+ const terms = this.buildTerms();
172
+ const requiresCanonicalization = terms.some(term => this.variables.some(variable => term.coeff.hasVariable(variable)));
173
+ const expression = this.toExpression();
174
+ let retval;
175
+ if (requiresCanonicalization) {
176
+ retval = new Polynomial_1.Polynomial(expression, this.variables);
177
+ }
178
+ else {
179
+ retval = new Polynomial_1.Polynomial((0, shortcuts_1.zero)(), this.variables);
180
+ retval.terms = terms.filter(term => !term.isZero());
181
+ retval.order();
182
+ retval.expression = expression;
183
+ }
184
+ return retval;
185
+ }
186
+ toString() {
187
+ return this.text();
188
+ }
189
+ /**
190
+ * Converts univariate coefficients to a dense {@link Vector} ordered by ascending power.
191
+ *
192
+ * Missing powers are represented by zero expressions.
193
+ */
194
+ toVector() {
195
+ return new Vector_1.Vector(this.toArray());
196
+ }
197
+ }
198
+ exports.CoeffObject = CoeffObject;