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,25 @@
1
+ import { CoeffObject } from './CoeffObject';
2
+ import { Expression } from './Expression';
3
+ /**
4
+ * Separates the variable and coefficient for the specified variable
5
+ *
6
+ * @param x
7
+ * @param variable
8
+ * @returns
9
+ */
10
+ export declare function separateVar(x: Expression, variables: (string | Expression)[]): Expression[];
11
+ /**
12
+ * Gets the coefficients wrt to a given variable
13
+ *
14
+ * @param wrt
15
+ */
16
+ export declare function coeffs(x: Expression, variables: string[], coeffsObj?: CoeffObject, expandExpression?: boolean): CoeffObject;
17
+ export declare function getDenominator(x: Expression): Expression;
18
+ export declare function getNumerator(x: Expression): Expression; /**
19
+ * Returns true fo polynomial with coefficients in Z or Q.
20
+ * @param x
21
+ * @returns
22
+ */
23
+ export declare function isPolynomialLike(x: Expression): boolean;
24
+ export declare function getVariable(x: Expression, variable: string): Expression;
25
+ export declare function normalizeMultiplierDenominators(x: Expression): Expression;
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.separateVar = separateVar;
4
+ exports.coeffs = coeffs;
5
+ exports.getDenominator = getDenominator;
6
+ exports.getNumerator = getNumerator;
7
+ exports.isPolynomialLike = isPolynomialLike;
8
+ exports.getVariable = getVariable;
9
+ exports.normalizeMultiplierDenominators = normalizeMultiplierDenominators;
10
+ const errors_1 = require("../../errors");
11
+ const bigint_1 = require("../../functions/bigint/bigint");
12
+ const expand_1 = require("../../functions/expand/expand");
13
+ const CoeffObject_1 = require("./CoeffObject");
14
+ const Expression_1 = require("./Expression");
15
+ const shortcuts_1 = require("./shortcuts");
16
+ const utils_1 = require("./utils");
17
+ /**
18
+ * Separates the variable and coefficient for the specified variable
19
+ *
20
+ * @param x
21
+ * @param variable
22
+ * @returns
23
+ */
24
+ function separateVar(x, variables) {
25
+ // Extract the value of the variable if a Expression was provided
26
+ const vars = variables.map(x => {
27
+ if (typeof x !== 'string') {
28
+ return x.value;
29
+ }
30
+ return x;
31
+ });
32
+ function isLike(x, vars) {
33
+ return vars.includes(x.value);
34
+ }
35
+ let retval;
36
+ // You can only separate in a product and not a sum. e.g. 3*a*x
37
+ if (x.isProduct()) {
38
+ const coeff = [Expression_1.Expression.fromRational(x.getMultiplier())];
39
+ const v = [];
40
+ x.each(e => {
41
+ // GRP should be separated as well so we have to perform an additional check.
42
+ if (isLike(e, vars)) {
43
+ v.push(e);
44
+ }
45
+ else {
46
+ coeff.push(e);
47
+ }
48
+ });
49
+ retval = [(0, utils_1.product)(...coeff), (0, utils_1.product)(...v) || (0, shortcuts_1.one)()];
50
+ }
51
+ // E.g. 3*x^2 or 5*(x^2+x) or 4*x^x
52
+ else if (isLike(x, vars)) {
53
+ retval = [Expression_1.Expression.fromRational(x.getMultiplier()), x.toUnitMultiplier()];
54
+ }
55
+ // e.g. 3*b or 6
56
+ else {
57
+ retval = [Expression_1.Expression.create(x), (0, shortcuts_1.one)()];
58
+ }
59
+ return retval;
60
+ }
61
+ /**
62
+ * Gets the coefficients wrt to a given variable
63
+ *
64
+ * @param wrt
65
+ */
66
+ function coeffs(x, variables, coeffsObj, expandExpression = true) {
67
+ const cObj = coeffsObj || new CoeffObject_1.CoeffObject(variables);
68
+ // Complex sums are canonically stored as re + i*im. If the requested variables
69
+ // are inside im, treating i*im as a single coefficient leaves those variables
70
+ // buried inside the coefficient. Split the two components and collect them
71
+ // independently, then restore i on the imaginary coefficients.
72
+ if (x.isComplex() && !variables.includes(Expression_1.Expression.imaginary)) {
73
+ const realCoeffs = coeffs(x.realPart(), variables, undefined, expandExpression);
74
+ const imaginaryCoeffs = coeffs(x.imagPart(), variables, undefined, expandExpression);
75
+ realCoeffs.each((coeff, power) => cObj.add(power, coeff));
76
+ imaginaryCoeffs.each((coeff, power) => cObj.add(power, coeff.times(Expression_1.Expression.Img())));
77
+ return cObj;
78
+ }
79
+ // First sanitize the expression
80
+ if (x.isProduct()) {
81
+ let coefficient = (0, shortcuts_1.one)();
82
+ let product = Expression_1.Expression.fromRational(x.getMultiplier());
83
+ let hasCoefficientFactor = false;
84
+ for (const element of x.elementsArray()) {
85
+ if (element.isSum() && element.getPower().sign() < 0) {
86
+ const dependsOnVariable = variables.some(variable => element.hasVariable(variable));
87
+ if (dependsOnVariable) {
88
+ throw new errors_1.PolynomialError((0, errors_1.message)('notAPolynomial'));
89
+ }
90
+ coefficient = coefficient.times(element);
91
+ hasCoefficientFactor = true;
92
+ }
93
+ else {
94
+ product = product.times(element);
95
+ }
96
+ }
97
+ if (hasCoefficientFactor) {
98
+ const productCoeffs = coeffs(product, variables, undefined, expandExpression);
99
+ productCoeffs.each((value, power) => {
100
+ cObj.add(power, coefficient.times(value));
101
+ });
102
+ return cObj;
103
+ }
104
+ x = product;
105
+ }
106
+ // Expand only when the caller has not already supplied expanded structure.
107
+ const f = expandExpression ? (0, expand_1.expand)(x) : x;
108
+ if (f.isSum()) {
109
+ // Loop through the expression and get the coefficient for each
110
+ f.each(e => {
111
+ coeffs(e, variables, cObj, false);
112
+ });
113
+ }
114
+ else {
115
+ // const [coeff, v] = x.separateVar(...variables);
116
+ const [coeff, v] = separateVar(x, variables);
117
+ // const p = v.getPower().text();
118
+ const powers = variables.map(x => v.getVariable(x).getPower().text());
119
+ // cObj[p] = cObj[p] ? cObj[p].plus(coeff) : coeff;
120
+ cObj.add(powers.join(','), coeff);
121
+ }
122
+ return cObj;
123
+ }
124
+ function getDenominator(x) {
125
+ let retval = Expression_1.Expression.Number(x.getMultiplier().denominator);
126
+ const isProduct = x.isProduct();
127
+ const sign = x.getPower().sign();
128
+ // Using sign === -1 is not a bug since the power gets distributed by default.
129
+ if (sign === -1) {
130
+ retval = retval.times(x.toUnitMultiplier().invert());
131
+ }
132
+ else if (isProduct && x.isLinear()) {
133
+ for (const element of x.elementsArray()) {
134
+ if (element.isProduct()) {
135
+ retval = retval.times(getDenominator(element));
136
+ }
137
+ else if (element.getPower().sign() < 0) {
138
+ retval = retval.times(element.invert());
139
+ // retval = retval.times(element.invert());
140
+ }
141
+ }
142
+ }
143
+ return retval;
144
+ }
145
+ function getNumerator(x) {
146
+ // Initialize with the value of the multiplier's numerator. e.g. (1/2)*x = 1*x as the numerator
147
+ let retval = Expression_1.Expression.Number(x.getMultiplier().numerator);
148
+ const isProduct = x.isProduct();
149
+ const sign = x.getPower().sign();
150
+ // If it's not a product and the sign is positive then we're done e.g. x, (1+x)^2, ...
151
+ if ((!isProduct && sign > 0) || (isProduct && sign > 0 && !x.isLinear())) {
152
+ retval = retval.times(x.toUnitMultiplier());
153
+ }
154
+ // Otherwise, we loop through the product
155
+ else if (isProduct && x.isLinear()) {
156
+ const elements = x.elementsArray();
157
+ for (const e of elements) {
158
+ const num = getNumerator(e);
159
+ retval = retval.times(num);
160
+ }
161
+ }
162
+ return retval;
163
+ } /**
164
+ * Returns true fo polynomial with coefficients in Z or Q.
165
+ * @param x
166
+ * @returns
167
+ */
168
+ function isPolynomialLike(x) {
169
+ const power = x.getPower();
170
+ // Instantly disqualify elements under the denominator, radicals, exponential functions, infinity, ...
171
+ if (!power.isInteger() || power.sign() === -1 || x.isEXP() || x.isFunction() || x.isInf()) {
172
+ return false;
173
+ }
174
+ // Check within nested sums and products
175
+ else if (x.isSum() || x.isProduct()) {
176
+ // Check the elements
177
+ for (const element of x.elementsArray()) {
178
+ if (!isPolynomialLike(element)) {
179
+ return false;
180
+ }
181
+ }
182
+ }
183
+ // Return true for all else x, x^2, etc
184
+ return true;
185
+ }
186
+ function getVariable(x, variable) {
187
+ if (x.value === variable) {
188
+ return x;
189
+ }
190
+ else if (x.isProduct()) {
191
+ const elements = x.getElements();
192
+ for (const x in elements) {
193
+ if (elements[x].value === variable) {
194
+ return elements[x];
195
+ }
196
+ }
197
+ }
198
+ return (0, shortcuts_1.zero)();
199
+ } // Example 1/2*x+3/5*y+2/7*z
200
+ // Returns 1/70 (35 x + 42 y + 20 z)
201
+ function normalizeMultiplierDenominators(x) {
202
+ let retval;
203
+ if (x.isSum()) {
204
+ const distributed = x.distributeMultiplier();
205
+ const terms = distributed.elementsArray();
206
+ const denominators = [];
207
+ for (const term of terms) {
208
+ denominators.push(term.getMultiplier().denominator);
209
+ }
210
+ const denominator = (0, bigint_1.LCM)(...denominators);
211
+ const expression = distributed.times(denominator).distributeMultiplier();
212
+ retval = expression.div(denominator);
213
+ }
214
+ else {
215
+ retval = x;
216
+ }
217
+ return retval;
218
+ }
@@ -0,0 +1,9 @@
1
+ import type { Expression } from './Expression';
2
+ import type { conditionType, actionType } from './utils';
3
+ export declare function collect(x: Expression, condition: conditionType, action: actionType, values?: string[]): string[];
4
+ /**
5
+ * Collects all variables from a set of expressions, sorted alphabetically.
6
+ * @param exprs The array of expression from which the variables will be collect
7
+ * @returns
8
+ */
9
+ export declare function collectVariablesSet(exprs: Expression[]): string[];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collect = collect;
4
+ exports.collectVariablesSet = collectVariablesSet;
5
+ function collect(x, condition, action, values) {
6
+ values ??= [];
7
+ if (condition(x, values)) {
8
+ action(x, values);
9
+ }
10
+ // Apply it to function arguments
11
+ if (x.args) {
12
+ for (const e of x.args) {
13
+ collect(e, condition, action, values);
14
+ }
15
+ }
16
+ // Search the sub-elements
17
+ if (x.elements) {
18
+ for (const e in x.elements) {
19
+ collect(x.elements[e], condition, action, values);
20
+ }
21
+ }
22
+ // Search the power
23
+ if (x.isEXP()) {
24
+ // Check target value. It's difficult to know if it's a variable so the best way is to parse and check.
25
+ // The unfortunate consequence is that we create a reliance on Parser.parse but target is a very tricky
26
+ // issue to solve. Consider (x+1)^x. A link to the previous type can be created but then if it gets
27
+ // raised again (x+1)^x^x then we have two links in which case we're not searching the chain.
28
+ // Is it better to rely on parse? Or a reference to target class and introduce a `searchChain` method for instance.
29
+ collect(x.getBase(), condition, action, values);
30
+ // Check the power
31
+ collect(x.getPower(), condition, action, values);
32
+ }
33
+ return values;
34
+ }
35
+ /**
36
+ * Collects all variables from a set of expressions, sorted alphabetically.
37
+ * @param exprs The array of expression from which the variables will be collect
38
+ * @returns
39
+ */
40
+ function collectVariablesSet(exprs) {
41
+ const varSet = new Set();
42
+ for (const expr of exprs) {
43
+ const v = expr.variables();
44
+ for (const name of v) {
45
+ varSet.add(name);
46
+ }
47
+ }
48
+ return Array.from(varSet).sort();
49
+ }
@@ -0,0 +1,54 @@
1
+ import type { TextOptions } from '../parser/types';
2
+ import type { Expression } from './Expression';
3
+ type ExpressionSortFunction = (a: Expression, b: Expression) => number;
4
+ type ExpressionTextOptions = TextOptions & {
5
+ internalAccessor?: boolean;
6
+ exactScientific?: boolean;
7
+ };
8
+ /**
9
+ * Formats the multiplier string for string output.
10
+ * The multiplier string can be blank, include an *, or be formatted as a decimal or fraction.
11
+ *
12
+ * @param x
13
+ * @param options
14
+ * @returns
15
+ */
16
+ export declare function formatMultiplierString(x: Expression, options?: ExpressionTextOptions): string;
17
+ /**
18
+ * The power string can be blank, include a ^, or be formatted as a decimal or fraction.
19
+ * Since it can be fraction or an expression, it will also determine if brackets are needed.
20
+ *
21
+ * @param x
22
+ * @param options
23
+ * @param powerOperator
24
+ * @returns
25
+ */
26
+ export declare function formatPowerString(x: Expression, options: ExpressionTextOptions | undefined, powerOperator: string): string;
27
+ /**
28
+ * Formats the ordinary no-options text form without creating formatting option objects
29
+ * while descending the expression tree.
30
+ *
31
+ * This routine follows the same default rendering rules as {@link toText}. Calls that
32
+ * request explicit formatting options continue through {@link toText}.
33
+ */
34
+ export declare function toDefaultText(x: Expression, powerOperator: string, sortFunction: ExpressionSortFunction): string;
35
+ /**
36
+ * Formats an expression using the current formatting policy supplied by Expression.
37
+ *
38
+ * @param x
39
+ * @param options
40
+ * @param asId
41
+ * @param powerOperator
42
+ * @param sortFunction
43
+ * @returns
44
+ */
45
+ export declare function toText(x: Expression, options: ExpressionTextOptions | undefined, asId: boolean | undefined, powerOperator: string, sortFunction: ExpressionSortFunction): string;
46
+ export declare function formatExpressionString(x: Expression, options: ExpressionTextOptions | undefined, sortFunction: ExpressionSortFunction): string;
47
+ /**
48
+ * Converts to capital letter e.g. 1=A, 2=B, ..., 100=CV
49
+ *
50
+ * @param n
51
+ * @returns
52
+ */
53
+ export declare function convertToTitle(n: number): string;
54
+ export {};
@@ -0,0 +1,340 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMultiplierString = formatMultiplierString;
4
+ exports.formatPowerString = formatPowerString;
5
+ exports.toDefaultText = toDefaultText;
6
+ exports.toText = toText;
7
+ exports.formatExpressionString = formatExpressionString;
8
+ exports.convertToTitle = convertToTitle;
9
+ const Settings_1 = require("../../Settings");
10
+ const constants_1 = require("../parser/constants");
11
+ const constants_2 = require("../parser/constants");
12
+ const { NUM, FUN, VAR, INF, GRP, EXP, PRD, SUM } = constants_2.EXPRESSION_TYPES;
13
+ /**
14
+ * Formats the multiplier string for string output.
15
+ * The multiplier string can be blank, include an *, or be formatted as a decimal or fraction.
16
+ *
17
+ * @param x
18
+ * @param options
19
+ * @returns
20
+ */
21
+ function formatMultiplierString(x, options) {
22
+ let retval = '';
23
+ const m = x.getMultiplier();
24
+ const mString = m.text(options);
25
+ const isScientific = options?.scientific !== undefined;
26
+ const isUnit = isScientific ? m.isOne() : mString === '1' || mString === '1.0';
27
+ if (!isUnit) {
28
+ retval = mString;
29
+ if (!m.isInteger() && !(m.asDecimal || options?.decimal || options?.scientific)) {
30
+ retval = `(${retval})`;
31
+ }
32
+ // Keep the established display behavior for approximate decimal values that render as -1.0.
33
+ const isMinusUnit = isScientific
34
+ ? m.isMinusOne()
35
+ : mString === '-1' || mString === '-1.0';
36
+ if (isMinusUnit && !options?.wrapPow) {
37
+ retval = '-';
38
+ }
39
+ else {
40
+ retval += '*';
41
+ }
42
+ }
43
+ return retval;
44
+ }
45
+ /**
46
+ * The power string can be blank, include a ^, or be formatted as a decimal or fraction.
47
+ * Since it can be fraction or an expression, it will also determine if brackets are needed.
48
+ *
49
+ * @param x
50
+ * @param options
51
+ * @param powerOperator
52
+ * @returns
53
+ */
54
+ function formatPowerString(x, options, powerOperator) {
55
+ let retval = '';
56
+ const power = x.getPower();
57
+ const powerOptions = {
58
+ ...options,
59
+ exactScientific: true,
60
+ };
61
+ const powerString = power.text(powerOptions);
62
+ if (powerString !== '1' && powerString !== '1.0') {
63
+ retval = powerString;
64
+ // Wrap fractions in brackets
65
+ if (power.dataType === constants_1.RATIONAL && !power.isInteger()) {
66
+ retval = `(${retval})`;
67
+ }
68
+ else {
69
+ const power = x.getPower();
70
+ let needsBrackets = false;
71
+ if (power.type === SUM || power.type === PRD) {
72
+ needsBrackets = true;
73
+ }
74
+ else if (x.type === EXP) {
75
+ if (power.isNUM() && !power.isInteger()) {
76
+ needsBrackets = true;
77
+ }
78
+ else if (!power.isNUM() && !power.getMultiplier().isOne()) {
79
+ needsBrackets = true;
80
+ }
81
+ }
82
+ if (needsBrackets || retval.includes('/')) {
83
+ retval = `(${retval})`;
84
+ }
85
+ }
86
+ if (options?.wrapPow && !retval.startsWith('(')) {
87
+ retval = `(${retval})`;
88
+ }
89
+ retval = `${powerOperator}${retval}`;
90
+ }
91
+ return retval;
92
+ }
93
+ function formatDefaultPowerString(x, powerOperator, sortFunction) {
94
+ let retval = '';
95
+ const power = x.getPower();
96
+ const powerString = toDefaultText(power, powerOperator, sortFunction);
97
+ if (powerString !== '1' && powerString !== '1.0') {
98
+ retval = powerString;
99
+ if (power.dataType === constants_1.RATIONAL && !power.isInteger()) {
100
+ retval = `(${retval})`;
101
+ }
102
+ else {
103
+ let needsBrackets = false;
104
+ if (power.type === SUM || power.type === PRD) {
105
+ needsBrackets = true;
106
+ }
107
+ else if (x.type === EXP) {
108
+ if (power.isNUM() && !power.isInteger()) {
109
+ needsBrackets = true;
110
+ }
111
+ else if (!power.isNUM() && !power.getMultiplier().isOne()) {
112
+ needsBrackets = true;
113
+ }
114
+ }
115
+ if (needsBrackets || retval.includes('/')) {
116
+ retval = `(${retval})`;
117
+ }
118
+ }
119
+ retval = `${powerOperator}${retval}`;
120
+ }
121
+ return retval;
122
+ }
123
+ function formatDefaultExpressionString(x, powerOperator, sortFunction) {
124
+ const glue = x.type === PRD ? '*' : '+';
125
+ const elements = Object.values(x.getElements());
126
+ if (Settings_1.Settings.SORT_TERMS) {
127
+ elements.sort(sortFunction);
128
+ }
129
+ return elements
130
+ .map(element => {
131
+ let value = toDefaultText(element, powerOperator, sortFunction);
132
+ if (x.type === PRD && element.isSum()) {
133
+ value = `(${value})`;
134
+ }
135
+ return value;
136
+ })
137
+ .join(glue)
138
+ .replace('+-', '-');
139
+ }
140
+ /**
141
+ * Formats the ordinary no-options text form without creating formatting option objects
142
+ * while descending the expression tree.
143
+ *
144
+ * This routine follows the same default rendering rules as {@link toText}. Calls that
145
+ * request explicit formatting options continue through {@link toText}.
146
+ */
147
+ function toDefaultText(x, powerOperator, sortFunction) {
148
+ let retval = '';
149
+ if (x.type === NUM) {
150
+ retval = x.getMultiplier().text();
151
+ }
152
+ else {
153
+ const multiplier = formatMultiplierString(x);
154
+ const power = formatDefaultPowerString(x, powerOperator, sortFunction);
155
+ let value;
156
+ switch (x.type) {
157
+ case VAR:
158
+ case INF:
159
+ retval = `${multiplier}${x.value}`;
160
+ break;
161
+ case FUN: {
162
+ if (x.name === constants_1.SYMBOLIC_ACCESSOR) {
163
+ const args = x.getArguments();
164
+ const target = args[0];
165
+ const indices = args.slice(1);
166
+ retval = `${multiplier}${toDefaultText(target, powerOperator, sortFunction)}[${indices
167
+ .map(index => toDefaultText(index, powerOperator, sortFunction))
168
+ .join(', ')}]`;
169
+ }
170
+ else {
171
+ retval = `${multiplier}${x.name || ''}(${x
172
+ .getArguments()
173
+ .map(argument => toDefaultText(argument, powerOperator, sortFunction))
174
+ .join(', ')})`;
175
+ }
176
+ break;
177
+ }
178
+ case GRP:
179
+ case SUM:
180
+ value = formatDefaultExpressionString(x, powerOperator, sortFunction);
181
+ value = multiplier || power ? `(${value})` : value;
182
+ retval = `${multiplier}${value}`;
183
+ break;
184
+ case PRD:
185
+ value = formatDefaultExpressionString(x, powerOperator, sortFunction);
186
+ value = power ? `(${value})` : value;
187
+ retval = `${multiplier}${value}`;
188
+ break;
189
+ case EXP: {
190
+ const arg = x.getBase();
191
+ const p = arg.getPower();
192
+ value = toDefaultText(arg, powerOperator, sortFunction);
193
+ if (arg.elements ||
194
+ value.startsWith('-') ||
195
+ value.includes('/') ||
196
+ !(p.isOne() || p.isZero())) {
197
+ value = `(${value})`;
198
+ }
199
+ retval = `${multiplier}${value}`;
200
+ break;
201
+ }
202
+ }
203
+ retval += power;
204
+ }
205
+ return retval.replace(/\+-/g, '-');
206
+ }
207
+ /**
208
+ * Formats an expression using the current formatting policy supplied by Expression.
209
+ *
210
+ * @param x
211
+ * @param options
212
+ * @param asId
213
+ * @param powerOperator
214
+ * @param sortFunction
215
+ * @returns
216
+ */
217
+ function toText(x, options, asId, powerOperator, sortFunction) {
218
+ options = { ...{ precision: x.precision, scientific: x.scientific }, ...options };
219
+ let retval = '';
220
+ if (x.type === NUM) {
221
+ retval = x.getMultiplier().text(options);
222
+ }
223
+ else {
224
+ // Get the multiplier but don't add it for the top level. Only
225
+ // format sub-elements
226
+ const multiplier = asId && !x.elements ? '' : formatMultiplierString(x, options);
227
+ const power = formatPowerString(x, options, powerOperator);
228
+ let value;
229
+ switch (x.type) {
230
+ case VAR:
231
+ case INF:
232
+ if (options?.wrapPow && power) {
233
+ retval = `${multiplier}(${x.value})`;
234
+ }
235
+ else {
236
+ retval = `${multiplier}${x.value}`;
237
+ }
238
+ break;
239
+ case FUN: {
240
+ // Symbolic access is stored as an ordinary function node so it can participate
241
+ // in Expression logic without allowing Vector or Matrix objects into args.
242
+ if (x.name === constants_1.SYMBOLIC_ACCESSOR) {
243
+ const args = x.getArguments();
244
+ if (options?.internalAccessor) {
245
+ // Evaluation needs a parseable form that cannot be confused with
246
+ // implicit multiplication when the target type is still unknown.
247
+ retval = `${multiplier}${constants_1.SYMBOLIC_ACCESSOR}(${args
248
+ .map(argument => argument.text(options))
249
+ .join(', ')})`;
250
+ }
251
+ else {
252
+ const target = args[0];
253
+ const indices = args.slice(1);
254
+ retval = `${multiplier}${target.text(options)}[${indices
255
+ .map(index => index.text(options))
256
+ .join(', ')}]`;
257
+ }
258
+ }
259
+ else {
260
+ // TODO: See Expression.toFunction for possible refactoring.
261
+ retval = `${multiplier}${x.name || ''}(${x
262
+ .getArguments()
263
+ .map(x => x.text(options))
264
+ .join(', ')})`;
265
+ }
266
+ break;
267
+ }
268
+ case GRP:
269
+ case SUM: {
270
+ value = formatExpressionString(x, options, sortFunction);
271
+ value = multiplier || power ? `(${value})` : value;
272
+ // The value has already been calculated when the values were added
273
+ retval = `${multiplier}${value}`;
274
+ break;
275
+ }
276
+ case PRD: {
277
+ value = formatExpressionString(x, options, sortFunction);
278
+ value = power ? `(${value})` : value;
279
+ retval = `${multiplier}${value}`;
280
+ break;
281
+ }
282
+ case EXP: {
283
+ const arg = x.getBase();
284
+ const p = arg.getPower();
285
+ value = toText(arg, options, undefined, powerOperator, sortFunction);
286
+ // The following cases get brackets.
287
+ // 1 - (x+1)^x
288
+ // 2 - (-x)^x
289
+ // 3 - (2/3)^x
290
+ // 4 - (x^x)^x
291
+ if (options?.wrapPow ||
292
+ arg.elements ||
293
+ value.startsWith('-') ||
294
+ value.includes('/') ||
295
+ !(p.isOne() || p.isZero())) {
296
+ value = `(${value})`;
297
+ }
298
+ retval = `${multiplier}${value}`;
299
+ break;
300
+ }
301
+ }
302
+ retval += power;
303
+ }
304
+ return retval.replace(/\+-/g, '-');
305
+ }
306
+ // export function toTeX(x: Expression, options?: ExpressionTextOptions) {
307
+ // }
308
+ function formatExpressionString(x, options, sortFunction) {
309
+ const glue = x.type === PRD ? '*' : '+';
310
+ const elements = Object.values(x.getElements());
311
+ if (Settings_1.Settings.SORT_TERMS || options?.sort) {
312
+ elements.sort(sortFunction);
313
+ }
314
+ return elements
315
+ .map(e => {
316
+ let value = e.text(options);
317
+ // Wrap it in brackets for certain conditions
318
+ if (x.type === PRD && e.isSum()) {
319
+ value = `(${value})`;
320
+ }
321
+ return value;
322
+ })
323
+ .join(glue)
324
+ .replace('+-', '-');
325
+ }
326
+ /**
327
+ * Converts to capital letter e.g. 1=A, 2=B, ..., 100=CV
328
+ *
329
+ * @param n
330
+ * @returns
331
+ */
332
+ function convertToTitle(n) {
333
+ let result = '';
334
+ while (n > 0) {
335
+ n--;
336
+ result = String.fromCharCode(65 + (n % 26)) + result;
337
+ n = Math.floor(n / 26);
338
+ }
339
+ return result;
340
+ }