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,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.product = product;
4
+ exports.sum = sum;
5
+ exports.stripPower = stripPower;
6
+ exports.copyOver = copyOver;
7
+ exports.toArrays = toArrays;
8
+ exports.largestPower = largestPower;
9
+ exports.assertPlainVariableAndGetString = assertPlainVariableAndGetString;
10
+ exports.getNumericOrAssumedValue = getNumericOrAssumedValue;
11
+ const errors_1 = require("../../errors");
12
+ const assume_1 = require("../assumption/assume");
13
+ const Rational_1 = require("../rational/Rational");
14
+ const Expression_1 = require("./Expression");
15
+ const shortcuts_1 = require("./shortcuts");
16
+ /** Multiplies a series of Expressions into one product. */
17
+ function product(...args) {
18
+ let retval = (0, shortcuts_1.one)();
19
+ for (const x of args) {
20
+ retval = retval.times(x);
21
+ }
22
+ return retval;
23
+ }
24
+ /** Adds a series of Expressions into one sum. */
25
+ function sum(...args) {
26
+ let retval = (0, shortcuts_1.zero)();
27
+ for (const x of args) {
28
+ retval = retval.plus(x);
29
+ }
30
+ return retval;
31
+ }
32
+ /** Removes the power from an Expression. The original object is unchanged. */
33
+ function stripPower(x) {
34
+ const retval = x.copy();
35
+ delete retval.power;
36
+ return retval;
37
+ }
38
+ /**
39
+ * Copies over all the properties of the provided symbolic essentially cloning it to x.
40
+ *
41
+ * @param sym
42
+ * @returns
43
+ */
44
+ function copyOver(src, target, options) {
45
+ options = {
46
+ ...{ omitMultiplier: false, omitPower: false },
47
+ ...options,
48
+ };
49
+ // Copy over the multiplier
50
+ if (src.multiplier && !options.omitMultiplier) {
51
+ target.multiplier = Rational_1.Rational.makeCopy(src.multiplier);
52
+ }
53
+ // toFunctions have name so we need those copied
54
+ if (src.name !== undefined) {
55
+ target.name = src.name;
56
+ }
57
+ // Copy over the power
58
+ if (src.power && !options.omitPower) {
59
+ target.power = Expression_1.Expression.create(src.power, undefined, true);
60
+ }
61
+ // Copy over the args if any
62
+ if (src.args) {
63
+ target.args = [];
64
+ for (const arg of src.args) {
65
+ target.args.push(Expression_1.Expression.create(arg, undefined, true));
66
+ }
67
+ }
68
+ // Copy over the base if an
69
+ if (src.base) {
70
+ target.base = src.base.copy();
71
+ }
72
+ // Copy over the elements if any
73
+ if (src.elements) {
74
+ target.elements = {};
75
+ for (const x in src.elements) {
76
+ target.elements[x] = Expression_1.Expression.create(src.elements[x], undefined, true);
77
+ }
78
+ }
79
+ // Last but not least
80
+ target.type = src.type;
81
+ target.value = src.value;
82
+ target.precision = src.precision;
83
+ target.deferred = src.deferred;
84
+ return target;
85
+ }
86
+ /**
87
+ * This function converts the expression in a collection of arrays
88
+ *
89
+ * @param x
90
+ * @param arrayObj
91
+ * @returns
92
+ */
93
+ function toArrays(x, arrayObj) {
94
+ /*
95
+ * The first thing to realize is that only PRD elements can have a numerator and denominators.
96
+ * All others are either the numerator or the denominator. To illustrate let look at some examples:
97
+ * x^2/4 => x^2/4
98
+ * cos(x)^(1/3) => cos(x)^(1/3)
99
+ * 5*x^-1+(5/6)*x^3+x => (5*x^3)/6+x+5/x
100
+ * (x+1)/(x+5) => (x+1)/(x+5)
101
+ * Out of all the examples, the only one with symbolic values in the denominator is the last one which is of type PRD.
102
+ * We can now simplify the problem by only focusing on PRD elements for symbolic denominators
103
+ */
104
+ const retval = arrayObj || {
105
+ num: [],
106
+ den: [],
107
+ };
108
+ function addMultiplier(m) {
109
+ retval.num.push(Expression_1.Expression.Number(m.numerator));
110
+ // Only add the denominator if it's not one
111
+ if (m.denominator !== 1n) {
112
+ retval.den.push(Expression_1.Expression.Number(m.denominator));
113
+ }
114
+ }
115
+ if (x.isNUM()) {
116
+ addMultiplier(x.getMultiplier());
117
+ }
118
+ else {
119
+ addMultiplier(x.getMultiplier());
120
+ const power = x.getPower();
121
+ // Handle products. Their elements should be distributed over the numerator and denominator
122
+ // Consider 2*x*y/(a*b). The desired output is { num: [2, y, y], den: [a, b]}
123
+ if (x.isProduct()) {
124
+ const elements = x.elementsArray();
125
+ for (const element of elements) {
126
+ // Pass in this object so they're added to the numerator or the denominator of this retval object
127
+ toArrays(element, retval);
128
+ }
129
+ }
130
+ // Consider 2/3*x. The desired output is { num: [2, x], den [3] };
131
+ // Consider (3*y)^(2/3). The desired output = { num: [3, y], den: [], power: { num: [2], den: [3]} };
132
+ else {
133
+ const term = stripPower(x.toUnitMultiplier());
134
+ // Put it in numerator if positive power else the denominator
135
+ const target = power.getMultiplier().isNegative() ? retval.den : retval.num;
136
+ target.push(term);
137
+ }
138
+ // Handle the power. Remember that x^(-2) is now 1/x^2 so the power has to be the absolute value
139
+ retval.power = toArrays(power.abs());
140
+ // Handle args
141
+ // Consider cos(2*pi). The desired output = { name: 'cos', args[{ num: [2, pi], den: [] }] }
142
+ if (x.args) {
143
+ retval.args = x.getArguments().map(x => {
144
+ return toArrays(x);
145
+ });
146
+ }
147
+ }
148
+ return retval;
149
+ }
150
+ /**
151
+ * Gets the max between two or more Expressions. Just know that if two variable arguments are provided,
152
+ * it will not be able to know with any certainty which is bigger so the first one will be returned.
153
+ *
154
+ * @param x
155
+ * @param args
156
+ * @returns
157
+ */
158
+ function largestPower(x, ...args) {
159
+ let retval = x;
160
+ for (const y of args) {
161
+ if (y.getPower().gt(retval.getPower())) {
162
+ retval = y;
163
+ }
164
+ }
165
+ return retval;
166
+ }
167
+ function assertPlainVariableAndGetString(x) {
168
+ if (!x.isVAR()) {
169
+ throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: x.text() }));
170
+ }
171
+ return x.value;
172
+ }
173
+ function getNumericOrAssumedValue(x) {
174
+ let retval = undefined;
175
+ // If it's numeric then we're done
176
+ if (x.isNUM()) {
177
+ retval = x;
178
+ }
179
+ else {
180
+ // Check the assumptions
181
+ const assumedValue = (0, assume_1.getAssumptionFor)(x);
182
+ // Make sure it's a single value. Since this is used for comparison,
183
+ // we cannot compare a point to a range.
184
+ if (assumedValue && assumedValue.isSingleton) {
185
+ retval = assumedValue.getSingletonValue();
186
+ }
187
+ }
188
+ return retval;
189
+ }
@@ -0,0 +1,12 @@
1
+ import type { Pattern } from '../../converters/Pattern';
2
+ import type { Expression } from '../expression/Expression';
3
+ export type TableEntryHandler = (f: Pattern, depth?: number) => Expression | undefined;
4
+ export type TableEntries = Record<string, TableEntryHandler>;
5
+ export declare class LookupTable {
6
+ private _entries;
7
+ private addEntry;
8
+ private get;
9
+ addEntries(table: TableEntries): void;
10
+ lookup(pattern: Pattern, depth?: number): Expression | undefined;
11
+ set(pattern: string, handler: TableEntryHandler): boolean;
12
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LookupTable = void 0;
4
+ class LookupTable {
5
+ _entries = new Map();
6
+ addEntry(pattern, handler) {
7
+ // Check if there's an existing entry
8
+ const existingEntry = this._entries.get(pattern);
9
+ // If not then just add it
10
+ if (!existingEntry) {
11
+ this._entries.set(pattern, [handler]);
12
+ }
13
+ // Add the handler if there's an existing entry
14
+ else {
15
+ existingEntry.push(handler);
16
+ }
17
+ }
18
+ get(pattern) {
19
+ return this._entries.get(pattern);
20
+ }
21
+ addEntries(table) {
22
+ for (const pattern in table) {
23
+ // Get the handler in the table
24
+ const handler = table[pattern];
25
+ this.addEntry(pattern, handler);
26
+ }
27
+ }
28
+ lookup(pattern, depth) {
29
+ // Get the handlers
30
+ const handlers = this.get(pattern.patternString);
31
+ // console.log('Looking up\n');
32
+ // console.log(
33
+ // `pattern: ${pattern.patternString}, expression: ${pattern.expression}, handler found: ${handlers ? handlers.length : 'none'}\n`
34
+ // );
35
+ if (handlers) {
36
+ // If there are handlers then try each one until a match is found.
37
+ for (const handler of handlers) {
38
+ const result = handler(pattern, depth);
39
+ if (result) {
40
+ return result;
41
+ }
42
+ }
43
+ }
44
+ return undefined;
45
+ }
46
+ set(pattern, handler) {
47
+ const handlers = this._entries.get(pattern);
48
+ if (handler) {
49
+ handlers?.push(handler);
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+ }
55
+ exports.LookupTable = LookupTable;
@@ -0,0 +1,227 @@
1
+ import { StructuredEntity } from '../../common/classes/StructuredEntity';
2
+ import { Expression } from '../expression/Expression';
3
+ import { MATRIX } from '../parser/constants';
4
+ import { Vector } from '../vector/Vector';
5
+ import type { StructuredEntityType, ParserEntity, NerdamerInput } from '../../types';
6
+ import type { ParserValuesObject } from '../parser/types';
7
+ /**
8
+ * A rectangular two-dimensional matrix of scalar {@link Expression} elements.
9
+ *
10
+ * @remarks
11
+ * Construction validates that all nonempty rows have the same length and
12
+ * converts every entry to an Expression; nested parser aggregates are not
13
+ * matrix elements. Existing Expression entries are retained, so use
14
+ * {@link copy} when independent element objects are required. `copy`,
15
+ * {@link evaluate}, and {@link expand} return deep independent matrices.
16
+ *
17
+ * Addition, subtraction, and division remain element-wise. {@link times}
18
+ * implements scalar scaling, matrix multiplication, and matrix-vector multiplication,
19
+ * while {@link pow} implements integer matrix powers. Scalar and matrix products return
20
+ * new Matrices; a matrix-vector product returns a new Vector. {@link each}, {@link set},
21
+ * and parser assignment mutate this matrix. `each` may also be used for observation by
22
+ * returning nothing; use {@link forEach} when no transformation is intended.
23
+ *
24
+ * Direct `get`/`set` indices are zero-based. The compatibility accessor
25
+ * {@link e} and the {@link row}/{@link col} helpers are one-based. Matrix
26
+ * comparisons are component-wise predicates, not a total or lexicographic
27
+ * ordering; a type or dimension mismatch compares false.
28
+ */
29
+ export declare class Matrix extends StructuredEntity<Matrix, Vector> {
30
+ /**
31
+ * Number of row swaps performed during the last toRightTriangular call.
32
+ * Used internally by determinant() to correct the sign.
33
+ */
34
+ private _rowSwaps;
35
+ dataType: typeof MATRIX;
36
+ elements: Expression[][];
37
+ isEnumerable: boolean;
38
+ precision?: number | undefined;
39
+ /**
40
+ * Creates a matrix from array or Vector rows.
41
+ *
42
+ * @param elements - Rows containing values convertible to scalar Expressions.
43
+ * @throws {@link core!MathError} If nonempty rows have different lengths.
44
+ * @throws {@link core!UnexpectedDataType} If an entry cannot be converted to an
45
+ * Expression.
46
+ */
47
+ constructor(...elements: (NerdamerInput[] | Vector)[]);
48
+ /** Creates a matrix whose cells are independent copies of `value`. */
49
+ static fill(rows: number, cols: number, value: Expression): Matrix;
50
+ /** Creates the `n` by `n` identity matrix. */
51
+ static identity(n: number): Matrix;
52
+ static isMatrix(obj: unknown): obj is Matrix;
53
+ /** Creates a matrix filled with symbolic zeros. */
54
+ static zeroMatrix(rows: number, cols: number): Matrix;
55
+ /**
56
+ * Returns a row at the given zero-based index as a Vector.
57
+ * Used by the parser for bracket indexing, e.g. matrix[0] returns the first row.
58
+ * This enables chained indexing: matrix[0][1] returns the element at row 0, col 1.
59
+ *
60
+ * @param indices Zero-based indices (after INDEX_BASE adjustment).
61
+ * Single index [i] returns row i as a Vector.
62
+ * Two indices [i, j] returns the element at row i, col j.
63
+ * @returns A copied row Vector for one index, or the stored Expression for two.
64
+ * @throws {@link core!MathError} If either index is out of bounds.
65
+ */
66
+ __get__(indices: number[]): ParserEntity;
67
+ /**
68
+ * Sets a zero-based cell or replaces an entire row.
69
+ * [i, j] sets the element at row i, col j.
70
+ * [i] requires a Vector whose length matches the matrix column count.
71
+ *
72
+ * @param indices Zero-based indices
73
+ * @param value The value to set
74
+ * @throws {@link core!UnexpectedDataType} If a full-row assignment does not receive a Vector.
75
+ * @throws {@link core!MathError} If an index is out of bounds or a replacement row has the wrong length.
76
+ */
77
+ __set__(indices: number[] | string, value: ParserEntity): void;
78
+ /**
79
+ * Returns the horizontal augmentation `[this | matrix]` without mutating either input.
80
+ *
81
+ * @throws {@link core!MathError} If the row counts differ.
82
+ */
83
+ augment(matrix: Matrix): Matrix;
84
+ canMultiplyFromLeft(M: Matrix): boolean;
85
+ col(n: number): Matrix;
86
+ cols(): number;
87
+ /** Copies the matrix and every Expression element. */
88
+ copy(): Matrix;
89
+ /**
90
+ * Computes the determinant by triangular elimination.
91
+ *
92
+ * The determinant of the empty matrix is one.
93
+ *
94
+ * @throws {@link core!UnsupportedOperationError} If the matrix is not square.
95
+ */
96
+ determinant(): Expression;
97
+ dimensions(): number[];
98
+ dimensionsMatch(M: StructuredEntityType): M is Matrix;
99
+ /**
100
+ * Divides corresponding entries, or broadcasts a scalar divisor.
101
+ *
102
+ * @throws {@link core!DimensionError} If a Matrix divisor has different dimensions.
103
+ */
104
+ div(x: NerdamerInput): Matrix;
105
+ /**
106
+ * Returns a one-based matrix element for compatibility with the legacy accessor.
107
+ *
108
+ * @throws {@link core!MathError} If either index is out of bounds.
109
+ */
110
+ e(i: number, j: number): Expression;
111
+ /**
112
+ * Visits or replaces every element in row-major order.
113
+ * Returning `void` leaves the current cell unchanged. Callback row and column
114
+ * indices are zero-based.
115
+ */
116
+ each(fn: (e: Expression, i?: string | number, j?: string | number) => Expression | void): Matrix;
117
+ eq(M: ParserEntity): boolean;
118
+ /** Evaluates a copied matrix, resolving symbolic cell access when values are supplied. */
119
+ evaluate(): Matrix;
120
+ evaluate(values: ParserValuesObject): ParserEntity;
121
+ /** Expands a copied matrix, leaving this one unchanged. */
122
+ expand(): Matrix;
123
+ /** Visits every cell without changing the matrix. */
124
+ forEach(callback: (value: Expression, row: number, col: number) => void): void;
125
+ /**
126
+ * Returns the stored Expression at a zero-based row and column.
127
+ *
128
+ * @throws {@link core!MathError} If either index is out of bounds.
129
+ */
130
+ get(row: number, col: number): Expression;
131
+ gt(M: ParserEntity): boolean;
132
+ gte(M: ParserEntity): boolean;
133
+ inspect(): string;
134
+ /**
135
+ * Computes an inverse by augmenting with the identity and eliminating rows.
136
+ *
137
+ * @returns A new inverse matrix; this matrix is unchanged.
138
+ * @throws {@link core!UnsupportedOperationError} If the matrix is not square.
139
+ * @throws {@link core!MathError} If the matrix is singular.
140
+ */
141
+ inverse(): Matrix;
142
+ isSingular(): boolean;
143
+ isSquare(): boolean;
144
+ lt(M: ParserEntity): boolean;
145
+ lte(M: ParserEntity): boolean;
146
+ /** Returns a new matrix populated by callback results without mutating this matrix. */
147
+ map(callback: (a: Expression, row?: string | number, col?: string | number) => Expression): Matrix;
148
+ /**
149
+ * Subtracts corresponding entries, or broadcasts a scalar subtrahend.
150
+ *
151
+ * @throws {@link core!DimensionError} If a Matrix operand has different dimensions.
152
+ */
153
+ minus(x: NerdamerInput): Matrix;
154
+ /** Delegates the public multiplication alias to the Matrix-specific times() method. */
155
+ multiply(x: Expression): Matrix;
156
+ multiply(x: Matrix): Matrix;
157
+ multiply(x: Vector): Vector;
158
+ multiply(x: ParserEntity): Matrix | Vector;
159
+ /**
160
+ * Computes a basis for the nullspace using the same reduced row-echelon form as {@link rref}.
161
+ *
162
+ * @remarks
163
+ * Without `prime`, the basis is computed with exact symbolic Expression arithmetic. When
164
+ * `prime` is supplied, the existing modular arithmetic path is preserved and basis entries
165
+ * are reduced modulo that value. Each free column contributes one basis vector, ordered by
166
+ * increasing free-column index. A full-column-rank matrix therefore returns an empty basis.
167
+ *
168
+ * @param prime - Optional modulus for finite-field nullspace arithmetic.
169
+ * @returns Basis vectors as independent Expression arrays ordered by matrix column.
170
+ */
171
+ nullspace(prime?: string | number | Expression): Expression[][];
172
+ /**
173
+ * Adds corresponding entries, or broadcasts a scalar addend.
174
+ *
175
+ * @throws {@link core!DimensionError} If a Matrix operand has different dimensions.
176
+ */
177
+ plus(x: NerdamerInput): Matrix;
178
+ /**
179
+ * Raises this matrix to an integer power without mutating it.
180
+ *
181
+ * Positive powers use matrix multiplication, zero returns the identity, and
182
+ * negative powers use the matrix inverse. A rectangular matrix is accepted only
183
+ * for the identity power `1`; all other matrix powers require a square matrix.
184
+ *
185
+ * @throws {@link core!UnsupportedOperationError} If the exponent is not an integer,
186
+ * or if a nontrivial power is requested for a rectangular matrix.
187
+ * @throws {@link core!MathError} If a negative power requires the inverse of a singular matrix.
188
+ */
189
+ pow(x: NerdamerInput): Matrix;
190
+ rank(): number;
191
+ row(n: number): Matrix;
192
+ rows(): number;
193
+ /**
194
+ * Returns reduced row-echelon form without mutating this matrix.
195
+ *
196
+ * When `prime` is supplied, pivot arithmetic is performed modulo that value.
197
+ * Otherwise pivots and zero rows are determined by exact Expression equality.
198
+ */
199
+ rref(prime?: string | number | Expression): Matrix;
200
+ /** Sets a zero-based cell after converting `value` to an Expression. */
201
+ set(row: number, col: number, value: ParserEntity): this;
202
+ text(): string;
203
+ /**
204
+ * Returns scalar multiplication, the matrix product `this * M`, or the
205
+ * matrix-vector product `this * v`.
206
+ *
207
+ * @throws {@link core!MathError} If matrix or vector dimensions are incompatible.
208
+ * @throws {@link core!UnsupportedOperationError} If the operand is not a supported
209
+ * scalar, Matrix, or Vector.
210
+ */
211
+ times(M: Expression): Matrix;
212
+ times(M: Matrix): Matrix;
213
+ times(M: Vector): Vector;
214
+ times(M: ParserEntity): Matrix | Vector;
215
+ /** Returns a row-echelon copy produced by forward elimination and row swaps. */
216
+ toRightTriangular(): Matrix;
217
+ toUpperTriangular(): Matrix;
218
+ /**
219
+ * Returns the sum of the main diagonal. The empty matrix has trace zero.
220
+ * @throws {@link core!MathError} If the matrix is not square.
221
+ */
222
+ trace(): Expression;
223
+ /** Returns a transposed matrix. Existing elements are normalized by the constructor. */
224
+ transpose(): Matrix;
225
+ /** Returns elements as a column-major Vector. */
226
+ unroll(): Vector;
227
+ }