nerdamer 1.1.13 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +293 -312
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +7 -0
  5. package/dist/parser.js +2 -0
  6. package/dist/parser.js.LICENSE.txt +7 -0
  7. package/docs-data/parser-functions.json +1960 -0
  8. package/index.d.ts +10 -426
  9. package/output/algebra/adapters.d.ts +33 -0
  10. package/output/algebra/adapters.js +109 -0
  11. package/output/algebra/algorithms/arith.d.ts +84 -0
  12. package/output/algebra/algorithms/arith.js +323 -0
  13. package/output/algebra/algorithms/factor.d.ts +3 -0
  14. package/output/algebra/algorithms/factor.js +5 -0
  15. package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
  16. package/output/algebra/algorithms/factorMultivariate.js +2393 -0
  17. package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
  18. package/output/algebra/algorithms/factorUnivariate.js +1072 -0
  19. package/output/algebra/algorithms/gcd.d.ts +22 -0
  20. package/output/algebra/algorithms/gcd.js +690 -0
  21. package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
  22. package/output/algebra/algorithms/groebnerBase.js +1166 -0
  23. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
  24. package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
  25. package/output/algebra/algorithms/poly.d.ts +228 -0
  26. package/output/algebra/algorithms/poly.js +1299 -0
  27. package/output/algebra/algorithms/rational.d.ts +17 -0
  28. package/output/algebra/algorithms/rational.js +115 -0
  29. package/output/algebra/factor/factor.d.ts +62 -0
  30. package/output/algebra/factor/factor.js +158 -0
  31. package/output/algebra/gcd/gcd.d.ts +29 -0
  32. package/output/algebra/gcd/gcd.js +141 -0
  33. package/output/algebra/groebner.d.ts +21 -0
  34. package/output/algebra/groebner.js +42 -0
  35. package/output/algebra/partfrac.d.ts +19 -0
  36. package/output/algebra/partfrac.js +398 -0
  37. package/output/algebra/polynomialize.d.ts +20 -0
  38. package/output/algebra/polynomialize.js +24 -0
  39. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  40. package/output/algebra/simplify/complexsimp.js +24 -0
  41. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  42. package/output/algebra/simplify/factorCommon.js +136 -0
  43. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  44. package/output/algebra/simplify/funcsimp.js +633 -0
  45. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  46. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  47. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  48. package/output/algebra/simplify/ratsimp.js +140 -0
  49. package/output/algebra/simplify/simplify.d.ts +25 -0
  50. package/output/algebra/simplify/simplify.js +228 -0
  51. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  52. package/output/algebra/simplify/trigreduce.js +424 -0
  53. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  54. package/output/algebra/simplify/trigrewrite.js +156 -0
  55. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  56. package/output/algebra/simplify/trigsimp.js +369 -0
  57. package/output/algebra/simplify/utils.d.ts +32 -0
  58. package/output/algebra/simplify/utils.js +56 -0
  59. package/output/algebra/utils.d.ts +32 -0
  60. package/output/algebra/utils.js +48 -0
  61. package/output/api/advanced.d.ts +7 -0
  62. package/output/api/advanced.js +18 -0
  63. package/output/api/algebra.d.ts +17 -0
  64. package/output/api/algebra.js +32 -0
  65. package/output/api/assumptions.d.ts +4 -0
  66. package/output/api/assumptions.js +11 -0
  67. package/output/api/calculus.d.ts +9 -0
  68. package/output/api/calculus.js +21 -0
  69. package/output/api/core.d.ts +17 -0
  70. package/output/api/core.js +41 -0
  71. package/output/api/debug.d.ts +16 -0
  72. package/output/api/debug.js +23 -0
  73. package/output/api/parser.d.ts +85 -0
  74. package/output/api/parser.js +16 -0
  75. package/output/api/solve.d.ts +10 -0
  76. package/output/api/solve.js +16 -0
  77. package/output/api/structures.d.ts +10 -0
  78. package/output/api/structures.js +22 -0
  79. package/output/calculus/derivative/diff.d.ts +30 -0
  80. package/output/calculus/derivative/diff.js +238 -0
  81. package/output/calculus/fresnel.d.ts +16 -0
  82. package/output/calculus/fresnel.js +39 -0
  83. package/output/calculus/integrate/byParts.d.ts +18 -0
  84. package/output/calculus/integrate/byParts.js +339 -0
  85. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  86. package/output/calculus/integrate/bySubstitution.js +411 -0
  87. package/output/calculus/integrate/integrate.d.ts +38 -0
  88. package/output/calculus/integrate/integrate.js +652 -0
  89. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  90. package/output/calculus/integrate/integrationTable.js +914 -0
  91. package/output/calculus/integrate/utils.d.ts +28 -0
  92. package/output/calculus/integrate/utils.js +96 -0
  93. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  94. package/output/calculus/laplace/ilaplace.js +192 -0
  95. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  96. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  97. package/output/calculus/laplace/laplace.d.ts +22 -0
  98. package/output/calculus/laplace/laplace.js +109 -0
  99. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  100. package/output/calculus/laplace/laplaceTable.js +187 -0
  101. package/output/calculus/limit/limit.d.ts +35 -0
  102. package/output/calculus/limit/limit.js +1183 -0
  103. package/output/calculus/limit/limitsTable.d.ts +2 -0
  104. package/output/calculus/limit/limitsTable.js +7 -0
  105. package/output/core/Settings.d.ts +32 -0
  106. package/output/core/Settings.js +68 -0
  107. package/output/core/adapters.d.ts +18 -0
  108. package/output/core/adapters.js +40 -0
  109. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  110. package/output/core/classes/assumption/Assumption.js +605 -0
  111. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  112. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  113. package/output/core/classes/assumption/assume.d.ts +90 -0
  114. package/output/core/classes/assumption/assume.js +145 -0
  115. package/output/core/classes/collection/Collection.d.ts +107 -0
  116. package/output/core/classes/collection/Collection.js +231 -0
  117. package/output/core/classes/complex/Complex.d.ts +99 -0
  118. package/output/core/classes/complex/Complex.js +135 -0
  119. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  120. package/output/core/classes/decimalSet/DecimalSet.js +453 -0
  121. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  122. package/output/core/classes/dictionary/Dictionary.js +213 -0
  123. package/output/core/classes/equation/Equation.d.ts +256 -0
  124. package/output/core/classes/equation/Equation.js +350 -0
  125. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  126. package/output/core/classes/expression/CoeffObject.js +198 -0
  127. package/output/core/classes/expression/Expression.d.ts +1674 -0
  128. package/output/core/classes/expression/Expression.js +2332 -0
  129. package/output/core/classes/expression/analysis.d.ts +25 -0
  130. package/output/core/classes/expression/analysis.js +218 -0
  131. package/output/core/classes/expression/collect.d.ts +9 -0
  132. package/output/core/classes/expression/collect.js +49 -0
  133. package/output/core/classes/expression/format.d.ts +45 -0
  134. package/output/core/classes/expression/format.js +217 -0
  135. package/output/core/classes/expression/products.d.ts +23 -0
  136. package/output/core/classes/expression/products.js +115 -0
  137. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  138. package/output/core/classes/expression/shortcuts.js +129 -0
  139. package/output/core/classes/expression/traversal.d.ts +31 -0
  140. package/output/core/classes/expression/traversal.js +216 -0
  141. package/output/core/classes/expression/trig.d.ts +25 -0
  142. package/output/core/classes/expression/trig.js +40 -0
  143. package/output/core/classes/expression/utils.d.ts +52 -0
  144. package/output/core/classes/expression/utils.js +189 -0
  145. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  146. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  147. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  148. package/output/core/classes/matrix/Matrix.js +889 -0
  149. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  150. package/output/core/classes/matrix/Sylvester.js +54 -0
  151. package/output/core/classes/matrix/functions.d.ts +26 -0
  152. package/output/core/classes/matrix/functions.js +52 -0
  153. package/output/core/classes/matrix/utils.d.ts +9 -0
  154. package/output/core/classes/matrix/utils.js +22 -0
  155. package/output/core/classes/parser/Parser.d.ts +480 -0
  156. package/output/core/classes/parser/Parser.js +1812 -0
  157. package/output/core/classes/parser/Token.d.ts +58 -0
  158. package/output/core/classes/parser/Token.js +137 -0
  159. package/output/core/classes/parser/constants.d.ts +160 -0
  160. package/output/core/classes/parser/constants.js +227 -0
  161. package/output/core/classes/parser/helpers.d.ts +21 -0
  162. package/output/core/classes/parser/helpers.js +42 -0
  163. package/output/core/classes/parser/operations/add.d.ts +15 -0
  164. package/output/core/classes/parser/operations/add.js +238 -0
  165. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  166. package/output/core/classes/parser/operations/comma.js +11 -0
  167. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  168. package/output/core/classes/parser/operations/compare.js +461 -0
  169. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  170. package/output/core/classes/parser/operations/divide.js +72 -0
  171. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  172. package/output/core/classes/parser/operations/functions.js +430 -0
  173. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  174. package/output/core/classes/parser/operations/multiply.js +321 -0
  175. package/output/core/classes/parser/operations/power.d.ts +48 -0
  176. package/output/core/classes/parser/operations/power.js +673 -0
  177. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  178. package/output/core/classes/parser/operations/subtract.js +35 -0
  179. package/output/core/classes/parser/preprocess.d.ts +14 -0
  180. package/output/core/classes/parser/preprocess.js +259 -0
  181. package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
  182. package/output/core/classes/parser/scripting/controlFlow.js +355 -0
  183. package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
  184. package/output/core/classes/parser/scripting/evaluate.js +112 -0
  185. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  186. package/output/core/classes/parser/scripting/functions.js +59 -0
  187. package/output/core/classes/parser/scripting/scope.d.ts +35 -0
  188. package/output/core/classes/parser/scripting/scope.js +155 -0
  189. package/output/core/classes/parser/types.d.ts +125 -0
  190. package/output/core/classes/parser/types.js +2 -0
  191. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  192. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  193. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  194. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  195. package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
  196. package/output/core/classes/polynomial/Polynomial.js +1149 -0
  197. package/output/core/classes/polynomial/Term.d.ts +222 -0
  198. package/output/core/classes/polynomial/Term.js +430 -0
  199. package/output/core/classes/polynomial/functions.d.ts +69 -0
  200. package/output/core/classes/polynomial/functions.js +126 -0
  201. package/output/core/classes/polynomial/utils.d.ts +62 -0
  202. package/output/core/classes/polynomial/utils.js +206 -0
  203. package/output/core/classes/rational/Rational.d.ts +504 -0
  204. package/output/core/classes/rational/Rational.js +779 -0
  205. package/output/core/classes/seq/SEQ.d.ts +13 -0
  206. package/output/core/classes/seq/SEQ.js +137 -0
  207. package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
  208. package/output/core/classes/valuesSet/ValuesSet.js +381 -0
  209. package/output/core/classes/vector/Vector.d.ts +222 -0
  210. package/output/core/classes/vector/Vector.js +497 -0
  211. package/output/core/classes/vector/functions.d.ts +28 -0
  212. package/output/core/classes/vector/functions.js +47 -0
  213. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  214. package/output/core/common/classes/MathematicalAggregate.js +140 -0
  215. package/output/core/common/classes/Scope.d.ts +62 -0
  216. package/output/core/common/classes/Scope.js +122 -0
  217. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  218. package/output/core/common/classes/StructuredEntity.js +151 -0
  219. package/output/core/common/common.d.ts +63 -0
  220. package/output/core/common/common.js +279 -0
  221. package/output/core/common/functions/functions.d.ts +14 -0
  222. package/output/core/common/functions/functions.js +33 -0
  223. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  224. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  225. package/output/core/converters/BaseConverter.d.ts +97 -0
  226. package/output/core/converters/BaseConverter.js +405 -0
  227. package/output/core/converters/Converter.d.ts +111 -0
  228. package/output/core/converters/Converter.js +802 -0
  229. package/output/core/converters/Pattern.d.ts +71 -0
  230. package/output/core/converters/Pattern.js +302 -0
  231. package/output/core/dispatch.d.ts +34 -0
  232. package/output/core/dispatch.js +304 -0
  233. package/output/core/errors.d.ts +531 -0
  234. package/output/core/errors.js +621 -0
  235. package/output/core/functions/bigint/bigint.d.ts +121 -0
  236. package/output/core/functions/bigint/bigint.js +392 -0
  237. package/output/core/functions/bigint/primeFactor.d.ts +49 -0
  238. package/output/core/functions/bigint/primeFactor.js +267 -0
  239. package/output/core/functions/bigint/primes.d.ts +1 -0
  240. package/output/core/functions/bigint/primes.js +11 -0
  241. package/output/core/functions/build/definitions.d.ts +12 -0
  242. package/output/core/functions/build/definitions.js +133 -0
  243. package/output/core/functions/build/index.d.ts +32 -0
  244. package/output/core/functions/build/index.js +136 -0
  245. package/output/core/functions/complex.d.ts +90 -0
  246. package/output/core/functions/complex.js +482 -0
  247. package/output/core/functions/decimal.d.ts +24 -0
  248. package/output/core/functions/decimal.js +664 -0
  249. package/output/core/functions/expand/expand.d.ts +42 -0
  250. package/output/core/functions/expand/expand.js +376 -0
  251. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  252. package/output/core/functions/fresnelNumeric.js +123 -0
  253. package/output/core/functions/numeric.d.ts +140 -0
  254. package/output/core/functions/numeric.js +790 -0
  255. package/output/core/functions/rationalNormalization.d.ts +11 -0
  256. package/output/core/functions/rationalNormalization.js +117 -0
  257. package/output/core/functions/setFunction.d.ts +19 -0
  258. package/output/core/functions/setFunction.js +75 -0
  259. package/output/core/functions/string.d.ts +26 -0
  260. package/output/core/functions/string.js +101 -0
  261. package/output/core/functions/subst.d.ts +90 -0
  262. package/output/core/functions/subst.js +498 -0
  263. package/output/core/functions/utils.d.ts +24 -0
  264. package/output/core/functions/utils.js +51 -0
  265. package/output/core/types.d.ts +48 -0
  266. package/output/core/types.js +2 -0
  267. package/output/index.d.ts +339 -0
  268. package/output/index.js +715 -0
  269. package/output/math/defint/defintDecimal.d.ts +37 -0
  270. package/output/math/defint/defintDecimal.js +320 -0
  271. package/output/math/defint/defintNative.d.ts +57 -0
  272. package/output/math/defint/defintNative.js +292 -0
  273. package/output/math/geometry.d.ts +8 -0
  274. package/output/math/geometry.js +32 -0
  275. package/output/math/math.d.ts +655 -0
  276. package/output/math/math.js +1811 -0
  277. package/output/math/trig.d.ts +518 -0
  278. package/output/math/trig.js +1444 -0
  279. package/output/math/trunc.d.ts +19 -0
  280. package/output/math/trunc.js +36 -0
  281. package/output/math/utils.d.ts +60 -0
  282. package/output/math/utils.js +180 -0
  283. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  284. package/output/solve/classes/DecimalMatrix.js +86 -0
  285. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  286. package/output/solve/classes/FunctionSolver.js +433 -0
  287. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  288. package/output/solve/classes/MultivariateSolver.js +240 -0
  289. package/output/solve/classes/PolynomialSolver.d.ts +85 -0
  290. package/output/solve/classes/PolynomialSolver.js +292 -0
  291. package/output/solve/classes/SolutionSet.d.ts +153 -0
  292. package/output/solve/classes/SolutionSet.js +357 -0
  293. package/output/solve/classes/Solver.d.ts +17 -0
  294. package/output/solve/classes/Solver.js +132 -0
  295. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  296. package/output/solve/classes/SymbolicSolver.js +601 -0
  297. package/output/solve/linsolve.d.ts +51 -0
  298. package/output/solve/linsolve.js +225 -0
  299. package/output/solve/solve.d.ts +34 -0
  300. package/output/solve/solve.js +260 -0
  301. package/output/solve/solveSystem.d.ts +31 -0
  302. package/output/solve/solveSystem.js +290 -0
  303. package/output/solve/utils.d.ts +9 -0
  304. package/output/solve/utils.js +62 -0
  305. package/output/utils/array.d.ts +42 -0
  306. package/output/utils/array.js +98 -0
  307. package/output/utils/debug.d.ts +131 -0
  308. package/output/utils/debug.js +295 -0
  309. package/output/utils/decimal.d.ts +3 -0
  310. package/output/utils/decimal.js +16 -0
  311. package/output/utils/numeric.d.ts +14 -0
  312. package/output/utils/numeric.js +51 -0
  313. package/output/utils/object.d.ts +26 -0
  314. package/output/utils/object.js +56 -0
  315. package/package.json +213 -57
  316. package/.travis.yml +0 -3
  317. package/Algebra.js +0 -4568
  318. package/BREAKING_CHANGES.md +0 -5
  319. package/CODE_OF_CONDUCT.md +0 -46
  320. package/CONTRIBUTING.md +0 -14
  321. package/Calculus.js +0 -2675
  322. package/Extra.js +0 -622
  323. package/Solve.js +0 -1783
  324. package/all.js +0 -16
  325. package/all.min.js +0 -1
  326. package/gulpfile.js +0 -16
  327. package/index.html +0 -158
  328. package/license.txt +0 -19
  329. package/nerdamer.core.js +0 -12510
  330. package/spec/LaTeX.spec.js +0 -302
  331. package/spec/TeXConvert.spec.js +0 -8
  332. package/spec/algebra.spec.js +0 -287
  333. package/spec/basic_parser.spec.js +0 -134
  334. package/spec/build.spec.js +0 -131
  335. package/spec/calculus.spec.js +0 -183
  336. package/spec/core.spec.js +0 -2970
  337. package/spec/extra.spec.js +0 -54
  338. package/spec/solve.spec.js +0 -126
  339. package/spec/support/jasmine.json +0 -11
  340. package/spec/support/utils.js +0 -42
  341. package/spec/text.spec.js +0 -132
