nerdamer 1.1.13 → 2.0.0-rc.2

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 (387) hide show
  1. package/BREAKING_CHANGES.md +244 -5
  2. package/LICENSE.md +184 -0
  3. package/README.md +232 -318
  4. package/dist/bundle.js +2 -0
  5. package/dist/bundle.js.LICENSE.txt +7 -0
  6. package/dist/parser.js +2 -0
  7. package/dist/parser.js.LICENSE.txt +7 -0
  8. package/docs-data/parser-functions.json +2248 -0
  9. package/index.d.ts +10 -426
  10. package/output/algebra/adapters.d.ts +3 -0
  11. package/output/algebra/adapters.js +11 -0
  12. package/output/algebra/algorithms/arith.d.ts +84 -0
  13. package/output/algebra/algorithms/arith.js +324 -0
  14. package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
  15. package/output/algebra/algorithms/groebnerBase.js +929 -0
  16. package/output/algebra/dispatch.d.ts +1 -0
  17. package/output/algebra/dispatch.js +25 -0
  18. package/output/algebra/factor/factor.d.ts +77 -0
  19. package/output/algebra/factor/factor.js +245 -0
  20. package/output/algebra/gcd/gcd.d.ts +30 -0
  21. package/output/algebra/gcd/gcd.js +95 -0
  22. package/output/algebra/groebner.d.ts +21 -0
  23. package/output/algebra/groebner.js +36 -0
  24. package/output/algebra/partfrac.d.ts +19 -0
  25. package/output/algebra/partfrac.js +365 -0
  26. package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
  27. package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
  28. package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
  29. package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
  30. package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
  31. package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
  32. package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
  33. package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
  34. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
  35. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
  36. package/output/algebra/polynomial/modularGcd.d.ts +40 -0
  37. package/output/algebra/polynomial/modularGcd.js +365 -0
  38. package/output/algebra/polynomialize.d.ts +20 -0
  39. package/output/algebra/polynomialize.js +26 -0
  40. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  41. package/output/algebra/simplify/complexsimp.js +24 -0
  42. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  43. package/output/algebra/simplify/factorCommon.js +136 -0
  44. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  45. package/output/algebra/simplify/funcsimp.js +633 -0
  46. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  47. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  48. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  49. package/output/algebra/simplify/ratsimp.js +140 -0
  50. package/output/algebra/simplify/simplify.d.ts +25 -0
  51. package/output/algebra/simplify/simplify.js +237 -0
  52. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  53. package/output/algebra/simplify/trigreduce.js +424 -0
  54. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  55. package/output/algebra/simplify/trigrewrite.js +156 -0
  56. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  57. package/output/algebra/simplify/trigsimp.js +369 -0
  58. package/output/algebra/simplify/utils.d.ts +32 -0
  59. package/output/algebra/simplify/utils.js +56 -0
  60. package/output/algebra/utils.d.ts +32 -0
  61. package/output/algebra/utils.js +48 -0
  62. package/output/api/advanced.d.ts +8 -0
  63. package/output/api/advanced.js +18 -0
  64. package/output/api/algebra.d.ts +17 -0
  65. package/output/api/algebra.js +35 -0
  66. package/output/api/assumptions.d.ts +4 -0
  67. package/output/api/assumptions.js +11 -0
  68. package/output/api/calculus.d.ts +10 -0
  69. package/output/api/calculus.js +22 -0
  70. package/output/api/core.d.ts +17 -0
  71. package/output/api/core.js +41 -0
  72. package/output/api/debug.d.ts +16 -0
  73. package/output/api/debug.js +23 -0
  74. package/output/api/languages/deu.d.ts +3 -0
  75. package/output/api/languages/deu.js +266 -0
  76. package/output/api/languages/fra.d.ts +3 -0
  77. package/output/api/languages/fra.js +266 -0
  78. package/output/api/languages/ita.d.ts +3 -0
  79. package/output/api/languages/ita.js +266 -0
  80. package/output/api/languages/nld.d.ts +3 -0
  81. package/output/api/languages/nld.js +266 -0
  82. package/output/api/languages/por.d.ts +3 -0
  83. package/output/api/languages/por.js +266 -0
  84. package/output/api/languages/spa.d.ts +3 -0
  85. package/output/api/languages/spa.js +266 -0
  86. package/output/api/parser.d.ts +93 -0
  87. package/output/api/parser.js +18 -0
  88. package/output/api/solve.d.ts +10 -0
  89. package/output/api/solve.js +17 -0
  90. package/output/api/structures.d.ts +10 -0
  91. package/output/api/structures.js +23 -0
  92. package/output/calculus/adapters.d.ts +8 -0
  93. package/output/calculus/adapters.js +41 -0
  94. package/output/calculus/derivative/diff.d.ts +30 -0
  95. package/output/calculus/derivative/diff.js +241 -0
  96. package/output/calculus/dispatch.d.ts +1 -0
  97. package/output/calculus/dispatch.js +25 -0
  98. package/output/calculus/fresnel.d.ts +16 -0
  99. package/output/calculus/fresnel.js +39 -0
  100. package/output/calculus/integrate/byParts.d.ts +18 -0
  101. package/output/calculus/integrate/byParts.js +339 -0
  102. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  103. package/output/calculus/integrate/bySubstitution.js +411 -0
  104. package/output/calculus/integrate/integrate.d.ts +38 -0
  105. package/output/calculus/integrate/integrate.js +652 -0
  106. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  107. package/output/calculus/integrate/integrationTable.js +914 -0
  108. package/output/calculus/integrate/utils.d.ts +28 -0
  109. package/output/calculus/integrate/utils.js +96 -0
  110. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  111. package/output/calculus/laplace/ilaplace.js +192 -0
  112. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  113. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  114. package/output/calculus/laplace/laplace.d.ts +22 -0
  115. package/output/calculus/laplace/laplace.js +109 -0
  116. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  117. package/output/calculus/laplace/laplaceTable.js +187 -0
  118. package/output/calculus/limit/limit.d.ts +35 -0
  119. package/output/calculus/limit/limit.js +1183 -0
  120. package/output/calculus/limit/limitsTable.d.ts +2 -0
  121. package/output/calculus/limit/limitsTable.js +7 -0
  122. package/output/core/Settings.d.ts +32 -0
  123. package/output/core/Settings.js +68 -0
  124. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  125. package/output/core/classes/assumption/Assumption.js +609 -0
  126. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  127. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  128. package/output/core/classes/assumption/assume.d.ts +90 -0
  129. package/output/core/classes/assumption/assume.js +145 -0
  130. package/output/core/classes/assumption/dispatch.d.ts +1 -0
  131. package/output/core/classes/assumption/dispatch.js +11 -0
  132. package/output/core/classes/collection/Collection.d.ts +107 -0
  133. package/output/core/classes/collection/Collection.js +240 -0
  134. package/output/core/classes/complex/Complex.d.ts +109 -0
  135. package/output/core/classes/complex/Complex.js +153 -0
  136. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  137. package/output/core/classes/decimalSet/DecimalSet.js +454 -0
  138. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  139. package/output/core/classes/dictionary/Dictionary.js +216 -0
  140. package/output/core/classes/equation/Equation.d.ts +256 -0
  141. package/output/core/classes/equation/Equation.js +350 -0
  142. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  143. package/output/core/classes/expression/CoeffObject.js +197 -0
  144. package/output/core/classes/expression/Expression.d.ts +1691 -0
  145. package/output/core/classes/expression/Expression.js +2381 -0
  146. package/output/core/classes/expression/analysis.d.ts +25 -0
  147. package/output/core/classes/expression/analysis.js +218 -0
  148. package/output/core/classes/expression/collect.d.ts +9 -0
  149. package/output/core/classes/expression/collect.js +49 -0
  150. package/output/core/classes/expression/format.d.ts +54 -0
  151. package/output/core/classes/expression/format.js +340 -0
  152. package/output/core/classes/expression/products.d.ts +23 -0
  153. package/output/core/classes/expression/products.js +115 -0
  154. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  155. package/output/core/classes/expression/shortcuts.js +129 -0
  156. package/output/core/classes/expression/traversal.d.ts +31 -0
  157. package/output/core/classes/expression/traversal.js +216 -0
  158. package/output/core/classes/expression/trig.d.ts +25 -0
  159. package/output/core/classes/expression/trig.js +40 -0
  160. package/output/core/classes/expression/utils.d.ts +61 -0
  161. package/output/core/classes/expression/utils.js +235 -0
  162. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  163. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  164. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  165. package/output/core/classes/matrix/Matrix.js +901 -0
  166. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  167. package/output/core/classes/matrix/Sylvester.js +54 -0
  168. package/output/core/classes/matrix/dispatch.d.ts +1 -0
  169. package/output/core/classes/matrix/dispatch.js +19 -0
  170. package/output/core/classes/matrix/functions.d.ts +28 -0
  171. package/output/core/classes/matrix/functions.js +57 -0
  172. package/output/core/classes/matrix/utils.d.ts +9 -0
  173. package/output/core/classes/matrix/utils.js +22 -0
  174. package/output/core/classes/parser/Parser.d.ts +493 -0
  175. package/output/core/classes/parser/Parser.js +1863 -0
  176. package/output/core/classes/parser/Token.d.ts +58 -0
  177. package/output/core/classes/parser/Token.js +137 -0
  178. package/output/core/classes/parser/constants.d.ts +162 -0
  179. package/output/core/classes/parser/constants.js +229 -0
  180. package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
  181. package/output/core/classes/parser/controlFlowSignals.js +60 -0
  182. package/output/core/classes/parser/helpers.d.ts +21 -0
  183. package/output/core/classes/parser/helpers.js +42 -0
  184. package/output/core/classes/parser/operations/add.d.ts +15 -0
  185. package/output/core/classes/parser/operations/add.js +236 -0
  186. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  187. package/output/core/classes/parser/operations/comma.js +11 -0
  188. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  189. package/output/core/classes/parser/operations/compare.js +474 -0
  190. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  191. package/output/core/classes/parser/operations/divide.js +72 -0
  192. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  193. package/output/core/classes/parser/operations/functions.js +438 -0
  194. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  195. package/output/core/classes/parser/operations/multiply.js +328 -0
  196. package/output/core/classes/parser/operations/power.d.ts +48 -0
  197. package/output/core/classes/parser/operations/power.js +673 -0
  198. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  199. package/output/core/classes/parser/operations/subtract.js +36 -0
  200. package/output/core/classes/parser/preprocess.d.ts +7 -0
  201. package/output/core/classes/parser/preprocess.js +246 -0
  202. package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
  203. package/output/core/classes/parser/scripting/controlFlow.js +279 -0
  204. package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
  205. package/output/core/classes/parser/scripting/deferred.js +65 -0
  206. package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
  207. package/output/core/classes/parser/scripting/dispatch.js +62 -0
  208. package/output/core/classes/parser/scripting/evaluate.d.ts +23 -0
  209. package/output/core/classes/parser/scripting/evaluate.js +128 -0
  210. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  211. package/output/core/classes/parser/scripting/functions.js +59 -0
  212. package/output/core/classes/parser/scripting/scope.d.ts +8 -0
  213. package/output/core/classes/parser/scripting/scope.js +132 -0
  214. package/output/core/classes/parser/types.d.ts +130 -0
  215. package/output/core/classes/parser/types.js +2 -0
  216. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  217. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  218. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  219. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  220. package/output/core/classes/polynomial/Polynomial.d.ts +504 -0
  221. package/output/core/classes/polynomial/Polynomial.js +1195 -0
  222. package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
  223. package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
  224. package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
  225. package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
  226. package/output/core/classes/polynomial/Term.d.ts +222 -0
  227. package/output/core/classes/polynomial/Term.js +430 -0
  228. package/output/core/classes/polynomial/adapters.d.ts +18 -0
  229. package/output/core/classes/polynomial/adapters.js +33 -0
  230. package/output/core/classes/polynomial/dispatch.d.ts +1 -0
  231. package/output/core/classes/polynomial/dispatch.js +14 -0
  232. package/output/core/classes/polynomial/functions.d.ts +77 -0
  233. package/output/core/classes/polynomial/functions.js +189 -0
  234. package/output/core/classes/polynomial/utils.d.ts +62 -0
  235. package/output/core/classes/polynomial/utils.js +207 -0
  236. package/output/core/classes/rational/Rational.d.ts +501 -0
  237. package/output/core/classes/rational/Rational.js +829 -0
  238. package/output/core/classes/seq/SEQ.d.ts +13 -0
  239. package/output/core/classes/seq/SEQ.js +137 -0
  240. package/output/core/classes/valuesSet/ValuesSet.d.ts +187 -0
  241. package/output/core/classes/valuesSet/ValuesSet.js +399 -0
  242. package/output/core/classes/vector/Vector.d.ts +222 -0
  243. package/output/core/classes/vector/Vector.js +501 -0
  244. package/output/core/classes/vector/dispatch.d.ts +1 -0
  245. package/output/core/classes/vector/dispatch.js +11 -0
  246. package/output/core/classes/vector/functions.d.ts +28 -0
  247. package/output/core/classes/vector/functions.js +47 -0
  248. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  249. package/output/core/common/classes/MathematicalAggregate.js +149 -0
  250. package/output/core/common/classes/Scope.d.ts +62 -0
  251. package/output/core/common/classes/Scope.js +122 -0
  252. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  253. package/output/core/common/classes/StructuredEntity.js +151 -0
  254. package/output/core/common/common.d.ts +62 -0
  255. package/output/core/common/common.js +74 -0
  256. package/output/core/common/functions/functions.d.ts +14 -0
  257. package/output/core/common/functions/functions.js +33 -0
  258. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  259. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  260. package/output/core/converters/BaseConverter.d.ts +97 -0
  261. package/output/core/converters/BaseConverter.js +405 -0
  262. package/output/core/converters/Converter.d.ts +111 -0
  263. package/output/core/converters/Converter.js +806 -0
  264. package/output/core/converters/Pattern.d.ts +71 -0
  265. package/output/core/converters/Pattern.js +302 -0
  266. package/output/core/dispatch.d.ts +52 -0
  267. package/output/core/dispatch.js +26 -0
  268. package/output/core/errors.d.ts +316 -0
  269. package/output/core/errors.js +349 -0
  270. package/output/core/fullFunctions.d.ts +7 -0
  271. package/output/core/fullFunctions.js +31 -0
  272. package/output/core/functions/bigint/bigint.d.ts +133 -0
  273. package/output/core/functions/bigint/bigint.js +444 -0
  274. package/output/core/functions/bigint/primeFactor.d.ts +51 -0
  275. package/output/core/functions/bigint/primeFactor.js +267 -0
  276. package/output/core/functions/bigint/primes.d.ts +1 -0
  277. package/output/core/functions/bigint/primes.js +11 -0
  278. package/output/core/functions/build/definitions.d.ts +12 -0
  279. package/output/core/functions/build/definitions.js +139 -0
  280. package/output/core/functions/build/index.d.ts +32 -0
  281. package/output/core/functions/build/index.js +136 -0
  282. package/output/core/functions/complex.d.ts +90 -0
  283. package/output/core/functions/complex.dispatch.d.ts +1 -0
  284. package/output/core/functions/complex.dispatch.js +16 -0
  285. package/output/core/functions/complex.js +482 -0
  286. package/output/core/functions/decimal.d.ts +24 -0
  287. package/output/core/functions/decimal.js +665 -0
  288. package/output/core/functions/expand/expand.d.ts +42 -0
  289. package/output/core/functions/expand/expand.js +376 -0
  290. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  291. package/output/core/functions/fresnelNumeric.js +123 -0
  292. package/output/core/functions/numeric.d.ts +140 -0
  293. package/output/core/functions/numeric.js +790 -0
  294. package/output/core/functions/rationalNormalization.d.ts +11 -0
  295. package/output/core/functions/rationalNormalization.js +117 -0
  296. package/output/core/functions/setFunction.d.ts +19 -0
  297. package/output/core/functions/setFunction.js +75 -0
  298. package/output/core/functions/string.d.ts +26 -0
  299. package/output/core/functions/string.js +102 -0
  300. package/output/core/functions/subst.d.ts +90 -0
  301. package/output/core/functions/subst.js +506 -0
  302. package/output/core/functions/utils.d.ts +24 -0
  303. package/output/core/functions/utils.js +51 -0
  304. package/output/core/parserFunctions.d.ts +7 -0
  305. package/output/core/parserFunctions.js +25 -0
  306. package/output/core/types.d.ts +48 -0
  307. package/output/core/types.js +2 -0
  308. package/output/index.d.ts +359 -0
  309. package/output/index.js +739 -0
  310. package/output/math/defint/defint.d.ts +18 -0
  311. package/output/math/defint/defint.js +60 -0
  312. package/output/math/defint/defintDecimal.d.ts +37 -0
  313. package/output/math/defint/defintDecimal.js +321 -0
  314. package/output/math/defint/defintNative.d.ts +57 -0
  315. package/output/math/defint/defintNative.js +281 -0
  316. package/output/math/dispatch.d.ts +1 -0
  317. package/output/math/dispatch.js +101 -0
  318. package/output/math/geometry.d.ts +12 -0
  319. package/output/math/geometry.js +55 -0
  320. package/output/math/math.d.ts +695 -0
  321. package/output/math/math.js +1955 -0
  322. package/output/math/trig.d.ts +518 -0
  323. package/output/math/trig.js +1444 -0
  324. package/output/math/trunc.d.ts +19 -0
  325. package/output/math/trunc.js +36 -0
  326. package/output/math/utils.d.ts +66 -0
  327. package/output/math/utils.js +219 -0
  328. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  329. package/output/solve/classes/DecimalMatrix.js +86 -0
  330. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  331. package/output/solve/classes/FunctionSolver.js +433 -0
  332. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  333. package/output/solve/classes/MultivariateSolver.js +240 -0
  334. package/output/solve/classes/PolynomialSolver.d.ts +104 -0
  335. package/output/solve/classes/PolynomialSolver.js +492 -0
  336. package/output/solve/classes/SolutionSet.d.ts +172 -0
  337. package/output/solve/classes/SolutionSet.js +434 -0
  338. package/output/solve/classes/Solver.d.ts +17 -0
  339. package/output/solve/classes/Solver.js +132 -0
  340. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  341. package/output/solve/classes/SymbolicSolver.js +601 -0
  342. package/output/solve/dispatch.d.ts +1 -0
  343. package/output/solve/dispatch.js +13 -0
  344. package/output/solve/linsolve.d.ts +53 -0
  345. package/output/solve/linsolve.js +233 -0
  346. package/output/solve/solve.d.ts +44 -0
  347. package/output/solve/solve.js +368 -0
  348. package/output/solve/solveSystem.d.ts +31 -0
  349. package/output/solve/solveSystem.js +266 -0
  350. package/output/solve/utils.d.ts +10 -0
  351. package/output/solve/utils.js +58 -0
  352. package/output/utils/array.d.ts +42 -0
  353. package/output/utils/array.js +98 -0
  354. package/output/utils/debug.d.ts +131 -0
  355. package/output/utils/debug.js +296 -0
  356. package/output/utils/decimal.d.ts +3 -0
  357. package/output/utils/decimal.js +16 -0
  358. package/output/utils/numeric.d.ts +14 -0
  359. package/output/utils/numeric.js +51 -0
  360. package/output/utils/object.d.ts +26 -0
  361. package/output/utils/object.js +56 -0
  362. package/package.json +178 -57
  363. package/.travis.yml +0 -3
  364. package/Algebra.js +0 -4568
  365. package/CODE_OF_CONDUCT.md +0 -46
  366. package/CONTRIBUTING.md +0 -14
  367. package/Calculus.js +0 -2675
  368. package/Extra.js +0 -622
  369. package/Solve.js +0 -1783
  370. package/all.js +0 -16
  371. package/all.min.js +0 -1
  372. package/gulpfile.js +0 -16
  373. package/index.html +0 -158
  374. package/license.txt +0 -19
  375. package/nerdamer.core.js +0 -12510
  376. package/spec/LaTeX.spec.js +0 -302
  377. package/spec/TeXConvert.spec.js +0 -8
  378. package/spec/algebra.spec.js +0 -287
  379. package/spec/basic_parser.spec.js +0 -134
  380. package/spec/build.spec.js +0 -131
  381. package/spec/calculus.spec.js +0 -183
  382. package/spec/core.spec.js +0 -2970
  383. package/spec/extra.spec.js +0 -54
  384. package/spec/solve.spec.js +0 -126
  385. package/spec/support/jasmine.json +0 -11
  386. package/spec/support/utils.js +0 -42
  387. package/spec/text.spec.js +0 -132
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NonlinearSystemError = void 0;
4
+ exports.solveLinearSystem = solveLinearSystem;
5
+ const collect_1 = require("../core/classes/expression/collect");
6
+ const Expression_1 = require("../core/classes/expression/Expression");
7
+ const shortcuts_1 = require("../core/classes/expression/shortcuts");
8
+ const Matrix_1 = require("../core/classes/matrix/Matrix");
9
+ const Vector_1 = require("../core/classes/vector/Vector");
10
+ const errors_1 = require("../core/errors");
11
+ class NonlinearSystemError extends Error {
12
+ }
13
+ exports.NonlinearSystemError = NonlinearSystemError;
14
+ /**
15
+ * Solves a system of linear equations by symbolic reduced row-echelon form.
16
+ *
17
+ * Each element of `equations` is an Expression representing `expr = 0`.
18
+ * If `variables` is omitted, the union of all variables across equations is used
19
+ * (sorted alphabetically for deterministic column ordering).
20
+ *
21
+ * Input Expressions and strings are interpreted as equal to zero. Coefficients
22
+ * may be symbolic as long as they do not contain any of the solve variables.
23
+ * For an underdetermined consistent system, free variables map to their own
24
+ * Expression and pivot variables are expressed in terms of them.
25
+ *
26
+ * @param equations - Vector of Expressions, or an array of Expressions and strings.
27
+ * @param variables - Optional ordered list of variable names.
28
+ * @returns A {@link LinearSystemResult} describing a unique, infinite, or
29
+ * inconsistent system.
30
+ * @throws {@link Error} If a solve variable occurs nonlinearly or in a
31
+ * non-polynomial position.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // x + y - 3 = 0, 2x + 3y - 8 = 0
36
+ * const result = solveLinearSystem(
37
+ * [Expression.create('x+y-3'), Expression.create('2*x+3*y-8')]
38
+ * );
39
+ * // result.type === 'unique'
40
+ * // result.solutions === { x: Expression(1), y: Expression(2) }
41
+ * ```
42
+ */
43
+ function solveLinearSystem(equations, variables) {
44
+ // Normalize input
45
+ const exprs = normalizeEquations(equations);
46
+ if (exprs.length === 0) {
47
+ return { type: 'unique', solutions: {} };
48
+ }
49
+ // Determine variables
50
+ const vars = variables ?? (0, collect_1.collectVariablesSet)(exprs);
51
+ if (vars.length === 0) {
52
+ // No variables — check if all equations are trivially 0
53
+ for (const expr of exprs) {
54
+ if (!expr.eq((0, shortcuts_1.zero)())) {
55
+ return { type: 'inconsistent' };
56
+ }
57
+ }
58
+ return { type: 'unique', solutions: {} };
59
+ }
60
+ // Extract coefficients and build augmented matrix
61
+ const { coeffMatrix, constants } = extractCoefficients(exprs, vars);
62
+ // Build augmented matrix [A | -b] where each equation is a_1*x_1 + ... + a_n*x_n + c = 0
63
+ // so the augmented column is -c
64
+ const numRows = exprs.length;
65
+ const numCols = vars.length;
66
+ const augRows = [];
67
+ for (let i = 0; i < numRows; i++) {
68
+ const row = [];
69
+ for (let j = 0; j < numCols; j++) {
70
+ row.push(coeffMatrix[i][j]);
71
+ }
72
+ // Augmented column: negate the constant
73
+ row.push((0, shortcuts_1.zero)().minus(constants[i]));
74
+ augRows.push(row);
75
+ }
76
+ const augmented = new Matrix_1.Matrix(...augRows);
77
+ // RREF
78
+ const R = augmented.rref();
79
+ const rRows = R.rows();
80
+ // const rCols = R.cols(); // = numCols + 1
81
+ const z = (0, shortcuts_1.zero)();
82
+ // Identify pivots and check consistency
83
+ const pivotCol = []; // pivotCol[i] = column of pivot in row i, or -1
84
+ for (let i = 0; i < rRows; i++) {
85
+ let found = -1;
86
+ for (let j = 0; j < numCols; j++) {
87
+ if (!R.get(i, j).eq(z)) {
88
+ found = j;
89
+ break;
90
+ }
91
+ }
92
+ if (found === -1) {
93
+ // All variable columns are zero — check augmented column
94
+ const rhs = R.get(i, numCols);
95
+ if (!rhs.eq(z)) {
96
+ return { type: 'inconsistent' };
97
+ }
98
+ // Otherwise it's a trivial 0 = 0 row
99
+ pivotCol.push(-1);
100
+ }
101
+ else {
102
+ pivotCol.push(found);
103
+ }
104
+ }
105
+ // Identify pivot vs free variable columns
106
+ const pivotColSet = new Set();
107
+ for (const pc of pivotCol) {
108
+ if (pc !== -1) {
109
+ pivotColSet.add(pc);
110
+ }
111
+ }
112
+ const freeColIndices = [];
113
+ for (let j = 0; j < numCols; j++) {
114
+ if (!pivotColSet.has(j)) {
115
+ freeColIndices.push(j);
116
+ }
117
+ }
118
+ // Unique solution
119
+ if (freeColIndices.length === 0) {
120
+ const solutions = {};
121
+ for (let i = 0; i < rRows; i++) {
122
+ const pc = pivotCol[i];
123
+ if (pc !== -1) {
124
+ solutions[vars[pc]] = R.get(i, numCols);
125
+ }
126
+ }
127
+ return { type: 'unique', solutions };
128
+ }
129
+ // Infinite solutions
130
+ // Free variables are parameters; pivot variables are expressed in terms of them.
131
+ const freeVariables = freeColIndices.map(j => vars[j]);
132
+ const solutions = {};
133
+ // Free variables map to themselves
134
+ for (const freeVar of freeVariables) {
135
+ solutions[freeVar] = Expression_1.Expression.create(freeVar);
136
+ }
137
+ // Pivot variables: x_pivot = rhs - sum(coeff * freeVar)
138
+ for (let i = 0; i < rRows; i++) {
139
+ const pc = pivotCol[i];
140
+ if (pc === -1) {
141
+ continue;
142
+ }
143
+ let expr = R.get(i, numCols);
144
+ for (const fj of freeColIndices) {
145
+ const coeff = R.get(i, fj);
146
+ if (!coeff.eq(z)) {
147
+ // x_pivot = rhs - coeff * freeVar
148
+ expr = expr.minus(coeff.times(Expression_1.Expression.create(vars[fj])));
149
+ }
150
+ }
151
+ solutions[vars[pc]] = expr;
152
+ }
153
+ return { type: 'infinite', solutions, freeVariables };
154
+ }
155
+ // ═══════════════════════════════════════════════════════════════════════════
156
+ // Helpers
157
+ // ═══════════════════════════════════════════════════════════════════════════
158
+ /**
159
+ * Normalizes input to an array of Expressions.
160
+ */
161
+ function normalizeEquations(equations) {
162
+ if (Vector_1.Vector.isVector(equations)) {
163
+ const result = [];
164
+ for (let i = 0; i < equations.count(); i++) {
165
+ result.push(equations.getExpressionAt(i));
166
+ }
167
+ return result;
168
+ }
169
+ return equations.map(e => (Expression_1.Expression.isExpression(e) ? e : Expression_1.Expression.create(e)));
170
+ }
171
+ /**
172
+ * Extracts the coefficient matrix and constant vector from linear expressions.
173
+ *
174
+ * For each expression, uses `expr.coeffs(...vars)` to get a CoeffObject.
175
+ * The CoeffObject keys are comma-separated multi-degree tuples like "1,0" for x in [x, y].
176
+ * The constant term has the all-zeros key (e.g. "0,0").
177
+ *
178
+ * Throws if any term has degree > 1 in any variable (nonlinear).
179
+ */
180
+ function extractCoefficients(exprs, vars) {
181
+ const n = vars.length;
182
+ const coeffMatrix = [];
183
+ const constants = [];
184
+ for (let i = 0; i < exprs.length; i++) {
185
+ const expr = exprs[i];
186
+ const coeffObj = expr.coeffs(...vars);
187
+ const row = new Array(n).fill(null).map(() => (0, shortcuts_1.zero)());
188
+ let constant = (0, shortcuts_1.zero)();
189
+ // CoeffObject stores coefficients in .coeffs keyed by comma-separated degree tuples.
190
+ // e.g. for vars [x, y]: "1,0" means x^1*y^0 (coefficient of x),
191
+ // "0,0" is the constant term, "0,1" is coefficient of y, etc.
192
+ // Use .each() to iterate over all entries.
193
+ coeffObj.each((coeff, key) => {
194
+ const degrees = key.split(',').map(Number);
195
+ // Check total degree
196
+ const totalDegree = degrees.reduce((sum, d) => sum + d, 0);
197
+ if (totalDegree === 0) {
198
+ // Constant term
199
+ constant = coeff;
200
+ }
201
+ else if (totalDegree === 1) {
202
+ // Linear term — find which variable
203
+ const varIndex = degrees.findIndex(d => d === 1);
204
+ if (varIndex !== -1) {
205
+ row[varIndex] = coeff;
206
+ }
207
+ }
208
+ else {
209
+ // Nonlinear term
210
+ throw new NonlinearSystemError((0, errors_1.message)('solveLinearNonlinearDegree', {
211
+ equation: String(i + 1),
212
+ degree: String(totalDegree),
213
+ }));
214
+ }
215
+ });
216
+ // Validate that no coefficient contains solve variables in non-polynomial positions
217
+ // (e.g. sin(x) would be absorbed as a "constant" but still contains x)
218
+ const allCoeffs = [...row, constant];
219
+ for (const c of allCoeffs) {
220
+ for (const v of vars) {
221
+ if (c.hasVariable(v)) {
222
+ throw new NonlinearSystemError((0, errors_1.message)('solveLinearNonPolynomialVariable', {
223
+ equation: String(i + 1),
224
+ variable: v,
225
+ }));
226
+ }
227
+ }
228
+ }
229
+ coeffMatrix.push(row);
230
+ constants.push(constant);
231
+ }
232
+ return { coeffMatrix, constants };
233
+ }
@@ -0,0 +1,44 @@
1
+ import { Vector } from '../core/classes/vector/Vector';
2
+ import { type FunctionSolverOptions } from './classes/FunctionSolver';
3
+ import { SolutionSet } from './classes/SolutionSet';
4
+ import type { Equation } from '../core/classes/equation/Equation';
5
+ import type { ExpressionInput } from '../core/types';
6
+ /**
7
+ * Returns polynomial roots as a Vector.
8
+ *
9
+ * Unlike solve(), which returns a SolutionSet with solver metadata, this function preserves
10
+ * the roots API's Vector return type. Numeric constants retain the historical square-root
11
+ * interpretation. Univariate polynomials delegate to PolynomialSolver and therefore return
12
+ * numerical roots.
13
+ */
14
+ export declare function roots(input: ExpressionInput, variable?: ExpressionInput): Vector;
15
+ /**
16
+ * Solves an equation or finds the zeros of an expression in one variable.
17
+ *
18
+ * The solver normalizes the input to `expression = 0`, tries direct symbolic
19
+ * transformations, factors numerator and denominator, and then applies
20
+ * symbolic, polynomial-numeric, and limited-range function-numeric strategies to the
21
+ * factors. Zeros of denominator factors are excluded from the result.
22
+ *
23
+ * @remarks
24
+ * Numerical fallback is heuristic and searches a finite range, so an empty result does
25
+ * not in general prove that no solution exists. Strategy and input errors are absorbed
26
+ * by this convenience entry point and produce the solutions collected before
27
+ * the failure. Decimal input marks returned solutions for decimal formatting.
28
+ *
29
+ * The `options` parameter is currently reserved and is not forwarded to the
30
+ * numerical strategies.
31
+ *
32
+ * @param input - Expression or equation to solve.
33
+ * @param variable - Variable to solve for. When omitted, input preparation
34
+ * infers it where possible.
35
+ * @param _options - Reserved numerical-solver options.
36
+ * @returns A {@link SolutionSet}. The special `all` expression represents an
37
+ * identity that is true for every value of the variable.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const roots = solve('x^2-1', 'x');
42
+ * ```
43
+ */
44
+ export declare function solve(input: ExpressionInput | Equation, variable?: ExpressionInput, _options?: FunctionSolverOptions): SolutionSet;
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.roots = roots;
4
+ exports.solve = solve;
5
+ const factor_1 = require("../algebra/factor/factor");
6
+ const factorCommon_1 = require("../algebra/simplify/factorCommon");
7
+ const ratsimp_1 = require("../algebra/simplify/ratsimp");
8
+ const Expression_1 = require("../core/classes/expression/Expression");
9
+ const shortcuts_1 = require("../core/classes/expression/shortcuts");
10
+ const utils_1 = require("../core/classes/expression/utils");
11
+ const constants_1 = require("../core/classes/parser/constants");
12
+ const Vector_1 = require("../core/classes/vector/Vector");
13
+ const trig_1 = require("../math/trig");
14
+ const FunctionSolver_1 = require("./classes/FunctionSolver");
15
+ const PolynomialSolver_1 = require("./classes/PolynomialSolver");
16
+ const SolutionSet_1 = require("./classes/SolutionSet");
17
+ const SymbolicSolver_1 = require("./classes/SymbolicSolver");
18
+ const utils_2 = require("./utils");
19
+ /**
20
+ * Accumulates roots from distinct exact polynomial factors.
21
+ *
22
+ * Each factor result has already enforced uniqueness within that factor. Exact univariate
23
+ * factorization proves separate factors coprime, so their accepted roots can be copied
24
+ * without repeating general symbolic equality checks across factors.
25
+ */
26
+ class FactorRootAccumulator extends SolutionSet_1.SolutionSet {
27
+ appendFactorSolutions(solutions) {
28
+ for (const solution of solutions.elements) {
29
+ this.addKnownUnique(solution);
30
+ }
31
+ if (this.solutionsType === undefined) {
32
+ this.solutionsType = solutions.solutionsType;
33
+ }
34
+ else if (solutions.solutionsType !== undefined &&
35
+ this.solutionsType !== solutions.solutionsType) {
36
+ this.solutionsType = 'mixed';
37
+ }
38
+ }
39
+ }
40
+ function calculateSolutions(factors, variable, disjointPolynomialFactors = false) {
41
+ const solutionSet = disjointPolynomialFactors
42
+ ? new FactorRootAccumulator()
43
+ : new SolutionSet_1.SolutionSet();
44
+ // We loop through each element (factor) and try to solve it. If we were successful,
45
+ // then we return 0. If we fail then we return the value
46
+ const firstPass = factors
47
+ .map(fn => {
48
+ let retval = fn;
49
+ // The exponential function has no zeros, so an e^u factor contributes no
50
+ // solutions and must not be sent through the numerical scan over a fixed interval.
51
+ if (fn.isEXP() && fn.getBase().isE()) {
52
+ retval = (0, shortcuts_1.zero)();
53
+ }
54
+ // Don't even try to solve the function if it does not have x
55
+ else if (fn.hasVariable(variable)) {
56
+ // First Symbolically
57
+ let solutions = new SymbolicSolver_1.SymbolicSolver(fn, variable).solve();
58
+ if (solutions.unsolved && fn.isPolynomialLike() && fn.getPower().gt(4)) {
59
+ const linearPoly = fn.toLinearAndUnitMultiplier();
60
+ // See if you can solve the linear polynomial
61
+ solutions = new SymbolicSolver_1.SymbolicSolver(linearPoly, variable).solve();
62
+ }
63
+ if (!solutions.unsolved) {
64
+ if (disjointPolynomialFactors) {
65
+ const factorSolutions = new SolutionSet_1.SolutionSet();
66
+ factorSolutions.addSolutions(solutions.solutions, fn, variable);
67
+ if (factorSolutions.count() > 0) {
68
+ factorSolutions.solutionsType = 'symbolic';
69
+ solutionSet.appendFactorSolutions(factorSolutions);
70
+ }
71
+ }
72
+ else {
73
+ const symbolicSolutions = new SolutionSet_1.SolutionSet(solutions.solutions);
74
+ symbolicSolutions.solutionsType = 'symbolic';
75
+ solutionSet.addSolutions(symbolicSolutions, fn, variable);
76
+ }
77
+ retval = (0, shortcuts_1.zero)();
78
+ }
79
+ }
80
+ return retval;
81
+ })
82
+ .filter(fn => !fn.eq((0, shortcuts_1.zero)()));
83
+ // For the second pass we solve polynomials using polynomials using numerical methods.
84
+ const secondPass = firstPass
85
+ .map(fn => {
86
+ let retval = fn;
87
+ // Numerical methods are only capable of solving univariate polynomials so
88
+ // we need to check as not to waste time.
89
+ const vars = fn.variables();
90
+ if (vars.length === 1 && vars[0] === variable && fn.isPolynomialLike()) {
91
+ const solutions = new PolynomialSolver_1.PolynomialSolver(fn, variable).validatedRoots();
92
+ if (solutions.length > 0) {
93
+ if (disjointPolynomialFactors) {
94
+ const factorSolutions = new SolutionSet_1.SolutionSet();
95
+ factorSolutions.addValidatedNumericalSolutions(solutions);
96
+ factorSolutions.solutionsType = 'numeric';
97
+ solutionSet.appendFactorSolutions(factorSolutions);
98
+ }
99
+ else {
100
+ solutionSet.addValidatedNumericalSolutions(solutions);
101
+ solutionSet.solutionsType =
102
+ solutionSet.solutionsType === undefined ||
103
+ solutionSet.solutionsType === 'numeric'
104
+ ? 'numeric'
105
+ : 'mixed';
106
+ }
107
+ }
108
+ retval = (0, shortcuts_1.zero)();
109
+ }
110
+ return retval;
111
+ })
112
+ .filter(fn => !fn.eq((0, shortcuts_1.zero)()));
113
+ // We ultimately fall back to numerical methods
114
+ for (const fn of secondPass) {
115
+ // Numerical methods are only capable of solving univariate functions so
116
+ // we need to check as not to waste time.
117
+ const vars = fn.variables();
118
+ const options = { method: 'Brent' };
119
+ if (vars.length === 1 && vars[0] === variable) {
120
+ const solutions = new FunctionSolver_1.FunctionSolver(fn, variable, options).roots();
121
+ if (solutions.length > 0) {
122
+ for (const solution of solutions) {
123
+ solutionSet.add(solution);
124
+ }
125
+ solutionSet.solutionsType =
126
+ solutionSet.solutionsType === undefined ||
127
+ solutionSet.solutionsType === 'numeric'
128
+ ? 'numeric'
129
+ : 'mixed';
130
+ }
131
+ }
132
+ }
133
+ return solutionSet;
134
+ }
135
+ /**
136
+ * Returns polynomial roots as a Vector.
137
+ *
138
+ * Unlike solve(), which returns a SolutionSet with solver metadata, this function preserves
139
+ * the roots API's Vector return type. Numeric constants retain the historical square-root
140
+ * interpretation. Univariate polynomials delegate to PolynomialSolver and therefore return
141
+ * numerical roots.
142
+ */
143
+ function roots(input, variable) {
144
+ const expression = Expression_1.Expression.create(input);
145
+ const variables = expression.variables();
146
+ if (variables.length === 0 && expression.isConstant()) {
147
+ const evaluated = expression.evaluate();
148
+ if (evaluated.isNUM()) {
149
+ const magnitude = evaluated.abs();
150
+ const root = magnitude.pow((0, shortcuts_1.half)());
151
+ const positive = evaluated.sign() < 0
152
+ ? root.times(Expression_1.Expression.Img())
153
+ : root;
154
+ return new Vector_1.Vector([positive, positive.neg()]);
155
+ }
156
+ }
157
+ const variableName = variable === undefined
158
+ ? variables[0]
159
+ : (0, utils_1.assertPlainVariableAndGetString)(Expression_1.Expression.create(variable));
160
+ if (variableName === undefined) {
161
+ return new Vector_1.Vector([expression]);
162
+ }
163
+ return new Vector_1.Vector(new PolynomialSolver_1.PolynomialSolver(expression, variableName).validatedRoots());
164
+ }
165
+ /**
166
+ * Solves an equation or finds the zeros of an expression in one variable.
167
+ *
168
+ * The solver normalizes the input to `expression = 0`, tries direct symbolic
169
+ * transformations, factors numerator and denominator, and then applies
170
+ * symbolic, polynomial-numeric, and limited-range function-numeric strategies to the
171
+ * factors. Zeros of denominator factors are excluded from the result.
172
+ *
173
+ * @remarks
174
+ * Numerical fallback is heuristic and searches a finite range, so an empty result does
175
+ * not in general prove that no solution exists. Strategy and input errors are absorbed
176
+ * by this convenience entry point and produce the solutions collected before
177
+ * the failure. Decimal input marks returned solutions for decimal formatting.
178
+ *
179
+ * The `options` parameter is currently reserved and is not forwarded to the
180
+ * numerical strategies.
181
+ *
182
+ * @param input - Expression or equation to solve.
183
+ * @param variable - Variable to solve for. When omitted, input preparation
184
+ * infers it where possible.
185
+ * @param _options - Reserved numerical-solver options.
186
+ * @returns A {@link SolutionSet}. The special `all` expression represents an
187
+ * identity that is true for every value of the variable.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * const roots = solve('x^2-1', 'x');
192
+ * ```
193
+ */
194
+ function solve(input, variable, _options) {
195
+ // The solution set that's being returned
196
+ const solutions = new SolutionSet_1.SolutionSet();
197
+ let asDecimal = false;
198
+ // Try to solve the equation.
199
+ try {
200
+ // Prepare the inputs
201
+ const { expression, x } = (0, utils_2.prepareSolverInputs)(input, variable);
202
+ asDecimal = expression.hasDecimal();
203
+ // Get the variables
204
+ const vars = expression.variables();
205
+ // Handle the zero polynomial. This has as return type the special value all
206
+ if (expression.isZero()) {
207
+ solutions.addSolution((0, shortcuts_1.all)(), expression, x);
208
+ solutions.solutionsType = 'symbolic';
209
+ }
210
+ // For monomials a*x^n the value is zero for all values of x
211
+ else if (expression.isVAR() || (!vars.includes(x) && !expression.isNUM())) {
212
+ // There's not need to check if the variable matches x as this one done in prepareSolverInputs
213
+ solutions.addSolution((0, shortcuts_1.zero)(), expression, x);
214
+ solutions.solutionsType = 'symbolic';
215
+ }
216
+ else {
217
+ // The strategy is a follows:
218
+ // 1. Try the original expression symbolically before factoring. This avoids expensive
219
+ // factorization when the existing symbolic solver can already close the equation.
220
+ // 2. Factor the expression. Take the divide and conquer approach. Solve the smaller parts. The factors function
221
+ // helps by breaking both the numerator and the denominator into their factors.
222
+ // 3. We only need to solve the numerator. The denominator only gives us singularities.
223
+ // We return that as the extraneous roots.
224
+ // 4. Try to solve symbolically with the symbol solver.
225
+ // 5. Try to solve polynomials numerically as a fallback.
226
+ // 6. When all else fails, switch to a numerical solver.
227
+ const containsRadicalTerm = expression.isSum() &&
228
+ expression.elementsArray().some(term => {
229
+ let retval = term.hasVariable(x) && term.getPower().eq((0, shortcuts_1.half)());
230
+ if (!retval && term.isProduct() && term.hasVariable(x)) {
231
+ const variableFactors = term
232
+ .elementsArray()
233
+ .filter(factor => factor.hasVariable(x));
234
+ retval =
235
+ variableFactors.length === 1 &&
236
+ variableFactors[0].getPower().eq((0, shortcuts_1.half)().neg());
237
+ }
238
+ return retval;
239
+ });
240
+ const directCoeffs = expression.isPolynomialLike()
241
+ ? expression.coeffs(x).toArray()
242
+ : undefined;
243
+ const isNumericUnivariatePolynomial = directCoeffs !== undefined &&
244
+ vars.length === 1 &&
245
+ vars[0] === x &&
246
+ directCoeffs.every(coefficient => coefficient.isNUM());
247
+ let directPowerBinomialSolutions;
248
+ if (directCoeffs) {
249
+ const degree = directCoeffs.length - 1;
250
+ const hasSymbolicCoefficients = directCoeffs.some(coefficient => coefficient.variables().length > 0);
251
+ const isPowerBinomial = degree > 4 &&
252
+ hasSymbolicCoefficients &&
253
+ !directCoeffs[0].isZero() &&
254
+ directCoeffs.slice(1, degree).every(coefficient => coefficient.isZero());
255
+ if (isPowerBinomial) {
256
+ const degreeExpression = Expression_1.Expression.create(degree);
257
+ const rootPower = (0, shortcuts_1.one)().div(degreeExpression);
258
+ const radicand = directCoeffs[0].neg().div(directCoeffs[degree]);
259
+ const principalRoot = Expression_1.Expression.toEXP(radicand, rootPower);
260
+ const fullTurn = (0, shortcuts_1.two)().times(Expression_1.Expression.Variable(constants_1.PI_NAME));
261
+ directPowerBinomialSolutions = [];
262
+ for (let k = 0; k < degree; k++) {
263
+ let rotation = (0, shortcuts_1.one)();
264
+ if (k > 0) {
265
+ const angle = fullTurn
266
+ .copy()
267
+ .times(Expression_1.Expression.create(k))
268
+ .div(degreeExpression);
269
+ rotation = (0, trig_1.cos)(angle).plus((0, trig_1.sin)(angle).times(Expression_1.Expression.Img()));
270
+ }
271
+ directPowerBinomialSolutions.push(principalRoot.copy().times(rotation));
272
+ }
273
+ }
274
+ }
275
+ const commonFactored = directCoeffs?.length === 3 && directCoeffs[0].isZero()
276
+ ? (0, factorCommon_1.factorCommonPower)(expression)
277
+ : undefined;
278
+ const commonFactors = commonFactored?.isProduct()
279
+ ? commonFactored.elementsArray()
280
+ : undefined;
281
+ const direct = containsRadicalTerm
282
+ ? new SymbolicSolver_1.SymbolicSolver(expression, x).solve()
283
+ : undefined;
284
+ let rationalNumerator;
285
+ let rationalDenominator;
286
+ if (!expression.isPolynomialLike()) {
287
+ try {
288
+ const rational = (0, ratsimp_1.toCommonDenominator)(expression);
289
+ const numerator = rational.getNumerator().expand();
290
+ const denominator = rational.getDenominator().expand();
291
+ if (!denominator.isOne() &&
292
+ numerator.isPolynomialLike() &&
293
+ denominator.isPolynomialLike()) {
294
+ rationalNumerator = numerator;
295
+ rationalDenominator = denominator;
296
+ }
297
+ }
298
+ catch {
299
+ // This is an optimization path. If rational normalization is not supported,
300
+ // continue with the existing factorization and numerical strategies below.
301
+ }
302
+ }
303
+ if (directPowerBinomialSolutions) {
304
+ const symbolicSolutions = new SolutionSet_1.SolutionSet(directPowerBinomialSolutions);
305
+ symbolicSolutions.solutionsType = 'symbolic';
306
+ solutions.addSolutions(symbolicSolutions, expression, x);
307
+ }
308
+ else if (commonFactors) {
309
+ solutions.addSolution((0, shortcuts_1.zero)(), expression, x);
310
+ solutions.solutionsType = 'symbolic';
311
+ const commonSolutions = calculateSolutions(commonFactors, x);
312
+ if (isNumericUnivariatePolynomial &&
313
+ commonSolutions.solutionsType === 'numeric') {
314
+ solutions.appendValidatedNumerical(commonSolutions);
315
+ }
316
+ else if (isNumericUnivariatePolynomial) {
317
+ solutions.append(commonSolutions);
318
+ }
319
+ else {
320
+ solutions.addSolutions(commonSolutions, expression, x);
321
+ }
322
+ }
323
+ else if (direct && !direct.unsolved) {
324
+ const symbolicSolutions = new SolutionSet_1.SolutionSet(direct.solutions);
325
+ symbolicSolutions.solutionsType = 'symbolic';
326
+ solutions.addSolutions(symbolicSolutions, expression, x);
327
+ }
328
+ else if (rationalNumerator && rationalDenominator) {
329
+ // A rational expression is zero exactly where its polynomial numerator is zero,
330
+ // except at denominator singularities. Avoid polynomializing the nested quotient again.
331
+ const extraneous = calculateSolutions([rationalDenominator], x);
332
+ solutions.exclude(extraneous);
333
+ solutions.addSolutions(calculateSolutions([rationalNumerator], x), expression, x);
334
+ }
335
+ else {
336
+ // Get the factors object
337
+ const factorObj = (0, factor_1.factorExpressionParts)(expression);
338
+ // Exact univariate factorization returns distinct irreducible factors with
339
+ // repeated factors represented by powers. Their solution sets can therefore
340
+ // be combined without proving cross-factor equality again.
341
+ const disjointPolynomialFactors = isNumericUnivariatePolynomial;
342
+ // Get the extraneous roots
343
+ const extraneous = calculateSolutions(factorObj.denominator, x, disjointPolynomialFactors);
344
+ solutions.exclude(extraneous);
345
+ // Get the solutions in the numerator
346
+ const numSolutions = calculateSolutions(factorObj.numerator, x, disjointPolynomialFactors);
347
+ if (isNumericUnivariatePolynomial &&
348
+ numSolutions.solutionsType === 'numeric') {
349
+ solutions.appendValidatedNumerical(numSolutions);
350
+ }
351
+ else if (isNumericUnivariatePolynomial) {
352
+ solutions.append(numSolutions);
353
+ }
354
+ else {
355
+ solutions.addSolutions(numSolutions, expression, x);
356
+ }
357
+ }
358
+ }
359
+ }
360
+ catch (_e) { }
361
+ if (asDecimal) {
362
+ solutions.each(solution => {
363
+ solution.getMultiplier().asDecimal = true;
364
+ return solution;
365
+ });
366
+ }
367
+ return solutions;
368
+ }
@@ -0,0 +1,31 @@
1
+ import { Vector } from '../core/classes/vector/Vector';
2
+ import type { Equation } from '../core/classes/equation/Equation';
3
+ import type { ExpressionInput } from '../core/types';
4
+ /**
5
+ * Solves a system of expressions or equations for an ordered set of variables.
6
+ *
7
+ * Expressions are interpreted as equal to zero. The solver first tries exact
8
+ * linear reduction, then a lexicographic Groebner basis with symbolic back
9
+ * substitution for polynomial systems, and finally multivariate Newton-Raphson
10
+ * over a fixed search interval. Rational polynomial systems may have denominators
11
+ * cleared for symbolic work; candidates are checked against the original domain.
12
+ *
13
+ * @remarks
14
+ * The nonlinear numerical fallback is heuristic and does not guarantee all
15
+ * roots. A returned outer {@link Vector} contains one {@link Dictionary} per
16
+ * solution. An empty system has one empty solution, while no discovered or
17
+ * inconsistent solution is represented by an empty Vector.
18
+ *
19
+ * Infinite nonlinear solution sets are not represented. Underdetermined
20
+ * systems that reach numerical fallback are rejected.
21
+ *
22
+ * @param equations - Vector or array of equations and zero-valued expressions.
23
+ * @param variables - Optional variable order. When omitted, variables are
24
+ * collected from the normalized expressions.
25
+ * @returns A Vector of solution dictionaries keyed by variable name.
26
+ * @throws {@link core!UnexpectedInputError} If an input cannot be normalized to an
27
+ * Expression or Equation.
28
+ * @throws {@link core!UnsupportedOperationError} If a solution is not isolated or an
29
+ * underdetermined nonlinear system reaches numerical fallback.
30
+ */
31
+ export declare function solveSystem(equations: Vector | Array<ExpressionInput | Equation | string>, variables?: string[]): Vector;