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,1691 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Rational } from '../rational/Rational';
3
+ import type { Base } from '../../common/common';
4
+ import type { ParserEntity, ExpressionInput, NerdamerInput } from '../../types';
5
+ import type { ParserValuesObject, TextOptions } from '../parser/types';
6
+ export type ElementsSortType = (a: Expression, b: Expression) => number;
7
+ /**
8
+ * Represents a symbolic expression in Nerdamer's canonical expression tree.
9
+ *
10
+ * @remarks
11
+ * `Expression` is the central symbolic value type used by the parser and by the
12
+ * algebra, calculus, and solver layers. Parsed expressions are normalized into a
13
+ * small set of internal node categories such as numbers, variables, functions,
14
+ * powers, products, and sums. Numeric coefficients are normally stored in a
15
+ * {@link Rational} multiplier rather than as separate product elements.
16
+ *
17
+ * Most arithmetic and transformation methods return a new `Expression`, but the
18
+ * class itself is mutable because parser and algorithm internals rebuild nodes in
19
+ * place. Accessors such as {@link Expression.getArguments},
20
+ * {@link Expression.getMultiplier}, and {@link Expression.getPower} may lazily
21
+ * initialize and return internal objects. Use {@link Expression.copy} when an
22
+ * independently mutable expression tree is required.
23
+ *
24
+ * {@link Expression.create} is the preferred construction API for ordinary
25
+ * expression construction and coercion. It centralizes supported input handling and
26
+ * normalization. When the input is already an `Expression`, it preserves object
27
+ * identity unless its `copy` argument is set to `true`.
28
+ *
29
+ * When the source is already known to be an `Expression` and an independent tree is
30
+ * required, use {@link Expression.copy}. When a caller accepts broader input but must
31
+ * guarantee a clone for an existing expression, use
32
+ * `Expression.create(input, undefined, true)`.
33
+ *
34
+ * Direct `new Expression(...)` construction is reserved for representation-level
35
+ * internals that require constructor semantics, such as the `plainConstruct` path and
36
+ * the implementation of {@link Expression.copy}. Ordinary callers should not use the
37
+ * constructor for coercion or cloning.
38
+ *
39
+ * The internal expression groups are organizational categories used by Nerdamer's
40
+ * canonicalization logic. They should not be confused with general mathematical
41
+ * classifications:
42
+ *
43
+ * - `NUM` stores plain numeric values.
44
+ * - `VAR` stores symbols/variables whose powers fit the variable representation.
45
+ * - `EXP` stores bases with powers that require a separate exponential node; it is
46
+ * not the same thing as an exponential function.
47
+ * - `FUN` stores function calls.
48
+ * - `GRP` stores sums with a common base but differing powers, such as
49
+ * `x + x^y` or `cos(x) - 3*cos(x)^2`.
50
+ * - `PRD` stores products of non-numeric symbolic factors; numeric coefficients are
51
+ * moved to the outer multiplier during parsing.
52
+ * - `SUM` stores other sums. For example, `1 + x + x^2` is a `SUM` containing a
53
+ * numeric term and a grouped polynomial-like component.
54
+ * - `INF` stores infinite values.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const expression = Expression.create('2*x + 1');
59
+ *
60
+ * expression.text(); // "1+2*x"
61
+ * expression.evaluate({ x: 3 }).text(); // "7"
62
+ * ```
63
+ */
64
+ export declare class Expression implements Base<Expression> {
65
+ /**
66
+ * Controls whether addition first distributes an outer multiplier on a sum.
67
+ *
68
+ * @remarks
69
+ * This is a process-wide parser/algebra setting used by the addition operation.
70
+ * Changing it affects subsequent symbolic operations globally.
71
+ */
72
+ static DISTRIBUTE_MULTIPLIER: boolean;
73
+ /**
74
+ * The symbol currently reserved for the imaginary unit.
75
+ *
76
+ * Use {@link Parser.setI} to change the symbol so the parser's restricted-name
77
+ * bookkeeping is updated at the same time.
78
+ */
79
+ static imaginary: string;
80
+ /** Names used by the internal logarithm representation and converters. */
81
+ static LOG: string;
82
+ static LOG10: string;
83
+ /**
84
+ * Placeholder key used when numeric terms are grouped inside expression containers.
85
+ *
86
+ * This is part of the internal canonical-key representation rather than the
87
+ * rendered mathematical value of a number.
88
+ */
89
+ static numberHash: string;
90
+ /** Power operator used by expression text formatting. */
91
+ static POW_OPR: string;
92
+ /**
93
+ * Symbols excluded from ordinary variable collection.
94
+ *
95
+ * @remarks
96
+ * This list differs from the parser's restricted-name list.
97
+ * It is used by expression traversal when deciding which `VAR` nodes should be
98
+ * reported as free variables. The distinction is historical and should not be
99
+ * interpreted as a general parser-reservation policy.
100
+ */
101
+ static RESERVED: string[];
102
+ /**
103
+ * Comparator used when expression elements are emitted in canonical display order.
104
+ *
105
+ * @remarks
106
+ * The ordering is representational, not a mathematical ordering relation. It keeps
107
+ * the imaginary unit last, orders like node types by value and descending power,
108
+ * and otherwise falls back to the internal expression-type order. Replacing this
109
+ * function changes ordering globally for subsequent formatting and reconstruction.
110
+ */
111
+ static sortFunction: ElementsSortType;
112
+ /** Internal expression-type constants used by parser and algebra code. */
113
+ static TYPES: {
114
+ NUM: number;
115
+ VAR: number;
116
+ EXP: number;
117
+ FUN: number;
118
+ GRP: number;
119
+ PRD: number;
120
+ SUM: number;
121
+ INF: number;
122
+ VEC: number;
123
+ MAT: number;
124
+ };
125
+ /**
126
+ * Arguments stored by a function node.
127
+ *
128
+ * Prefer {@link Expression.getArguments} when consuming this representation.
129
+ */
130
+ args?: Expression[];
131
+ /**
132
+ * Explicit mathematical base stored by an `EXP` node.
133
+ *
134
+ * Non-`EXP` nodes derive their base through {@link Expression.getBase} instead.
135
+ */
136
+ base?: Expression;
137
+ /** Parser entity discriminator for expression values. */
138
+ dataType: string;
139
+ /**
140
+ * Signals that the Expression was parsed with the deferred flag true
141
+ */
142
+ deferred: boolean;
143
+ /**
144
+ * Canonically keyed child expressions for aggregate nodes such as sums and products.
145
+ *
146
+ * @remarks
147
+ * The record is mutable representation state. {@link Expression.getElements}
148
+ * returns this object directly when it exists; callers that mutate it are
149
+ * responsible for preserving a valid expression representation and regenerating derived values.
150
+ */
151
+ elements?: Record<string, Expression>;
152
+ /**
153
+ * Cached ordinary lookup key for SUM and PRD nodes.
154
+ *
155
+ * Copies intentionally start without this cache. Aggregate reconstruction clears it
156
+ * through updateValue() before the node is used again.
157
+ */
158
+ private _keyValueCache?;
159
+ /**
160
+ * Let's the parser know not to treat it as a set of values
161
+ */
162
+ isEnumerable: boolean;
163
+ /**
164
+ * Outer rational coefficient carried by this node when explicitly initialized.
165
+ *
166
+ * Use {@link Expression.getMultiplier} to obtain the effective multiplier.
167
+ */
168
+ multiplier?: Rational;
169
+ /**
170
+ * The function name if any
171
+ */
172
+ name?: string;
173
+ /**
174
+ * Outer power carried by this node when explicitly initialized.
175
+ *
176
+ * Use {@link Expression.getPower} to obtain the effective power.
177
+ */
178
+ power?: Expression;
179
+ /**
180
+ * If set, this is the maximum known precision of any of the intermediate operations
181
+ */
182
+ precision?: number;
183
+ /** Significant digits requested by the legacy scientific-formatting helper. */
184
+ scientific?: number;
185
+ /**
186
+ * The default type is a number for the expression since the default value
187
+ * for an expression is "1". The assert flag is used because TypeScript
188
+ * currently doesn't recognized that it's also set in the copyOver method
189
+ */
190
+ type: number;
191
+ /**
192
+ * The value of the expression. This hash is used for comparing variable.
193
+ * This value is set in the constructor or the copyOver method
194
+ */
195
+ value: string;
196
+ /**
197
+ * Constructs or copies an expression value.
198
+ *
199
+ * @remarks
200
+ * Direct construction is primarily a representation-level API. When `x` is an
201
+ * existing `Expression`, the constructor deep-copies its expression tree. When
202
+ * `plainConstruct` is `true` and `x` is a string, that string is stored as the
203
+ * raw node value without parsing. Other inputs are delegated to
204
+ * {@link Expression.create}, and JavaScript constructor return semantics therefore
205
+ * allow that factory-created expression to become the result of `new Expression(...)`.
206
+ *
207
+ * Ordinary code should use {@link Expression.create} for construction/coercion and
208
+ * {@link Expression.copy} when an independent tree is required. Direct constructor
209
+ * calls are reserved for low-level representation code.
210
+ *
211
+ * @param x - The expression or Nerdamer input used to construct the value.
212
+ * @param plainConstruct - Store a string as a raw internal value instead of parsing it.
213
+ */
214
+ constructor(x: NerdamerInput, plainConstruct?: boolean);
215
+ /**
216
+ * Converts supported Nerdamer input into an `Expression`.
217
+ *
218
+ * @remarks
219
+ * Strings and primitive numeric inputs are parsed through {@link Parser}. An
220
+ * existing `Expression` is returned unchanged when no substitution `values` are
221
+ * supplied; pass `copy: true` to request an independent deep copy. A
222
+ * {@link Rational} is converted to a numeric expression while preserving its
223
+ * decimal-origin marker.
224
+ *
225
+ * An {@link Equation} is converted to its residual expression by moving the right
226
+ * side to the left on a copy of the equation. For example, `x = 2` becomes the
227
+ * expression `x - 2` in canonical form.
228
+ *
229
+ * @param x - The expression-compatible input to convert.
230
+ * @param values - Parser substitutions applied while parsing non-`Expression` input.
231
+ * @param copy - Copy an existing `Expression` instead of preserving its identity.
232
+ * @returns The parsed, converted, reused, or copied expression.
233
+ * @throws {@link core!UnexpectedDataType}
234
+ * Thrown when parsing produces another parser entity, such as a vector or matrix,
235
+ * where an `Expression` is required.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * const expression = Expression.create('x^2 + 1');
240
+ *
241
+ * Expression.create(expression) === expression; // true
242
+ * Expression.create(expression, undefined, true) === expression; // false
243
+ * Expression.create('a+b', { a: 2, b: 3 }).text(); // "5"
244
+ * ```
245
+ */
246
+ static create(x: NerdamerInput, values?: ParserValuesObject, copy?: boolean): Expression;
247
+ /**
248
+ * Creates Euler's constant as a symbolic or evaluated expression.
249
+ *
250
+ * @param asNumericValue - Force the evaluated representation even when parser
251
+ * evaluation mode is disabled.
252
+ * @returns Symbolic `e`, or its current numeric representation when evaluation is enabled.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * Expression.E().text(); // "e"
257
+ * Expression.E(true).text(); // numeric approximation
258
+ * ```
259
+ */
260
+ static E(asNumericValue?: boolean): Expression;
261
+ /**
262
+ * Converts a rational value into a numeric expression.
263
+ *
264
+ * The conversion preserves the rational's `asDecimal` provenance flag so later
265
+ * formatting and decimal-contagion logic can distinguish decimal-origin values.
266
+ *
267
+ * @param x - Rational value to convert.
268
+ * @returns A new numeric expression with an independent multiplier.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const rational = Rational.create('3/4');
273
+ * Expression.fromRational(rational).text(); // "3/4"
274
+ * ```
275
+ */
276
+ static fromRational(x: Rational): Expression;
277
+ /**
278
+ * Converts a structured entity carrying symbolic bracket access into the scalar
279
+ * Expression form used by ordinary algebra and function nodes.
280
+ *
281
+ * Structured entities without symbolic access are left unchanged by returning
282
+ * `undefined`; callers can then apply their normal conversion rules.
283
+ */
284
+ static fromSymbolicAccess(x: NerdamerInput): Expression | undefined;
285
+ /**
286
+ * Creates a symbolic function node with the given name.
287
+ *
288
+ * This creates a bare function symbol without arguments. To create a function
289
+ * with arguments, use {@link Expression.toFunction} instead.
290
+ *
291
+ * @param x - The function name.
292
+ * @returns A function-typed Expression.
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * Expression.Function('f').text() // "f"
297
+ * ```
298
+ */
299
+ static Function(x: string): Expression;
300
+ /**
301
+ * Generates a canonical string representation for an array of sub-expressions,
302
+ * joined by `+` (for SUM/GRP) or `*` (for PRD), with sums wrapped in parentheses
303
+ * when inside a product.
304
+ *
305
+ * @param arr - The array of sub-expressions.
306
+ * @param f - The string method to call on each element: `'idString'`, `'keyValue'`, or `'text'`.
307
+ * @param expressionType - The parent expression type (SUM, GRP, or PRD).
308
+ * @returns The joined string representation.
309
+ */
310
+ static getValue(arr: Expression[], f: 'idString' | 'keyValue' | 'text', expressionType: number): string;
311
+ /**
312
+ * Intercepts values passed through the `Expression` constructor.
313
+ *
314
+ * @remarks
315
+ * The default implementation is the identity function. Applications may replace
316
+ * this static hook, but doing so changes direct-construction behavior globally.
317
+ * {@link Expression.create} does not route every parsed input through this hook.
318
+ *
319
+ * @param x - Raw constructor input.
320
+ * @returns The value the constructor should continue processing.
321
+ */
322
+ static hook(x: NerdamerInput): NerdamerInput;
323
+ /**
324
+ * Creates the variable node representing the current imaginary-unit symbol.
325
+ *
326
+ * @returns A new variable expression using {@link Expression.imaginary}.
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * Expression.Img().text(); // "i" with the default parser configuration
331
+ * ```
332
+ *
333
+ * @see {@link Parser.setI}
334
+ */
335
+ static Img(): Expression;
336
+ /**
337
+ * Creates a symbolic positive infinity Expression.
338
+ *
339
+ * @returns An Expression representing `+∞`.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * Expression.Inf().text() // "Infinity"
344
+ * ```
345
+ */
346
+ static Inf(): Expression;
347
+ /**
348
+ * Type guard that checks whether an object is an Expression.
349
+ *
350
+ * @param obj - The value to test.
351
+ * @returns `true` if `obj` is an Expression instance.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * Expression.isExpression(Expression.create('x')) // true
356
+ * Expression.isExpression(42) // false
357
+ * ```
358
+ */
359
+ static isExpression(obj: unknown): obj is Expression;
360
+ /**
361
+ * Type guard that checks whether every element of an array is an Expression.
362
+ *
363
+ * @param obj - The value to test.
364
+ * @returns `true` if `obj` is an array and all elements are Expressions.
365
+ */
366
+ static isExpressionArray(obj: unknown): obj is Expression[];
367
+ /**
368
+ * Creates the internal summation/product index placeholder variable `_n`.
369
+ *
370
+ * @returns An Expression representing the variable `_n`.
371
+ */
372
+ static N(): Expression;
373
+ /**
374
+ * Creates a symbolic negative infinity Expression.
375
+ *
376
+ * @returns An Expression representing `−∞`.
377
+ *
378
+ * @example
379
+ * ```ts
380
+ * Expression.NegInf().text() // "-Infinity"
381
+ * ```
382
+ */
383
+ static NegInf(): Expression;
384
+ /**
385
+ * Creates a numeric (`NUM`) expression node from a numeric representation.
386
+ *
387
+ * @remarks
388
+ * This is a low-level constructor for numeric expression nodes. The supplied value
389
+ * is stored as text and is interpreted as a {@link Rational} when the multiplier is
390
+ * first requested. Use {@link Expression.create} when the input should be parsed as
391
+ * a general mathematical expression.
392
+ *
393
+ * @param x - Numeric representation to store.
394
+ * @returns A new numeric expression.
395
+ *
396
+ * @example
397
+ * ```ts
398
+ * Expression.Number('42').text(); // "42"
399
+ * Expression.Number('3/4').text(); // "3/4"
400
+ * ```
401
+ */
402
+ static Number(x: string | bigint | number | Decimal): Expression;
403
+ /**
404
+ * Creates π as a symbolic or evaluated expression.
405
+ *
406
+ * @param asNumericValue - Force the evaluated representation even when parser
407
+ * evaluation mode is disabled.
408
+ * @returns Symbolic `pi`, or its current numeric representation when evaluation is enabled.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * Expression.Pi().text(); // "pi"
413
+ * Expression.Pi(true).text(); // numeric approximation
414
+ * ```
415
+ */
416
+ static Pi(asNumericValue?: boolean): Expression;
417
+ /**
418
+ * Sets the power of an Expression. Use this instead of assigning `power` directly.
419
+ *
420
+ * @param x - The Expression whose power to set.
421
+ * @param power - The new power Expression.
422
+ * @returns The modified Expression `x`.
423
+ */
424
+ static setPower(x: Expression, power: Expression): Expression;
425
+ /**
426
+ * Creates multiple Expressions at once from a list of inputs.
427
+ *
428
+ * @param values - One or more inputs to convert to Expressions.
429
+ * @returns An array of Expressions.
430
+ *
431
+ * @example
432
+ * ```ts
433
+ * const [x, y] = Expression.symbols('x', 'y');
434
+ * x.text() // "x"
435
+ * y.text() // "y"
436
+ * ```
437
+ */
438
+ static symbols(...values: ExpressionInput[]): Expression[];
439
+ /**
440
+ * Creates the internal scalar Expression used to represent symbolic bracket access.
441
+ * The formatter renders this as ordinary bracket notation rather than exposing the
442
+ * internal function name.
443
+ */
444
+ static toAccessor(target: Expression, indices: Expression[]): Expression;
445
+ /**
446
+ * Constructs an `EXP` node without applying the normal power simplification rules.
447
+ *
448
+ * @remarks
449
+ * This is an internal representation helper for bases whose exponent must be stored
450
+ * separately. When `powerLess` is `true`, the existing outer power is deleted from
451
+ * the converted base before it is wrapped. Because {@link Expression.create} may
452
+ * reuse an input `Expression`, callers must not use that option when the original
453
+ * object must remain unchanged.
454
+ *
455
+ * @param x - Base to store in the `EXP` node.
456
+ * @param pow - Exponent to store on the node.
457
+ * @param powerLess - Remove an existing outer power from the base before wrapping it.
458
+ * @returns The constructed power expression, or the base itself when the base is one.
459
+ */
460
+ static toEXP(x: ExpressionInput, pow: ExpressionInput, powerLess?: boolean): Expression;
461
+ /**
462
+ * Constructs a function node and assigns its arguments.
463
+ *
464
+ * `undefined` entries are omitted. Existing `Expression` arguments may be retained
465
+ * by identity because conversion uses {@link Expression.create} without requesting
466
+ * copies. A Vector or Matrix carrying symbolic bracket access is first normalized
467
+ * to its scalar accessor Expression; ordinary structured values remain invalid
468
+ * function arguments where an Expression is required.
469
+ *
470
+ * @param name - Function name stored on the node.
471
+ * @param args - Function arguments; `undefined` entries are ignored.
472
+ * @returns The reconstructed function expression.
473
+ */
474
+ static toFunction(name: string, args: (NerdamerInput | undefined)[]): Expression;
475
+ /**
476
+ * Low-level helper that creates an Expression with a specific internal type.
477
+ *
478
+ * @param x - The value string.
479
+ * @param type - The Expression type constant (NUM, VAR, FUN, EXP, etc.).
480
+ * @returns A new Expression of the specified type.
481
+ */
482
+ static Type(x: string, type: number): Expression;
483
+ /**
484
+ * Creates a symbolic variable Expression.
485
+ *
486
+ * @param x - The variable name.
487
+ * @returns A `VAR`-typed Expression.
488
+ *
489
+ * @example
490
+ * ```ts
491
+ * Expression.Variable('x').text() // "x"
492
+ * ```
493
+ */
494
+ static Variable(x: string): Expression;
495
+ /**
496
+ * Returns the symbolic absolute value of this expression.
497
+ *
498
+ * The operation delegates to Nerdamer's `abs` implementation and may simplify
499
+ * values whose sign or complex magnitude can be determined.
500
+ *
501
+ * @returns The resulting expression; the receiver is not modified.
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * Expression.create(-5).abs().text(); // "5"
506
+ * Expression.create('x').abs().text(); // "abs(x)"
507
+ * ```
508
+ */
509
+ abs(): Expression;
510
+ /**
511
+ * Legacy alias for {@link plus}.
512
+ *
513
+ * @param x - The value to add.
514
+ * @returns A new Expression representing `this + x`.
515
+ */
516
+ add(x: ExpressionInput): Expression;
517
+ /**
518
+ * Compiles this expression into a native JavaScript numeric function.
519
+ *
520
+ * @remarks
521
+ * The generated function uses JavaScript `number` arithmetic and the registered
522
+ * numerical implementations. It is intended for repeated, relatively low-precision
523
+ * scalar evaluation rather than arbitrary-precision symbolic computation. Functions
524
+ * without a faithful JavaScript-number equivalent are rejected instead of being
525
+ * compiled with approximate or unrelated semantics.
526
+ *
527
+ * When `args` is omitted, free variables are collected and sorted alphabetically.
528
+ * Supplying `args` defines the positional argument order explicitly.
529
+ *
530
+ * @param args - Variable names in the positional order expected by the compiled function.
531
+ * @returns A JavaScript function accepting numeric arguments and returning a number.
532
+ * @throws {@link core!UnsupportedOperationError} If a surviving function has no faithful
533
+ * JavaScript-number implementation.
534
+ *
535
+ * @example
536
+ * ```ts
537
+ * const fn = Expression.create('x^2 + y').buildFunction(['x', 'y']);
538
+ * fn(3, 1); // 10
539
+ * ```
540
+ */
541
+ buildFunction(args?: string[]): (...args: number[]) => number;
542
+ /**
543
+ * Collects coefficients with respect to one or more requested variables.
544
+ *
545
+ * @remarks
546
+ * The expression is expanded as part of coefficient collection. For multivariate
547
+ * input, coefficient keys encode the exponent tuple in the same order as
548
+ * `variables`. Terms that do not contain a requested variable are retained as
549
+ * coefficients rather than discarded.
550
+ *
551
+ * @param variables - Variables whose powers define the coefficient keys.
552
+ * @returns Nerdamer's coefficient object for the requested variable ordering.
553
+ *
554
+ * @example
555
+ * ```ts
556
+ * const coefficients = Expression.create('3*x^2 + 2*x + 1').coeffs('x');
557
+ * coefficients.toArray().map(value => value.text()); // ["1", "2", "3"]
558
+ * ```
559
+ */
560
+ coeffs(...variables: string[]): import("./CoeffObject").CoeffObject;
561
+ /**
562
+ * Deep-copies the expression tree.
563
+ *
564
+ * @remarks
565
+ * Multipliers, powers, function arguments, explicit exponential bases, and aggregate
566
+ * elements are recursively copied. Mutating those structures on the returned
567
+ * expression therefore does not mutate the corresponding structures on the source.
568
+ *
569
+ * @returns An independently mutable expression with the same symbolic representation.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * const source = Expression.create('x + 1');
574
+ * const copy = source.copy();
575
+ *
576
+ * copy === source; // false
577
+ * copy.text(); // "1+x"
578
+ * ```
579
+ */
580
+ copy(): Expression;
581
+ /**
582
+ * Legacy alias for {@link getDenominator}.
583
+ *
584
+ * @returns The denominator Expression.
585
+ */
586
+ denominator(): Expression;
587
+ /**
588
+ * Distributes this node's outer multiplier through a linear sum.
589
+ *
590
+ * @remarks
591
+ * A copy is created before any changes are made. Distribution is performed only
592
+ * when the expression is sum-like, has power one, and carries a non-unit outer
593
+ * multiplier. Nested sum terms encountered during the pass are handled recursively.
594
+ * Expressions that do not meet those conditions are returned as equivalent copies.
595
+ *
596
+ * @returns A new expression with the eligible multiplier distributed.
597
+ *
598
+ * @example
599
+ * ```ts
600
+ * Expression.create('2*(x+y)').distributeMultiplier().text(); // "2*x+2*y"
601
+ * ```
602
+ */
603
+ distributeMultiplier(): Expression;
604
+ /**
605
+ * Divides this Expression by the given value.
606
+ *
607
+ * @param x - The divisor.
608
+ * @returns A new Expression representing `this / x`.
609
+ *
610
+ * @example
611
+ * ```ts
612
+ * Expression.create('x^2').div('x').text() // "x"
613
+ * Expression.create(10).div(3).text() // "10/3"
614
+ * ```
615
+ */
616
+ div(x: ExpressionInput): Expression;
617
+ /**
618
+ * Legacy alias for {@link div}.
619
+ *
620
+ * @param x - The divisor.
621
+ * @returns A new Expression representing `this / x`.
622
+ */
623
+ divide(x: ExpressionInput): Expression;
624
+ /**
625
+ * Visits the immediate terms represented by this expression.
626
+ *
627
+ * @remarks
628
+ * Aggregate nodes pass each stored element and its key to `fn`. Atomic nodes invoke
629
+ * the callback once with a unit-multiplier form of the expression and the node's
630
+ * value as the key. The callback's return value is ignored; this method does not
631
+ * rebuild the expression. Use {@link Expression.forEveryElement} when returned
632
+ * replacements should participate in reconstruction.
633
+ *
634
+ * For atomic nodes, creating the unit-multiplier argument does not mutate the receiver.
635
+ * Aggregate elements, however, are passed by reference, so the callback can mutate
636
+ * their internal objects if it chooses to do so.
637
+ *
638
+ * @param fn - Visitor receiving an immediate expression element and its key.
639
+ * @returns This expression for chaining.
640
+ */
641
+ each(fn: (a: Expression, b: string | number) => void | Expression): this;
642
+ /**
643
+ * Returns the immediate expression elements in canonical sort order.
644
+ *
645
+ * @remarks
646
+ * Sum-like nodes flatten nested linear sums one level while products retain nested
647
+ * sums. Atomic nodes contribute a unit-multiplier copy. When `withMultiplier` is
648
+ * `true`, a product's outer multiplier is appended as a numeric expression before
649
+ * sorting. The option has no effect on sums.
650
+ *
651
+ * Stored aggregate elements are returned by reference rather than deep-copied.
652
+ *
653
+ * @param withMultiplier - Include a product's outer coefficient as an array element.
654
+ * @returns The sorted immediate elements.
655
+ */
656
+ elementsArray(withMultiplier?: boolean): Expression[];
657
+ /**
658
+ * Tests whether this expression is symbolically equal to another value.
659
+ *
660
+ * @remarks
661
+ * Equality is not a JavaScript identity or raw-tree comparison. Nerdamer first
662
+ * consults applicable assumptions and otherwise subtracts the expressions,
663
+ * canonicalizes numeric radicals where needed, expands the difference, and accepts
664
+ * equality when that result reduces to numeric zero. A `false` result therefore
665
+ * means equality was not established by the current comparison machinery; it is
666
+ * not a general theorem-prover result for arbitrary symbolic identities.
667
+ *
668
+ * @param x - Value to compare with this expression.
669
+ * @returns `true` when Nerdamer establishes equality, otherwise `false`.
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * Expression.create('x+1').eq('1+x'); // true
674
+ * Expression.create(3).eq(4); // false
675
+ * ```
676
+ */
677
+ eq(x: ParserEntity | ExpressionInput): boolean;
678
+ /**
679
+ * Re-evaluates this expression numerically, optionally substituting variable values.
680
+ *
681
+ * @remarks
682
+ * Evaluation uses the ordinary serialization path. When scientific display metadata is
683
+ * present, a copy without that metadata is serialized so formatting cannot change the value sent through
684
+ * {@link Parser.evaluate}. That parser path enables Nerdamer's evaluation mode, so
685
+ * numeric constants and supported numeric functions are evaluated according to the
686
+ * parser's current precision and settings. The original expression is not modified.
687
+ *
688
+ * @param values - Variable substitutions applied during evaluation.
689
+ * @returns The evaluated expression.
690
+ *
691
+ * @example
692
+ * ```ts
693
+ * Expression.create('x^2 + 1').evaluate({ x: 3 }).text(); // "10"
694
+ * Expression.create('pi/2').evaluate().text(); // numeric approximation
695
+ * ```
696
+ */
697
+ evaluate(values?: ParserValuesObject): Expression;
698
+ /**
699
+ * Expands products and eligible powers into an equivalent symbolic expression.
700
+ *
701
+ * @remarks
702
+ * Expansion delegates to Nerdamer's canonical expansion algorithm. The result is
703
+ * independent of the receiver, but callers should treat object identity as an
704
+ * implementation detail rather than relying on expansion to allocate a particular
705
+ * representation. Branch-sensitive power rules are preserved rather than treating
706
+ * every algebraic power identity as universally valid over the complex domain.
707
+ *
708
+ * @returns The expanded expression.
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * Expression.create('(x+1)^2').expand().text(); // "1+2*x+x^2"
713
+ * ```
714
+ */
715
+ expand(): Expression;
716
+ /**
717
+ * Applies a transformation while recursively rebuilding this expression.
718
+ *
719
+ * @remarks
720
+ * Unlike {@link Expression.each}, callback results are used as replacements. The
721
+ * traversal reconstructs functions, products, sums, and exponential powers while
722
+ * restoring the original outer multiplier and power. Numeric and variable roots are
723
+ * returned unchanged by the traversal helper rather than passed through `fn`, so the
724
+ * result may preserve the receiver's identity for those atomic cases.
725
+ *
726
+ * @param fn - Transformation applied to traversed symbolic components.
727
+ * @returns The rebuilt expression.
728
+ */
729
+ forEveryElement(fn: (x: Expression) => Expression): Expression;
730
+ /**
731
+ * Collects distinct function occurrences from the expression tree.
732
+ *
733
+ * @remarks
734
+ * By default the returned strings are function names such as `sin` and `cos`.
735
+ * When `getValues` is `true`, the collector instead returns each function node's
736
+ * stored value string, such as `sin(x)`, while still deduplicating repeated values.
737
+ * Traversal includes function arguments, aggregate elements, and `EXP` bases and
738
+ * powers.
739
+ *
740
+ * If `fns` is supplied, results are appended to that same array.
741
+ *
742
+ * @param fns - Optional accumulator that receives unique strings.
743
+ * @param getValues - Collect stored function-expression strings instead of names.
744
+ * @returns The accumulator containing the collected function strings.
745
+ *
746
+ * @example
747
+ * ```ts
748
+ * Expression.create('sin(x) + cos(y)').functions(); // ["sin", "cos"]
749
+ * ```
750
+ */
751
+ functions(fns?: string[], getValues?: boolean): string[];
752
+ /**
753
+ * Returns the mutable argument array stored by this function node.
754
+ *
755
+ * @remarks
756
+ * The array is lazily created when no arguments are present and is returned by
757
+ * reference, not copied. Mutating the returned array therefore mutates this
758
+ * expression. Call {@link Expression.updateValue} after structural changes when
759
+ * the stored `value` string must be regenerated.
760
+ *
761
+ * @returns The internal function-argument array.
762
+ *
763
+ * @example
764
+ * ```ts
765
+ * Expression.create('sin(x)').getArguments()[0].text(); // "x"
766
+ * ```
767
+ */
768
+ getArguments(): Expression[];
769
+ /**
770
+ * Returns the mathematical base represented by this node.
771
+ *
772
+ * @remarks
773
+ * `EXP` nodes return their stored base directly because signs and coefficients that
774
+ * belong inside an exponential base must remain part of that base. Other node types
775
+ * derive the same base from a deep structural copy with the outer multiplier and
776
+ * outer power removed.
777
+ *
778
+ * The `EXP` branch returns the internal base by reference. The non-`EXP` branch
779
+ * returns an independent expression and does not re-enter the parser.
780
+ *
781
+ * @returns The stored or derived base expression.
782
+ *
783
+ * @example
784
+ * ```ts
785
+ * Expression.create('3*x^2').getBase().text(); // "x"
786
+ * Expression.create('2^(x+1)').getBase().text(); // "2"
787
+ * ```
788
+ */
789
+ getBase(): Expression;
790
+ /**
791
+ * Extracts the denominator represented by this expression's current structure.
792
+ *
793
+ * @remarks
794
+ * The operation collects the rational multiplier's denominator and factors carried
795
+ * by negative powers in a product. It does not first combine a sum over a common
796
+ * denominator. For example, `a/x + 8` is a sum whose outer denominator is one, while
797
+ * the individual term `a/x` has denominator `x`.
798
+ *
799
+ * @returns The denominator represented by the current expression structure.
800
+ *
801
+ * @example
802
+ * ```ts
803
+ * Expression.create('x/y').getDenominator().text() // "y"
804
+ * Expression.create('3/4').getDenominator().text() // "4"
805
+ * ```
806
+ */
807
+ getDenominator(): Expression;
808
+ /**
809
+ * Returns the mutable child-element record stored by an aggregate expression.
810
+ *
811
+ * @remarks
812
+ * When `elements` exists, the actual internal record is returned rather than a copy.
813
+ * Mutating it therefore mutates this expression and can invalidate canonical keys or
814
+ * the stored `value` string unless the caller restores the corresponding representation state. When this
815
+ * node has no element record, a new empty object is returned and is not attached to
816
+ * the expression.
817
+ *
818
+ * @returns The internal element record, or a detached empty record for atomic nodes.
819
+ */
820
+ getElements(): Record<string, Expression>;
821
+ /**
822
+ * Returns this node's effective outer rational multiplier.
823
+ *
824
+ * @remarks
825
+ * The multiplier is initialized lazily. Numeric nodes derive it from their stored
826
+ * value; other nodes default to one. Without `asExpression`, the returned
827
+ * {@link Rational} is the actual mutable multiplier owned by this expression, not a
828
+ * copy. Passing `true` wraps that rational value in a new numeric `Expression`.
829
+ *
830
+ * @param asExpression - Return the coefficient as a numeric expression instead of a rational.
831
+ * @returns The internal multiplier, or a numeric expression representing it.
832
+ *
833
+ * @example
834
+ * ```ts
835
+ * Expression.create('3*x').getMultiplier().text(); // "3"
836
+ * Expression.create('3*x').getMultiplier(true).text(); // "3"
837
+ * ```
838
+ */
839
+ getMultiplier(asExpression: true): Expression;
840
+ getMultiplier(asExpression: false): Rational;
841
+ getMultiplier(): Rational;
842
+ /**
843
+ * Extracts the numerator represented by this expression's current structure.
844
+ *
845
+ * @remarks
846
+ * The operation separates the numerator of the rational multiplier and recursively
847
+ * collects numerator factors from linear products. It does not first rewrite a sum
848
+ * over a common denominator; a sum such as `a/x + 8` therefore remains the numerator
849
+ * of that top-level representation.
850
+ *
851
+ * @returns The numerator represented by the current expression structure.
852
+ *
853
+ * @example
854
+ * ```ts
855
+ * Expression.create('x/y').getNumerator().text() // "x"
856
+ * Expression.create('3/4').getNumerator().text() // "3"
857
+ * ```
858
+ */
859
+ getNumerator(): Expression;
860
+ /**
861
+ * Returns this node's effective outer power.
862
+ *
863
+ * @remarks
864
+ * The power is initialized lazily and stored on the expression. Numeric (`NUM`)
865
+ * nodes default to power zero because their numeric value is carried by the
866
+ * multiplier; other node types default to power one. The returned `Expression` is
867
+ * the mutable internal power object, not a copy.
868
+ *
869
+ * @returns The internal power expression.
870
+ *
871
+ * @example
872
+ * ```ts
873
+ * Expression.create('x^3').getPower().text(); // "3"
874
+ * Expression.create('x').getPower().text(); // "1"
875
+ * ```
876
+ */
877
+ getPower(): Expression;
878
+ /**
879
+ * Retrieves a matching variable factor from this node.
880
+ *
881
+ * The method returns this expression when its stored value matches `variable`, or
882
+ * the matching immediate factor when this is a product. When no match is found it
883
+ * returns the numeric zero expression rather than `undefined`.
884
+ *
885
+ * @param variable - Stored variable value to locate.
886
+ * @returns The matching expression reference, or zero when no match exists.
887
+ */
888
+ getVariable(variable: string): Expression;
889
+ /**
890
+ * Tests whether this expression is `>` another value.
891
+ *
892
+ * @remarks
893
+ * Nerdamer consults applicable assumptions and otherwise evaluates the difference
894
+ * numerically/symbolically. These `Expression` comparison methods remain boolean for
895
+ * compatibility. An unknown assumption result falls through to the ordinary comparison
896
+ * path; if the relation still cannot be established, the method returns `false`. The
897
+ * lower-level `Assumption` relations preserve unknown as `undefined`. Complex values are
898
+ * not ordered and cause the comparison to throw.
899
+ *
900
+ * @param x - Value to compare with this expression.
901
+ * @returns `true` when the requested ordering is established, otherwise `false`.
902
+ * @throws {@link core!UnsupportedOperationError}
903
+ * Thrown when either side is classified as complex.
904
+ */
905
+ gt(x: ExpressionInput | ParserEntity): boolean;
906
+ /**
907
+ * Tests whether this expression is `>=` another value.
908
+ *
909
+ * @remarks
910
+ * Nerdamer consults applicable assumptions and otherwise evaluates the difference
911
+ * numerically/symbolically. These `Expression` comparison methods remain boolean for
912
+ * compatibility. An unknown assumption result falls through to the ordinary comparison
913
+ * path; if the relation still cannot be established, the method returns `false`. The
914
+ * lower-level `Assumption` relations preserve unknown as `undefined`. Complex values are
915
+ * not ordered and cause the comparison to throw.
916
+ *
917
+ * @param x - Value to compare with this expression.
918
+ * @returns `true` when the requested ordering is established, otherwise `false`.
919
+ * @throws {@link core!UnsupportedOperationError}
920
+ * Thrown when either side is classified as complex.
921
+ */
922
+ gte(x: ExpressionInput | ParserEntity): boolean;
923
+ /**
924
+ * Reports whether decimal-origin numeric data occurs anywhere in this expression.
925
+ *
926
+ * @remarks
927
+ * The check follows the multiplier, explicit power, exponential base, function
928
+ * arguments, and aggregate elements. It tests the rational `asDecimal` provenance
929
+ * marker; it does not merely search rendered text for a decimal point.
930
+ *
931
+ * @returns `true` when any contained rational originated from decimal input.
932
+ */
933
+ hasDecimal(): boolean;
934
+ /**
935
+ * Tests whether a named function occurs in this expression.
936
+ *
937
+ * @remarks
938
+ * Aggregate elements are always searched. When `deep` is `true`, function arguments
939
+ * and the explicit base and power of `EXP` nodes are searched recursively as well.
940
+ * With `deep` disabled, nested function arguments and `EXP` components are not
941
+ * traversed.
942
+ *
943
+ * @param name - Function name to locate.
944
+ * @param deep - Include function arguments and `EXP` base/power traversal.
945
+ * @returns `true` when the named function is found.
946
+ */
947
+ hasFunction(name: string, deep?: boolean): boolean;
948
+ /**
949
+ * Tests the node's outer power for a rational exponent with a non-unit denominator.
950
+ *
951
+ * @remarks
952
+ * This predicate examines this node's effective power; it does not recursively scan
953
+ * every descendant for radicals. When `checkIrrationalDenominator` is `true`, the
954
+ * power must also be negative, which identifies a radical occurring in a denominator.
955
+ *
956
+ * @param checkIrrationalDenominator - Require the fractional power to be negative.
957
+ * @returns `true` when the outer power meets the requested radical condition.
958
+ */
959
+ hasRadical(checkIrrationalDenominator?: boolean): boolean;
960
+ /**
961
+ * Tests whether a variable node with the requested value occurs in the expression tree.
962
+ *
963
+ * Function arguments, aggregate elements, and `EXP` bases and powers are searched
964
+ * recursively. This predicate does not apply the free-variable filtering used by
965
+ * {@link Expression.variables}; reserved constants can still match when requested
966
+ * explicitly.
967
+ *
968
+ * @param variable - Variable value to locate.
969
+ * @returns `true` when a matching `VAR` node occurs.
970
+ */
971
+ hasVariable(variable: string): boolean;
972
+ /**
973
+ * Multiplies this Expression by the imaginary unit, converting it to an imaginary value.
974
+ *
975
+ * @returns A new Expression equal to `this * i`.
976
+ *
977
+ * @example
978
+ * ```ts
979
+ * Expression.create(3).i().text() // "3*i"
980
+ * ```
981
+ */
982
+ i(): Expression;
983
+ /**
984
+ * Returns a string representation used internally for structural comparison
985
+ * of expressions.
986
+ *
987
+ * @returns A string identifier suitable for equality checks.
988
+ */
989
+ idString(): string;
990
+ /**
991
+ * Returns Nerdamer's symbolic decomposition of the imaginary component.
992
+ *
993
+ * @remarks
994
+ * The result excludes the imaginary-unit factor itself. Decomposition follows
995
+ * principal-branch handling for powered complex values and preserves unresolved
996
+ * complex function components symbolically instead of silently treating them as
997
+ * zero. `realpart(...)` and `imagpart(...)` nodes are treated as real-valued component
998
+ * expressions.
999
+ *
1000
+ * @returns The symbolic imaginary coefficient.
1001
+ */
1002
+ imagPart(): Expression;
1003
+ /**
1004
+ * Returns the multiplicative inverse of this expression.
1005
+ *
1006
+ * @remarks
1007
+ * Real symbolic nodes are copied and inverted by negating the outer power and
1008
+ * rational multiplier. Complex expressions use the general division path so real and
1009
+ * imaginary components are handled correctly. Simple radical denominators are
1010
+ * rationalized when the power operation identifies an eligible radical.
1011
+ *
1012
+ * The receiver is not modified.
1013
+ *
1014
+ * @returns The reciprocal expression.
1015
+ * @throws {@link core!DivisionByZeroError}
1016
+ * Thrown by the underlying rational or division operation when the expression is zero.
1017
+ */
1018
+ invert(): Expression;
1019
+ /**
1020
+ * Reports whether the current expression tree contains a complex-valued component.
1021
+ *
1022
+ * @remarks
1023
+ * The check is structural: it recognizes the current imaginary-unit symbol, recurses
1024
+ * through function arguments, `EXP` bases and powers, and aggregate elements. The
1025
+ * component functions `realpart(...)` and `imagpart(...)` are treated as real-valued
1026
+ * by definition even when their arguments contain complex values.
1027
+ *
1028
+ * This predicate does not impose an ordering or otherwise claim that an unrestricted
1029
+ * symbolic expression is provably real.
1030
+ *
1031
+ * @returns `true` when the represented expression contains a recognized complex component.
1032
+ */
1033
+ isComplex(): boolean;
1034
+ /**
1035
+ * Tests whether this node is `realpart(...)` or `imagpart(...)`.
1036
+ *
1037
+ * These component functions are treated as real-valued by the complex-decomposition
1038
+ * logic even when their arguments are complex.
1039
+ */
1040
+ isComplexComponentFunction(): boolean;
1041
+ /**
1042
+ * Tests whether this node belongs to Nerdamer's currently recognized constant forms.
1043
+ *
1044
+ * @remarks
1045
+ * This is narrower than the mathematical statement "contains no free
1046
+ * variables." It recognizes numeric nodes, parser constants such as `pi` and `e`,
1047
+ * constant-base/constant-power `EXP` nodes, and sums or products whose elements are
1048
+ * recursively recognized as constant. The imaginary unit is handled by
1049
+ * dedicated complex logic rather than classified here as a parser constant.
1050
+ *
1051
+ * Do not use this predicate as a general proof that an arbitrary function expression
1052
+ * is or is not mathematically constant.
1053
+ *
1054
+ * @returns `true` for the constant forms recognized by this predicate.
1055
+ */
1056
+ isConstant(): boolean;
1057
+ /**
1058
+ * Tests whether this node's stored value is the Euler-constant symbol `e`.
1059
+ *
1060
+ * The check is representation-level and does not require a unit multiplier or power.
1061
+ *
1062
+ * @returns `true` when `value` is the current `e` symbol.
1063
+ */
1064
+ isE(): boolean;
1065
+ /**
1066
+ * Checks whether this Expression is an even integer.
1067
+ *
1068
+ * @returns `true` if the expression is `NUM` and its multiplier is even.
1069
+ *
1070
+ * @example
1071
+ * ```ts
1072
+ * Expression.create(4).isEven() // true
1073
+ * Expression.create(3).isEven() // false
1074
+ * ```
1075
+ */
1076
+ isEven(): boolean;
1077
+ /**
1078
+ * Checks whether this Expression has the EXP (exponential/power) internal type.
1079
+ *
1080
+ * @returns `true` if the type is EXP.
1081
+ */
1082
+ isEXP(): this is this & {
1083
+ base: Expression;
1084
+ };
1085
+ /**
1086
+ * Checks whether this Expression is a function node.
1087
+ *
1088
+ * @returns `true` if the expression is a function node.
1089
+ *
1090
+ * @example
1091
+ * ```ts
1092
+ * Expression.create('sin(x)').isFunction() // true
1093
+ * Expression.create('x').isFunction() // false
1094
+ * ```
1095
+ */
1096
+ isFunction(): this is this & {
1097
+ name: string;
1098
+ };
1099
+ /**
1100
+ * Checks whether this Expression is a function node with one of the given names.
1101
+ *
1102
+ * @param names - A single function name or an array of names to match.
1103
+ * @returns `true` if the expression is a function node with a matching name.
1104
+ *
1105
+ * @example
1106
+ * ```ts
1107
+ * Expression.create('sin(x)').isFunction('sin') // true
1108
+ * Expression.create('sin(x)').isFunction('cos') // false
1109
+ * ```
1110
+ */
1111
+ isFunction(names: string | string[]): boolean;
1112
+ /**
1113
+ * Checks whether this Expression is exactly `1/2`.
1114
+ *
1115
+ * @returns `true` if the expression is the numeric value `1/2`.
1116
+ */
1117
+ isHalf(): boolean;
1118
+ /**
1119
+ * Tests whether this node's stored value is the current imaginary-unit symbol.
1120
+ *
1121
+ * @remarks
1122
+ * This is a representation-level symbol check. It does not require the node to have
1123
+ * multiplier one or power one, so callers that require exactly the mathematical unit
1124
+ * `i` must impose those additional conditions themselves.
1125
+ *
1126
+ * @returns `true` when `value` matches {@link Expression.imaginary}.
1127
+ */
1128
+ isI(): boolean;
1129
+ /**
1130
+ * Evaluates the expression and reports whether the result is classified as complex.
1131
+ *
1132
+ * @remarks
1133
+ * Despite the historical method name, this is not a test for a purely imaginary
1134
+ * value with zero real part. A value such as `3 + 2*i` also returns `true` because
1135
+ * the evaluated result contains a complex component.
1136
+ *
1137
+ * @returns `true` when the evaluated expression satisfies {@link Expression.isComplex}.
1138
+ */
1139
+ isImaginary(): boolean;
1140
+ /**
1141
+ * Checks whether this Expression represents infinity (positive or negative).
1142
+ *
1143
+ * @returns `true` if the type is INF.
1144
+ */
1145
+ isInf(): boolean;
1146
+ /**
1147
+ * Checks whether this Expression is an exact integer.
1148
+ *
1149
+ * @returns `true` if the expression is `NUM` with an integer multiplier.
1150
+ *
1151
+ * @example
1152
+ * ```ts
1153
+ * Expression.create(5).isInteger() // true
1154
+ * Expression.create('3/2').isInteger() // false
1155
+ * ```
1156
+ */
1157
+ isInteger(): boolean;
1158
+ /**
1159
+ * Checks whether this Expression has power equal to `1` (i.e. is linear in itself).
1160
+ *
1161
+ * @returns `true` if the power is `1`.
1162
+ */
1163
+ isLinear(): boolean;
1164
+ /**
1165
+ * Checks whether this Expression is exactly `-1`.
1166
+ *
1167
+ * @returns `true` if the expression equals `-1`.
1168
+ */
1169
+ isMinusOne(): boolean;
1170
+ /**
1171
+ * Tests whether both evaluated complex components are small relative to Decimal precision.
1172
+ *
1173
+ * @remarks
1174
+ * The tolerance is `10^(-Decimal.precision + k)`. This is a numerical-algorithm
1175
+ * convenience and must not be used as a replacement for exact symbolic zero testing;
1176
+ * use {@link Expression.isZero} when exact representation-level zero is required.
1177
+ *
1178
+ * @param k - Number of guard digits removed from the active Decimal precision.
1179
+ * @returns `true` when the magnitudes of both real and imaginary components are within the tolerance.
1180
+ */
1181
+ isNearlyZero(k?: number): boolean;
1182
+ /**
1183
+ * Tests whether this expression is established to be strictly less than zero.
1184
+ *
1185
+ * The result follows {@link Expression.lt}: unresolved symbolic sign information
1186
+ * currently produces `false`, while complex values cannot be ordered.
1187
+ *
1188
+ * @returns `true` when the current comparison machinery establishes a negative value.
1189
+ * @throws {@link core!UnsupportedOperationError}
1190
+ * Thrown when the expression is classified as complex.
1191
+ */
1192
+ isNegative(): boolean;
1193
+ /**
1194
+ * Checks whether this Expression is negative infinity (`−∞`).
1195
+ *
1196
+ * @returns `true` if the expression is `−∞`.
1197
+ */
1198
+ isNegInf(): boolean;
1199
+ /**
1200
+ * Checks whether this Expression has the `NUM` (numeric) internal type.
1201
+ *
1202
+ * This only matches explicit numbers, not symbolic constants like `pi` or `e`.
1203
+ * Use {@link isConstant} to check for all values that reduce to a constant.
1204
+ *
1205
+ * @returns `true` if the type is `NUM`.
1206
+ *
1207
+ * @example
1208
+ * ```ts
1209
+ * Expression.create(5).isNUM() // true
1210
+ * Expression.create('pi').isNUM() // false
1211
+ * ```
1212
+ */
1213
+ isNUM(): boolean;
1214
+ /**
1215
+ * Tests whether this Expression is represented as a plain numeric value.
1216
+ *
1217
+ * @returns `true` for NUM expressions.
1218
+ */
1219
+ isNumber(): boolean;
1220
+ /**
1221
+ * Checks whether this Expression is an odd integer.
1222
+ *
1223
+ * @returns `true` only for numeric integer expressions whose multiplier is odd.
1224
+ */
1225
+ isOdd(): boolean;
1226
+ /**
1227
+ * Checks whether this Expression is exactly `1`.
1228
+ *
1229
+ * @returns `true` if the expression equals `1`.
1230
+ */
1231
+ isOne(): boolean;
1232
+ /**
1233
+ * Tests whether this node's stored value matches a recognized π symbol.
1234
+ *
1235
+ * The check is representation-level and does not require a unit multiplier or power.
1236
+ *
1237
+ * @returns `true` when `value` is one of Nerdamer's π aliases.
1238
+ */
1239
+ isPi(): boolean;
1240
+ /**
1241
+ * Checks whether this Expression is a plain variable with no multiplier and
1242
+ * no power (i.e. multiplier `1`, power `1`, type `VAR`).
1243
+ *
1244
+ * @returns `true` for a bare variable like `x`.
1245
+ *
1246
+ * @example
1247
+ * ```ts
1248
+ * Expression.create('x').isPlainVariable() // true
1249
+ * Expression.create('2*x').isPlainVariable() // false
1250
+ * Expression.create('x^2').isPlainVariable() // false
1251
+ * ```
1252
+ */
1253
+ isPlainVariable(): boolean;
1254
+ /**
1255
+ * Tests whether this expression has the structural form of a polynomial over rational coefficients.
1256
+ *
1257
+ * @remarks
1258
+ * The predicate accepts recursively composed sums and products whose outer powers are
1259
+ * non-negative integers. Function nodes, `EXP` nodes, infinities, negative powers,
1260
+ * and fractional powers are rejected. This is a structural eligibility check used by
1261
+ * polynomial-oriented algorithms; it does not construct a {@link algebra!Polynomial}.
1262
+ *
1263
+ * @returns `true` when the expression satisfies the current polynomial-like restrictions.
1264
+ */
1265
+ isPolynomialLike(): boolean;
1266
+ /**
1267
+ * Checks whether this Expression is positive infinity (`+∞`).
1268
+ *
1269
+ * @returns `true` if the expression is `+∞`.
1270
+ */
1271
+ isPosInf(): boolean;
1272
+ /**
1273
+ * Checks whether this Expression has the PRD (product) internal type.
1274
+ *
1275
+ * @returns `true` if the type is PRD.
1276
+ */
1277
+ isProduct(): boolean;
1278
+ /**
1279
+ * Checks whether this Expression is exactly `1/4`.
1280
+ *
1281
+ * @returns `true` if the expression is the numeric value `1/4`.
1282
+ */
1283
+ isQuarter(): boolean;
1284
+ /**
1285
+ * Checks whether this Expression is a summation-like type (SUM or GRP).
1286
+ *
1287
+ * @returns `true` if the type is SUM or GRP.
1288
+ */
1289
+ isSum(): boolean;
1290
+ /**
1291
+ * Checks whether this Expression has the VAR (variable) internal type.
1292
+ *
1293
+ * @returns `true` if the type is VAR.
1294
+ */
1295
+ isVAR(): boolean;
1296
+ /**
1297
+ * Checks whether this Expression is exactly `0`.
1298
+ *
1299
+ * @returns `true` if the multiplier is zero.
1300
+ *
1301
+ * @example
1302
+ * ```ts
1303
+ * Expression.create(0).isZero() // true
1304
+ * Expression.create(1).isZero() // false
1305
+ * ```
1306
+ */
1307
+ isZero(): boolean;
1308
+ /**
1309
+ * Builds the canonical lookup key used to group compatible expression terms.
1310
+ *
1311
+ * @remarks
1312
+ * This is an internal canonicalization key, not a user-facing serialization format.
1313
+ * Numeric nodes normally collapse to {@link Expression.numberHash}; variables,
1314
+ * functions, exponentials, and infinities use multiplier-free identifiers; aggregate
1315
+ * nodes derive a key from their canonical elements. Group (`GRP`) handling can use the
1316
+ * power directly when `isGroup` is requested.
1317
+ *
1318
+ * The exact key format is coupled to parser/algebra combination logic and should not
1319
+ * be persisted as an external interchange format.
1320
+ *
1321
+ * @param asSubExpression - Use the fuller sub-expression representation where supported.
1322
+ * @param isGroup - Build a group-member key from this expression's power.
1323
+ * @returns The canonical lookup key.
1324
+ * @throws Error
1325
+ * Thrown when no key-generation rule exists for the node's internal type.
1326
+ */
1327
+ keyValue(asSubExpression?: boolean, isGroup?: boolean): string;
1328
+ /**
1329
+ * Tests whether this expression is `<` another value.
1330
+ *
1331
+ * @remarks
1332
+ * Nerdamer consults applicable assumptions and otherwise evaluates the difference
1333
+ * numerically/symbolically. These `Expression` comparison methods remain boolean for
1334
+ * compatibility. An unknown assumption result falls through to the ordinary comparison
1335
+ * path; if the relation still cannot be established, the method returns `false`. The
1336
+ * lower-level `Assumption` relations preserve unknown as `undefined`. Complex values are
1337
+ * not ordered and cause the comparison to throw.
1338
+ *
1339
+ * @param x - Value to compare with this expression.
1340
+ * @returns `true` when the requested ordering is established, otherwise `false`.
1341
+ * @throws {@link core!UnsupportedOperationError}
1342
+ * Thrown when either side is classified as complex.
1343
+ */
1344
+ lt(x: ExpressionInput | ParserEntity): boolean;
1345
+ /**
1346
+ * Tests whether this expression is `<=` another value.
1347
+ *
1348
+ * @remarks
1349
+ * Nerdamer consults applicable assumptions and otherwise evaluates the difference
1350
+ * numerically/symbolically. These `Expression` comparison methods remain boolean for
1351
+ * compatibility. An unknown assumption result falls through to the ordinary comparison
1352
+ * path; if the relation still cannot be established, the method returns `false`. The
1353
+ * lower-level `Assumption` relations preserve unknown as `undefined`. Complex values are
1354
+ * not ordered and cause the comparison to throw.
1355
+ *
1356
+ * @param x - Value to compare with this expression.
1357
+ * @returns `true` when the requested ordering is established, otherwise `false`.
1358
+ * @throws {@link core!UnsupportedOperationError}
1359
+ * Thrown when either side is classified as complex.
1360
+ */
1361
+ lte(x: ExpressionInput | ParserEntity): boolean;
1362
+ /**
1363
+ * Subtracts `x` from this Expression.
1364
+ *
1365
+ * @param x - The value to subtract.
1366
+ * @returns A new Expression representing `this − x`.
1367
+ *
1368
+ * @example
1369
+ * ```ts
1370
+ * Expression.create('x').minus(1).text() // "-1+x"
1371
+ * Expression.create(10).minus(3).text() // "7"
1372
+ * ```
1373
+ */
1374
+ minus(x: ExpressionInput): Expression;
1375
+ /**
1376
+ * Computes the modulo of this Expression by `x`.
1377
+ *
1378
+ * @param x - The divisor.
1379
+ * @returns A new Expression representing `this mod x`.
1380
+ *
1381
+ * @example
1382
+ * ```ts
1383
+ * Expression.create(10).mod(3).text() // "1"
1384
+ * ```
1385
+ */
1386
+ mod(x: ExpressionInput): Expression;
1387
+ /**
1388
+ * Legacy alias for {@link times}.
1389
+ *
1390
+ * @param x - The value to multiply by.
1391
+ * @returns A new Expression representing `this * x`.
1392
+ */
1393
+ multiply(x: ExpressionInput): Expression;
1394
+ /**
1395
+ * Negates this Expression by flipping the sign of the multiplier.
1396
+ *
1397
+ * @returns A new Expression equal to `this * −1`.
1398
+ *
1399
+ * @example
1400
+ * ```ts
1401
+ * Expression.create(5).neg().text() // "-5"
1402
+ * Expression.create('x').neg().text() // "-x"
1403
+ * ```
1404
+ */
1405
+ neg(): Expression;
1406
+ /**
1407
+ * Legacy alias for {@link getNumerator}.
1408
+ *
1409
+ * @returns The numerator Expression.
1410
+ */
1411
+ numerator(): Expression;
1412
+ /**
1413
+ * Compatibility alias for the copy-oriented base extraction used by
1414
+ * {@link Expression.toLinearAndUnitMultiplier}.
1415
+ *
1416
+ * @returns An independent Expression representing the node's mathematical base.
1417
+ */
1418
+ parseValue(): Expression;
1419
+ /**
1420
+ * Adds `x` to this Expression.
1421
+ *
1422
+ * @param x - The value to add.
1423
+ * @returns A new Expression representing `this + x`.
1424
+ *
1425
+ * @example
1426
+ * ```ts
1427
+ * Expression.create('x').plus(1).text() // "1+x"
1428
+ * Expression.create(2).plus(3).text() // "5"
1429
+ * ```
1430
+ */
1431
+ plus(x: ExpressionInput): Expression;
1432
+ /**
1433
+ * Raises this expression to a symbolic or numeric exponent.
1434
+ *
1435
+ * @remarks
1436
+ * The operation delegates to Nerdamer's power canonicalization and simplification
1437
+ * rules. Noninteger and complex powers follow principal-branch semantics; identities
1438
+ * such as distributing a fractional power over arbitrary products are therefore
1439
+ * applied only when the implementation can preserve the relevant branch.
1440
+ *
1441
+ * The receiver is not modified.
1442
+ *
1443
+ * @param x - Exponent to apply.
1444
+ * @returns The simplified power expression.
1445
+ * @throws {@link core!UndefinedError}
1446
+ * Thrown for undefined infinity-related powers handled by the power operation.
1447
+ * @throws {@link core!ZeroToZeroPowerError}
1448
+ * Thrown for zero-power cases classified as undefined by the power operation.
1449
+ */
1450
+ pow(x: ExpressionInput): Expression;
1451
+ /**
1452
+ * Returns Nerdamer's symbolic decomposition of the real component.
1453
+ *
1454
+ * @remarks
1455
+ * Decomposition follows principal-branch handling for powered complex values.
1456
+ * Explicitly complex function calls that cannot be decomposed are preserved through
1457
+ * a symbolic `realpart(...)` wrapper rather than being guessed. The component
1458
+ * functions `realpart(...)` and `imagpart(...)` are themselves treated as real-valued.
1459
+ *
1460
+ * @returns The symbolic real component.
1461
+ */
1462
+ realPart(): Expression;
1463
+ /**
1464
+ * Returns the sign encoded by this node's coefficient representation.
1465
+ *
1466
+ * @remarks
1467
+ * This is not a general symbolic sign analysis. Most node types return the sign of
1468
+ * their outer {@link Rational} multiplier. `EXP` nodes additionally multiply that
1469
+ * result by the representation-level sign of their stored base. Unknown assumptions
1470
+ * are not inferred here.
1471
+ *
1472
+ * @returns `-1`, `0`, or `1` from the represented coefficient/base sign.
1473
+ */
1474
+ sign(): number;
1475
+ /**
1476
+ * Removes the sign represented by this expression's current form.
1477
+ *
1478
+ * @remarks
1479
+ * Complex expressions return their modulus `sqrt(re^2 + im^2)`. For other
1480
+ * expressions, the method copies the node and removes a negative stored sign or
1481
+ * multiplier. This is representation-oriented normalization, not a general
1482
+ * assumption-driven implementation of symbolic `abs(...)`.
1483
+ *
1484
+ * @returns A new sign-free expression or complex modulus.
1485
+ */
1486
+ signFree(): Expression;
1487
+ /**
1488
+ * Formats this expression using SymPy-style `**` exponentiation syntax.
1489
+ *
1490
+ * @remarks
1491
+ * Formatting temporarily switches the class-wide power-operator token while
1492
+ * delegating to the normal expression formatter, then restores `^`. The expression
1493
+ * itself is not modified.
1494
+ *
1495
+ * @param options - Formatting options accepted by the normal text formatter.
1496
+ * @param asId - Request the internal identifier-oriented formatting mode.
1497
+ * @returns SymPy-compatible expression text.
1498
+ */
1499
+ sptext(options?: TextOptions, asId?: boolean): string;
1500
+ /**
1501
+ * Squares this Expression. Shorthand for `this.pow('2')`.
1502
+ *
1503
+ * @returns A new Expression representing `this²`.
1504
+ *
1505
+ * @example
1506
+ * ```ts
1507
+ * Expression.create('x').sq().text() // "x^2"
1508
+ * Expression.create(5).sq().text() // "25"
1509
+ * ```
1510
+ */
1511
+ sq(): Expression;
1512
+ /**
1513
+ * Tests Nerdamer equality while also requiring the same top-level internal type.
1514
+ *
1515
+ * @remarks
1516
+ * This is stricter than {@link Expression.eq}, but it is still not object identity or
1517
+ * byte-for-byte tree equality. After verifying matching top-level types (or matching
1518
+ * function names for function nodes), it delegates to Nerdamer's symbolic equality
1519
+ * comparison.
1520
+ *
1521
+ * @param x - Value to compare with this expression.
1522
+ * @returns `true` when the type/name requirement and symbolic equality both hold.
1523
+ */
1524
+ strictEqual(x: ExpressionInput): boolean;
1525
+ /**
1526
+ * Legacy alias for {@link subst}.
1527
+ *
1528
+ * @param value - The sub-expression to find.
1529
+ * @param withValue - The replacement expression.
1530
+ * @returns A new Expression with the substitution applied.
1531
+ */
1532
+ sub(value: ExpressionInput, withValue: ExpressionInput): Expression;
1533
+ /**
1534
+ * Replaces occurrences of one symbolic expression with another.
1535
+ *
1536
+ * @remarks
1537
+ * Substitution supports more than direct variable replacement: the underlying
1538
+ * algorithm can match compatible products and sums, recurse into function arguments,
1539
+ * and substitute within powers. Inputs are converted through
1540
+ * {@link Expression.create}. The receiver is not mutated as part of normal execution. Unchanged
1541
+ * branches can preserve the receiver's identity, and an exact match can return the
1542
+ * supplied replacement object directly, so callers that require independent ownership
1543
+ * should copy the result explicitly.
1544
+ *
1545
+ * @param value - Symbolic value or sub-expression to match.
1546
+ * @param withValue - Replacement value.
1547
+ * @returns The expression produced by the substitution algorithm.
1548
+ */
1549
+ subst(value: ExpressionInput, withValue: ExpressionInput): Expression;
1550
+ /**
1551
+ * Legacy alias for {@link minus}.
1552
+ *
1553
+ * @param x - The value to subtract.
1554
+ * @returns A new Expression representing `this − x`.
1555
+ */
1556
+ subtract(x: ExpressionInput): Expression;
1557
+ /**
1558
+ * Formats this expression using Nerdamer's canonical text formatter.
1559
+ *
1560
+ * @remarks
1561
+ * Exact rational text is the default. Use `sort: true` to render terms in Nerdamer's
1562
+ * conventional display order without changing the stored expression. Decimal output,
1563
+ * precision, scientific notation, and power wrapping can also be selected per call. The `asId` mode is used
1564
+ * by internal identity/canonicalization logic and should not be
1565
+ * treated as a stable interchange format.
1566
+ *
1567
+ * @param options - Text-formatting options.
1568
+ * @param asId - Use the internal identifier-oriented formatting mode.
1569
+ * @returns The formatted expression text.
1570
+ *
1571
+ * @example
1572
+ * ```ts
1573
+ * Expression.create('x^2 + 2*x + 1').text(); // "1+2*x+x^2"
1574
+ * Expression.create('x^2 + 2*x + 1').text({ sort: true }); // "x^2+2*x+1"
1575
+ * Expression.create('1/3').text(); // "1/3"
1576
+ * Expression.create('1/3').text({ decimal: true }); // decimal representation
1577
+ * Expression.create('12345').text({ scientific: 3 }); // "1.23e4"
1578
+ * ```
1579
+ */
1580
+ text(options?: TextOptions, asId?: boolean): string;
1581
+ /**
1582
+ * Multiplies this Expression by `x`.
1583
+ *
1584
+ * @param x - The value to multiply by.
1585
+ * @returns A new Expression representing `this * x`.
1586
+ *
1587
+ * @example
1588
+ * ```ts
1589
+ * Expression.create('x').times(3).text() // "3*x"
1590
+ * Expression.create('x').times('y').text() // "x*y"
1591
+ * ```
1592
+ */
1593
+ times(x: ExpressionInput): Expression;
1594
+ /**
1595
+ * Formats this expression using decimal numeric output.
1596
+ *
1597
+ * This is a formatting operation equivalent to calling {@link Expression.text} with
1598
+ * `{ decimal: true }`; it does not convert the expression tree into a floating-point
1599
+ * data structure.
1600
+ *
1601
+ * @param precision - Optional decimal formatting precision.
1602
+ * @returns Decimal-form expression text.
1603
+ */
1604
+ toDecimal(precision?: number): string;
1605
+ /**
1606
+ * Returns an independent base expression with the outer multiplier and power removed.
1607
+ *
1608
+ * @remarks
1609
+ * Base extraction is defined by {@link Expression.getBase}. Because `getBase()`
1610
+ * exposes an `EXP` node's stored base by reference, this method copies
1611
+ * that base before returning it. Non-`EXP` bases are already independent copies.
1612
+ *
1613
+ * @returns An independent expression representing the node without its outer multiplier and power.
1614
+ */
1615
+ toLinearAndUnitMultiplier(): Expression;
1616
+ /**
1617
+ * Returns the string representation. Alias for {@link text}.
1618
+ *
1619
+ * @param options - Formatting options passed to {@link text}.
1620
+ * @returns The text representation.
1621
+ */
1622
+ toString(options?: TextOptions): string;
1623
+ /**
1624
+ * Returns the total degree of a monomial by summing the powers of all factors
1625
+ * in a product expression. For non-product types, returns the expression's own power.
1626
+ *
1627
+ * @returns The total power as an Expression.
1628
+ *
1629
+ * @example
1630
+ * ```ts
1631
+ * Expression.create('x^2*y^3').totalPower().text() // "5"
1632
+ * Expression.create('x^4').totalPower().text() // "4"
1633
+ * ```
1634
+ */
1635
+ totalPower(): Expression;
1636
+ /**
1637
+ * Returns a copy of this Expression with the multiplier removed (set to `1`).
1638
+ *
1639
+ * For `NUM` types (where the multiplier *is* the value), returns `1`.
1640
+ *
1641
+ * @returns A new multiplier-free Expression.
1642
+ *
1643
+ * @example
1644
+ * ```ts
1645
+ * Expression.create('3*x').toUnitMultiplier().text() // "x"
1646
+ * Expression.create(5).toUnitMultiplier().text() // "1"
1647
+ * ```
1648
+ */
1649
+ toUnitMultiplier(): Expression;
1650
+ /**
1651
+ * Regenerates the stored `value` string from mutable structural state where supported.
1652
+ *
1653
+ * @remarks
1654
+ * Function nodes rebuild `value` from their name and arguments. Product and sum-like
1655
+ * nodes rebuild it from their current elements. Other node types are left unchanged.
1656
+ * This method mutates the receiver and returns the same object for chaining.
1657
+ *
1658
+ * @param aggregateElements - Exact aggregate elements already available to a caller
1659
+ * rebuilding a SUM/PRD node. When supplied, the generated value is also the ordinary
1660
+ * lookup key and can seed the key cache without a second formatting pass.
1661
+ * @returns This expression after updating its stored value where applicable.
1662
+ */
1663
+ updateValue(aggregateElements?: Expression[]): this;
1664
+ /**
1665
+ * Provides the primitive value used by JavaScript coercion.
1666
+ *
1667
+ * Numeric (`NUM`) expressions return the primitive value of their rational
1668
+ * multiplier. Other expressions return decimal-formatted text. This coercion API is
1669
+ * intended for JavaScript interoperability; use explicit symbolic comparison methods
1670
+ * when mathematical equality or ordering is required.
1671
+ *
1672
+ * @returns A number for numeric nodes, otherwise decimal-form expression text.
1673
+ */
1674
+ valueOf(): number | string;
1675
+ /**
1676
+ * Collects distinct free-variable names from this expression tree.
1677
+ *
1678
+ * @remarks
1679
+ * Only `VAR` nodes are collected. The current imaginary-unit symbol and names in
1680
+ * {@link Expression.RESERVED} are excluded. Traversal includes function arguments,
1681
+ * aggregate elements, and `EXP` bases and powers. Encounter order is preserved unless
1682
+ * the caller sorts the returned array separately.
1683
+ *
1684
+ * If `vars` is supplied, new names are appended to that same accumulator without
1685
+ * duplicating names already present.
1686
+ *
1687
+ * @param vars - Optional accumulator of names already collected.
1688
+ * @returns The accumulator containing distinct variable names.
1689
+ */
1690
+ variables(vars?: string[]): string[];
1691
+ }