@@ -0,0 +1,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): 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) {
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);
74
+ const imaginaryCoeffs = coeffs(x.imagPart(), variables);
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);
99
+ productCoeffs.each((value, power) => {
100
+ cObj.add(power, coefficient.times(value));
101
+ });
102
+ return cObj;
103
+ }
104
+ x = product;
105
+ }
106
+ // Expand the expression
107
+ const f = (0, expand_1.expand)(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);
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,45 @@
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
+ };
7
+ /**
8
+ * Formats the multiplier string for string output.
9
+ * The multiplier string can be blank, include an *, or be formatted as a decimal or fraction.
10
+ *
11
+ * @param x
12
+ * @param options
13
+ * @returns
14
+ */
15
+ export declare function formatMultiplierString(x: Expression, options?: ExpressionTextOptions): string;
16
+ /**
17
+ * The power string can be blank, include a ^, or be formatted as a decimal or fraction.
18
+ * Since it can be fraction or an expression, it will also determine if brackets are needed.
19
+ *
20
+ * @param x
21
+ * @param options
22
+ * @param powerOperator
23
+ * @returns
24
+ */
25
+ export declare function formatPowerString(x: Expression, options: ExpressionTextOptions | undefined, powerOperator: string): string;
26
+ /**
27
+ * Formats an expression using the current formatting policy supplied by Expression.
28
+ *
29
+ * @param x
30
+ * @param options
31
+ * @param asId
32
+ * @param powerOperator
33
+ * @param sortFunction
34
+ * @returns
35
+ */
36
+ export declare function toText(x: Expression, options: ExpressionTextOptions | undefined, asId: boolean | undefined, powerOperator: string, sortFunction: ExpressionSortFunction): string;
37
+ export declare function formatExpressionString(x: Expression, options: ExpressionTextOptions | undefined, sortFunction: ExpressionSortFunction): string;
38
+ /**
39
+ * Converts to capital letter e.g. 1=A, 2=B, ..., 100=CV
40
+ *
41
+ * @param n
42
+ * @returns
43
+ */
44
+ export declare function convertToTitle(n: number): string;
45
+ export {};
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMultiplierString = formatMultiplierString;
4
+ exports.formatPowerString = formatPowerString;
5
+ exports.toText = toText;
6
+ exports.formatExpressionString = formatExpressionString;
7
+ exports.convertToTitle = convertToTitle;
8
+ const Settings_1 = require("../../Settings");
9
+ const constants_1 = require("../parser/constants");
10
+ const constants_2 = require("../parser/constants");
11
+ const { NUM, FUN, VAR, INF, GRP, EXP, PRD, SUM } = constants_2.EXPRESSION_TYPES;
12
+ /**
13
+ * Formats the multiplier string for string output.
14
+ * The multiplier string can be blank, include an *, or be formatted as a decimal or fraction.
15
+ *
16
+ * @param x
17
+ * @param options
18
+ * @returns
19
+ */
20
+ function formatMultiplierString(x, options) {
21
+ let retval = '';
22
+ const m = x.getMultiplier();
23
+ const mString = m.text(options);
24
+ if (mString !== '1' && mString !== '1.0') {
25
+ retval = mString;
26
+ if (!m.isInteger() && !(m.asDecimal || options?.decimal)) {
27
+ retval = `(${retval})`;
28
+ }
29
+ // Don't show the minus one as -1* but just -
30
+ // When wrapPow is set, keep -1* to avoid unary minus before **
31
+ if (retval === '-1' && !options?.wrapPow) {
32
+ retval = '-';
33
+ }
34
+ else {
35
+ retval += '*';
36
+ }
37
+ }
38
+ return retval;
39
+ }
40
+ /**
41
+ * The power string can be blank, include a ^, or be formatted as a decimal or fraction.
42
+ * Since it can be fraction or an expression, it will also determine if brackets are needed.
43
+ *
44
+ * @param x
45
+ * @param options
46
+ * @param powerOperator
47
+ * @returns
48
+ */
49
+ function formatPowerString(x, options, powerOperator) {
50
+ let retval = '';
51
+ const power = x.getPower();
52
+ const powerString = power.text(options);
53
+ if (powerString !== '1' && powerString !== '1.0') {
54
+ retval = powerString;
55
+ // Wrap fractions in brackets
56
+ if (power.dataType === constants_1.RATIONAL && !power.isInteger()) {
57
+ retval = `(${retval})`;
58
+ }
59
+ else {
60
+ const power = x.getPower();
61
+ let needsBrackets = false;
62
+ if (power.type === SUM || power.type === PRD) {
63
+ needsBrackets = true;
64
+ }
65
+ else if (x.type === EXP) {
66
+ if (power.isNUM() && !power.isInteger()) {
67
+ needsBrackets = true;
68
+ }
69
+ else if (!power.isNUM() && !power.getMultiplier().isOne()) {
70
+ needsBrackets = true;
71
+ }
72
+ }
73
+ if (needsBrackets || retval.includes('/')) {
74
+ retval = `(${retval})`;
75
+ }
76
+ }
77
+ if (options?.wrapPow && !retval.startsWith('(')) {
78
+ retval = `(${retval})`;
79
+ }
80
+ retval = `${powerOperator}${retval}`;
81
+ }
82
+ return retval;
83
+ }
84
+ /**
85
+ * Formats an expression using the current formatting policy supplied by Expression.
86
+ *
87
+ * @param x
88
+ * @param options
89
+ * @param asId
90
+ * @param powerOperator
91
+ * @param sortFunction
92
+ * @returns
93
+ */
94
+ function toText(x, options, asId, powerOperator, sortFunction) {
95
+ options = { ...{ precision: x.precision }, ...options };
96
+ let retval = '';
97
+ if (x.type === NUM) {
98
+ retval = x.getMultiplier().text(options);
99
+ }
100
+ else {
101
+ // Get the multiplier but don't add it for the top level. Only
102
+ // format sub-elements
103
+ const multiplier = asId && !x.elements ? '' : formatMultiplierString(x, options);
104
+ const power = formatPowerString(x, options, powerOperator);
105
+ let value;
106
+ switch (x.type) {
107
+ case VAR:
108
+ case INF:
109
+ if (options?.wrapPow && power) {
110
+ retval = `${multiplier}(${x.value})`;
111
+ }
112
+ else {
113
+ retval = `${multiplier}${x.value}`;
114
+ }
115
+ break;
116
+ case FUN: {
117
+ // Symbolic access is stored as an ordinary function node so it can participate
118
+ // in Expression logic without allowing Vector or Matrix objects into args.
119
+ if (x.name === constants_1.SYMBOLIC_ACCESSOR) {
120
+ const args = x.getArguments();
121
+ if (options?.internalAccessor) {
122
+ // Evaluation needs a parseable form that cannot be confused with
123
+ // implicit multiplication when the target type is still unknown.
124
+ retval = `${multiplier}${constants_1.SYMBOLIC_ACCESSOR}(${args
125
+ .map(argument => argument.text(options))
126
+ .join(', ')})`;
127
+ }
128
+ else {
129
+ const target = args[0];
130
+ const indices = args.slice(1);
131
+ retval = `${multiplier}${target.text(options)}[${indices
132
+ .map(index => index.text(options))
133
+ .join(', ')}]`;
134
+ }
135
+ }
136
+ else {
137
+ // TODO: See Expression.toFunction for possible refactoring.
138
+ retval = `${multiplier}${x.name || ''}(${x
139
+ .getArguments()
140
+ .map(x => x.text(options))
141
+ .join(', ')})`;
142
+ }
143
+ break;
144
+ }
145
+ case GRP:
146
+ case SUM: {
147
+ value = formatExpressionString(x, options, sortFunction);
148
+ value = multiplier || power ? `(${value})` : value;
149
+ // The value has already been calculated when the values were added
150
+ retval = `${multiplier}${value}`;
151
+ break;
152
+ }
153
+ case PRD: {
154
+ value = formatExpressionString(x, options, sortFunction);
155
+ value = power ? `(${value})` : value;
156
+ retval = `${multiplier}${value}`;
157
+ break;
158
+ }
159
+ case EXP: {
160
+ const arg = x.getBase();
161
+ const p = arg.getPower();
162
+ value = toText(arg, options, undefined, powerOperator, sortFunction);
163
+ // The following cases get brackets.
164
+ // 1 - (x+1)^x
165
+ // 2 - (-x)^x
166
+ // 3 - (2/3)^x
167
+ // 4 - (x^x)^x
168
+ if (options?.wrapPow ||
169
+ arg.elements ||
170
+ value.startsWith('-') ||
171
+ value.includes('/') ||
172
+ !(p.isOne() || p.isZero())) {
173
+ value = `(${value})`;
174
+ }
175
+ retval = `${multiplier}${value}`;
176
+ break;
177
+ }
178
+ }
179
+ retval += power;
180
+ }
181
+ return retval.replace(/\+-/g, '-');
182
+ }
183
+ // export function toTeX(x: Expression, options?: ExpressionTextOptions) {
184
+ // }
185
+ function formatExpressionString(x, options, sortFunction) {
186
+ const glue = x.type === PRD ? '*' : '+';
187
+ const elements = Object.values(x.getElements());
188
+ if (Settings_1.Settings.SORT_TERMS || options?.sort) {
189
+ elements.sort(sortFunction);
190
+ }
191
+ return elements
192
+ .map(e => {
193
+ let value = e.text(options);
194
+ // Wrap it in brackets for certain conditions
195
+ if (x.type === PRD && e.isSum()) {
196
+ value = `(${value})`;
197
+ }
198
+ return value;
199
+ })
200
+ .join(glue)
201
+ .replace('+-', '-');
202
+ }
203
+ /**
204
+ * Converts to capital letter e.g. 1=A, 2=B, ..., 100=CV
205
+ *
206
+ * @param n
207
+ * @returns
208
+ */
209
+ function convertToTitle(n) {
210
+ let result = '';
211
+ while (n > 0) {
212
+ n--;
213
+ result = String.fromCharCode(65 + (n % 26)) + result;
214
+ n = Math.floor(n / 26);
215
+ }
216
+ return result;
217
+ }
@@ -0,0 +1,23 @@
1
+ import type { Expression } from './Expression';
2
+ /**
3
+ * Similar to hasVariable but is extended to products
4
+ *
5
+ * @param x
6
+ * @param y
7
+ */
8
+ export declare function contains(x: Expression, y: Expression): boolean; /**
9
+ * Removes the multiplier and constants wrt to a given variable
10
+ * @param expression
11
+ * @param wrtVariable
12
+ */
13
+ export declare function constantsFreeProduct(expression: Expression, wrtVariable: string): {
14
+ constants: Expression;
15
+ expression: Expression;
16
+ };
17
+ /**
18
+ * Splits a product into its factors e.g. a^2*b^3 will return [a, a, b, b, b]
19
+ * @param f
20
+ * @param factors
21
+ * @returns
22
+ */
23
+ export declare function splitProductFactors(f: Expression, factors?: Expression[]): Expression[];