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,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MathematicalAggregate = void 0;
4
+ const StructuredEntity_1 = require("./StructuredEntity");
5
+ /**
6
+ * MathematicalAggregate
7
+ *
8
+ * Base class for linear iterable parser entities (Vector, ValuesSet, SolutionSet, ...).
9
+ *
10
+ * Elements are ParserEntity values at this shared level. Concrete subclasses may
11
+ * narrow their public element storage where their own method guarantees it.
12
+ */
13
+ class MathematicalAggregate extends StructuredEntity_1.StructuredEntity {
14
+ /**
15
+ * Returns the element at the given index.
16
+ * @param indices A single-element array [i]
17
+ */
18
+ __get__(indices) {
19
+ const index = indices[0];
20
+ if (index < 0 || index >= this.elements.length) {
21
+ throw new RangeError(`Index ${index} out of bounds for ${this.dataType} of length ${this.elements.length}`);
22
+ }
23
+ return this.elements[index];
24
+ }
25
+ /**
26
+ * Sets the element at the given index.
27
+ * @param indices A single-element array [i]
28
+ * @param value The value to set
29
+ */
30
+ __set__(indices, value) {
31
+ const index = indices[0];
32
+ if (index < 0 || index >= this.elements.length) {
33
+ throw new RangeError(`Index ${index} out of bounds for ${this.dataType} of length ${this.elements.length}`);
34
+ }
35
+ this.elements[index] = value;
36
+ }
37
+ clear() {
38
+ this.elements.length = 0;
39
+ return this;
40
+ }
41
+ /**
42
+ * Gets the number of current elements.
43
+ */
44
+ count() {
45
+ return this.elements.length;
46
+ }
47
+ dimensions() {
48
+ return [this.elements.length];
49
+ }
50
+ /**
51
+ * Visits or replaces elements in place.
52
+ * Returning `void` leaves the current element unchanged.
53
+ */
54
+ each(callback) {
55
+ for (let i = 0; i < this.elements.length; i++) {
56
+ const result = callback(this.elements[i], i);
57
+ if (result !== undefined) {
58
+ this.elements[i] = result;
59
+ }
60
+ }
61
+ return this;
62
+ }
63
+ eq(other) {
64
+ if (!this.dimensionsMatch(other)) {
65
+ return false;
66
+ }
67
+ const otherElements = other.elements;
68
+ for (let i = 0; i < this.elements.length; i++) {
69
+ if (!this.elements[i].eq(otherElements[i])) {
70
+ return false;
71
+ }
72
+ }
73
+ return true;
74
+ }
75
+ /**
76
+ * Visits every current element without changing the aggregate.
77
+ *
78
+ * This is the observation-only counterpart to {@link each}. Concrete subclasses may
79
+ * narrow the callback element type when their membership method guarantees a more
80
+ * specific entity.
81
+ */
82
+ forEach(callback) {
83
+ const elements = this.elements;
84
+ for (let i = 0; i < elements.length; i++) {
85
+ callback(elements[i], i);
86
+ }
87
+ }
88
+ gt(other) {
89
+ if (!this.dimensionsMatch(other)) {
90
+ return false;
91
+ }
92
+ const otherElements = other.elements;
93
+ for (let i = 0; i < this.elements.length; i++) {
94
+ if (!this.elements[i].gt(otherElements[i])) {
95
+ return false;
96
+ }
97
+ }
98
+ return true;
99
+ }
100
+ // Element-wise comparisons
101
+ gte(other) {
102
+ return this.gt(other) || this.eq(other);
103
+ }
104
+ lt(other) {
105
+ if (!this.dimensionsMatch(other)) {
106
+ return false;
107
+ }
108
+ const otherElements = other.elements;
109
+ for (let i = 0; i < this.elements.length; i++) {
110
+ if (!this.elements[i].lt(otherElements[i])) {
111
+ return false;
112
+ }
113
+ }
114
+ return true;
115
+ }
116
+ lte(other) {
117
+ return this.lt(other) || this.eq(other);
118
+ }
119
+ sort(compareFn) {
120
+ if (compareFn) {
121
+ this.elements.sort(compareFn);
122
+ return this;
123
+ }
124
+ this.elements.sort((a, b) => {
125
+ const ta = a && typeof a.text === 'function' ? a.text() : String(a);
126
+ const tb = b && typeof b.text === 'function' ? b.text() : String(b);
127
+ return ta < tb ? -1 : ta > tb ? 1 : 0;
128
+ });
129
+ return this;
130
+ }
131
+ /** Returns an iterator over the aggregate's current public element view. */
132
+ [Symbol.iterator]() {
133
+ return this.elements[Symbol.iterator]();
134
+ }
135
+ /** Returns a new array containing the aggregate's current public element view. */
136
+ toArray() {
137
+ return [...this.elements];
138
+ }
139
+ }
140
+ exports.MathematicalAggregate = MathematicalAggregate;
@@ -0,0 +1,62 @@
1
+ import { SCOPE } from '../../classes/parser/constants';
2
+ import type { Token } from '../../classes/parser/Token';
3
+ export declare class Scope extends Array<Scope | Token> {
4
+ /**
5
+ * The column at which the scope was encountered
6
+ */
7
+ column: number;
8
+ dataType: typeof SCOPE;
9
+ /**
10
+ * If true, the operator following this scope requires its left-hand structure to remain
11
+ * unresolved until the operator action is evaluated.
12
+ */
13
+ deferLHSResolution: boolean;
14
+ /**
15
+ * If true, this scope is a compiled right-hand operand whose evaluation is deferred
16
+ * until the receiving operator action chooses to execute it.
17
+ */
18
+ deferRHSResolution: boolean;
19
+ /**
20
+ * The current depth of the scope.
21
+ */
22
+ depth: number;
23
+ /**
24
+ * If true, adjacency before this scope may need a later parser decision. Square
25
+ * scopes defer indexing vs implicit multiplication. Parenthesis scopes retain their
26
+ * implicit-multiplication fallback so a later function registration can reinterpret
27
+ * the adjacency before RPN conversion.
28
+ */
29
+ implicitMultiply: boolean;
30
+ /**
31
+ * If the scope was properly closed then this should be closed.
32
+ */
33
+ isOpen: boolean;
34
+ /**
35
+ * The parent of the current scope
36
+ */
37
+ parent?: Scope;
38
+ /**
39
+ * The scope type, parentheses, or square, or curly, or pipe.
40
+ * This will be used to determine what it maps to during parsing.
41
+ */
42
+ type: string;
43
+ constructor(type: string, column: number, parent?: Scope);
44
+ static isScope(obj: unknown): obj is Scope;
45
+ /**
46
+ * Adds a nested scope to the current scope and then returns it, essentially
47
+ * pointing to the new scope.
48
+ *
49
+ * @param column The column number at which the scope was encountered
50
+ * @param type
51
+ * @returns
52
+ */
53
+ addScope(type: string, column: number): Scope;
54
+ text(valuesOnly?: boolean): string;
55
+ /**
56
+ * This essentially removes the scope and then returns the current scope,
57
+ * essentially going back up to the previous scope.
58
+ *
59
+ * @returns The current scope
60
+ */
61
+ upperScope(): Scope | undefined;
62
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scope = void 0;
4
+ const constants_1 = require("../../classes/parser/constants");
5
+ const common_1 = require("../common");
6
+ class Scope extends Array {
7
+ /**
8
+ * The column at which the scope was encountered
9
+ */
10
+ column;
11
+ dataType;
12
+ /**
13
+ * If true, the operator following this scope requires its left-hand structure to remain
14
+ * unresolved until the operator action is evaluated.
15
+ */
16
+ deferLHSResolution = false;
17
+ /**
18
+ * If true, this scope is a compiled right-hand operand whose evaluation is deferred
19
+ * until the receiving operator action chooses to execute it.
20
+ */
21
+ deferRHSResolution = false;
22
+ /**
23
+ * The current depth of the scope.
24
+ */
25
+ depth = 0;
26
+ /**
27
+ * If true, adjacency before this scope may need a later parser decision. Square
28
+ * scopes defer indexing vs implicit multiplication. Parenthesis scopes retain their
29
+ * implicit-multiplication fallback so a later function registration can reinterpret
30
+ * the adjacency before RPN conversion.
31
+ */
32
+ implicitMultiply = false;
33
+ /**
34
+ * If the scope was properly closed then this should be closed.
35
+ */
36
+ isOpen = false;
37
+ /**
38
+ * The parent of the current scope
39
+ */
40
+ parent;
41
+ /**
42
+ * The scope type, parentheses, or square, or curly, or pipe.
43
+ * This will be used to determine what it maps to during parsing.
44
+ */
45
+ type;
46
+ constructor(type, column, parent) {
47
+ super();
48
+ this.dataType = constants_1.SCOPE;
49
+ // The column where this scope was encountered
50
+ this.column = column;
51
+ // Scopes typically map to something
52
+ this.type = type;
53
+ // A temporary link to the parent of the parent scope;
54
+ this.parent = parent;
55
+ }
56
+ static isScope(obj) {
57
+ return (0, common_1.isNerdamerNativeType)(obj, constants_1.SCOPE);
58
+ }
59
+ /**
60
+ * Adds a nested scope to the current scope and then returns it, essentially
61
+ * pointing to the new scope.
62
+ *
63
+ * @param column The column number at which the scope was encountered
64
+ * @param type
65
+ * @returns
66
+ */
67
+ addScope(type, column) {
68
+ // Yup a circular reference but should be easy to understand.
69
+ const scope = new Scope(type, column, this);
70
+ // Mark that this is one scope deeper than this one.
71
+ scope.depth = this.depth + 1;
72
+ // Mark it as open
73
+ scope.isOpen = true;
74
+ // Add it to the current scope
75
+ this.push(scope);
76
+ return scope;
77
+ }
78
+ text(valuesOnly = true) {
79
+ return this.map(token => {
80
+ // Call scope recursively
81
+ if (Scope.isScope(token)) {
82
+ const scopedStr = token.text(valuesOnly);
83
+ // Put back the parenthesis
84
+ switch (token.type) {
85
+ case 'parenthesis':
86
+ return `( ${scopedStr} )`;
87
+ case 'square':
88
+ return `[ ${scopedStr} ]`;
89
+ case 'curly':
90
+ return `{ ${scopedStr} }`;
91
+ case 'pipe':
92
+ return `| ${scopedStr} |`;
93
+ default:
94
+ return scopedStr;
95
+ }
96
+ }
97
+ else {
98
+ if (valuesOnly) {
99
+ return token.toString();
100
+ }
101
+ return `<${token.toString()}, ${token.type}>`;
102
+ }
103
+ })
104
+ .join(valuesOnly ? ' ' : ', ')
105
+ .replace(/\s+/gi, ' ');
106
+ }
107
+ /**
108
+ * This essentially removes the scope and then returns the current scope,
109
+ * essentially going back up to the previous scope.
110
+ *
111
+ * @returns The current scope
112
+ */
113
+ upperScope() {
114
+ // Close the bracket
115
+ this.isOpen = false;
116
+ const parent = this.parent;
117
+ // This reference is no longer needed. This isn't critical but helps a little with cleanup.
118
+ delete this.parent;
119
+ return parent;
120
+ }
121
+ }
122
+ exports.Scope = Scope;
@@ -0,0 +1,55 @@
1
+ import type { Expression } from '../../classes/expression/Expression';
2
+ import type { ParserEntity } from '../../types';
3
+ import type { NerdamerInput } from '../../types';
4
+ /**
5
+ * Abstract base class for Vector, Matrix, and Collection classes.
6
+ * Consolidates common arithmetic operations and parser mappings.
7
+ *
8
+ * `TProduct` is reserved for multiplication results that differ from the
9
+ * concrete structured entity type. Most structures use the default `never`,
10
+ * so their inherited multiplication continues to return `T` exactly.
11
+ */
12
+ export declare abstract class StructuredEntity<T extends StructuredEntity<T, TProduct>, TProduct extends ParserEntity = never> {
13
+ abstract dataType: string;
14
+ abstract elements: ParserEntity[] | ParserEntity[][];
15
+ abstract isEnumerable: boolean;
16
+ abstract precision?: number;
17
+ /**
18
+ * Public index expressions retained when bracket access cannot yet be resolved.
19
+ * This state belongs to a copied structured entity, never the stored source value.
20
+ */
21
+ symbolicAccessor?: Expression[];
22
+ /** Original symbolic target used to render and later re-evaluate bracket access. */
23
+ symbolicTarget?: Expression;
24
+ /** Copies symbolic access metadata alongside a concrete structured copy. */
25
+ protected copySymbolicAccessTo(copy: T): T;
26
+ /** Renders symbolic access without exposing the carrier's concrete contents. */
27
+ protected formatSymbolicAccess(baseText: string): string;
28
+ private binaryOp;
29
+ abstract __get__(indices: number[] | string): ParserEntity;
30
+ abstract __set__(indices: number[] | string, value: ParserEntity): void;
31
+ abs(): T;
32
+ abstract copy(): T;
33
+ abstract dimensions(): number[];
34
+ dimensionsMatch(x: ParserEntity): x is ParserEntity & T;
35
+ div(x: NerdamerInput): T;
36
+ abstract each(callback: (e: ParserEntity, i?: string | number, j?: string | number) => ParserEntity | void): T;
37
+ abstract eq(other: ParserEntity): boolean;
38
+ abstract evaluate(): T;
39
+ abstract expand(): T;
40
+ abstract gt(other: ParserEntity): boolean;
41
+ abstract gte(other: ParserEntity): boolean;
42
+ abstract lt(other: ParserEntity): boolean;
43
+ abstract lte(other: ParserEntity): boolean;
44
+ minus(x: NerdamerInput): T;
45
+ plus(x: NerdamerInput): T;
46
+ pow(x: NerdamerInput): T;
47
+ abstract text(): string;
48
+ times(x: NerdamerInput): T | TProduct;
49
+ toString(): string;
50
+ /**
51
+ * Returns a copied structured entity carrying an unresolved bracket access.
52
+ * Existing accessor state is retained so chained symbolic access can be extended.
53
+ */
54
+ withSymbolicAccessor(target: Expression, indices: Expression[]): T;
55
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StructuredEntity = void 0;
4
+ function isEnumerableLike(x) {
5
+ if (typeof x !== 'object' || x === null) {
6
+ return false;
7
+ }
8
+ const r = x;
9
+ return (r['isEnumerable'] === true &&
10
+ typeof r['dataType'] === 'string' &&
11
+ Array.isArray(r['elements']));
12
+ }
13
+ function getAggregateElement(agg, i, j) {
14
+ if (i === undefined) {
15
+ return undefined;
16
+ }
17
+ const idx = typeof i === 'number' ? i : Number(i);
18
+ if (!Number.isFinite(idx)) {
19
+ return undefined;
20
+ }
21
+ const row = agg.elements[idx];
22
+ if (row === undefined) {
23
+ return undefined;
24
+ }
25
+ // If matrix-like (array of arrays), index into row using j.
26
+ if (Array.isArray(row)) {
27
+ if (j === undefined) {
28
+ return undefined;
29
+ }
30
+ const jdx = typeof j === 'number' ? j : Number(j);
31
+ if (!Number.isFinite(jdx)) {
32
+ return undefined;
33
+ }
34
+ return row[jdx];
35
+ }
36
+ // Vector/collection-like
37
+ return row;
38
+ }
39
+ function applyBinaryOp(op, lhs, rhs) {
40
+ switch (op) {
41
+ case 'plus': {
42
+ const target = lhs;
43
+ return target.plus(rhs);
44
+ }
45
+ case 'minus': {
46
+ const target = lhs;
47
+ return target.minus(rhs);
48
+ }
49
+ case 'times': {
50
+ const target = lhs;
51
+ return target.times(rhs);
52
+ }
53
+ case 'div': {
54
+ const target = lhs;
55
+ return target.div(rhs);
56
+ }
57
+ case 'pow': {
58
+ const target = lhs;
59
+ // Preserve the historical dynamic failure if an Equation reaches element-wise power.
60
+ return target.pow(rhs);
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * Abstract base class for Vector, Matrix, and Collection classes.
66
+ * Consolidates common arithmetic operations and parser mappings.
67
+ *
68
+ * `TProduct` is reserved for multiplication results that differ from the
69
+ * concrete structured entity type. Most structures use the default `never`,
70
+ * so their inherited multiplication continues to return `T` exactly.
71
+ */
72
+ class StructuredEntity {
73
+ /**
74
+ * Public index expressions retained when bracket access cannot yet be resolved.
75
+ * This state belongs to a copied structured entity, never the stored source value.
76
+ */
77
+ symbolicAccessor;
78
+ /** Original symbolic target used to render and later re-evaluate bracket access. */
79
+ symbolicTarget;
80
+ /** Copies symbolic access metadata alongside a concrete structured copy. */
81
+ copySymbolicAccessTo(copy) {
82
+ if (this.symbolicTarget) {
83
+ copy.symbolicTarget = this.symbolicTarget.copy();
84
+ }
85
+ if (this.symbolicAccessor) {
86
+ copy.symbolicAccessor = this.symbolicAccessor.map(index => index.copy());
87
+ }
88
+ return copy;
89
+ }
90
+ /** Renders symbolic access without exposing the carrier's concrete contents. */
91
+ formatSymbolicAccess(baseText) {
92
+ let retval = baseText;
93
+ if (this.symbolicAccessor && this.symbolicAccessor.length > 0) {
94
+ const target = this.symbolicTarget ? this.symbolicTarget.text() : baseText;
95
+ retval = `${target}[${this.symbolicAccessor.map(index => index.text()).join(', ')}]`;
96
+ }
97
+ return retval;
98
+ }
99
+ binaryOp(op, x) {
100
+ const rhsAgg = isEnumerableLike(x) && x.dataType === this.dataType ? x : undefined;
101
+ return this.copy().each((e, i, j) => {
102
+ const rhs = rhsAgg ? (getAggregateElement(rhsAgg, i, j) ?? x) : x;
103
+ return applyBinaryOp(op, e, rhs);
104
+ });
105
+ }
106
+ abs() {
107
+ return this.copy().each((e) => {
108
+ return e.abs();
109
+ });
110
+ }
111
+ dimensionsMatch(x) {
112
+ if (!isEnumerableLike(x) || this.dataType !== x.dataType) {
113
+ return false;
114
+ }
115
+ return x.elements.length === this.elements.length;
116
+ }
117
+ div(x) {
118
+ return this.binaryOp('div', x);
119
+ }
120
+ minus(x) {
121
+ return this.binaryOp('minus', x);
122
+ }
123
+ plus(x) {
124
+ return this.binaryOp('plus', x);
125
+ }
126
+ pow(x) {
127
+ return this.binaryOp('pow', x);
128
+ }
129
+ times(x) {
130
+ return this.binaryOp('times', x);
131
+ }
132
+ toString() {
133
+ return this.text();
134
+ }
135
+ /**
136
+ * Returns a copied structured entity carrying an unresolved bracket access.
137
+ * Existing accessor state is retained so chained symbolic access can be extended.
138
+ */
139
+ withSymbolicAccessor(target, indices) {
140
+ const retval = this.copy();
141
+ if (!retval.symbolicTarget) {
142
+ retval.symbolicTarget = target.copy();
143
+ }
144
+ retval.symbolicAccessor = [
145
+ ...(retval.symbolicAccessor ?? []),
146
+ ...indices.map(index => index.copy()),
147
+ ];
148
+ return retval;
149
+ }
150
+ }
151
+ exports.StructuredEntity = StructuredEntity;
@@ -0,0 +1,63 @@
1
+ export interface Base<Type> {
2
+ dataType: string;
3
+ isEnumerable: boolean;
4
+ text: () => string;
5
+ copy: () => Type;
6
+ }
7
+ /**
8
+ * Checks Nerdamer's runtime data-type discriminator without importing a concrete class.
9
+ *
10
+ * Class-specific guards such as `Matrix.isMatrix` should remain the normal call site when
11
+ * that class can be imported safely. This lower-level check backs those guards and provides
12
+ * the same discriminator in code where a concrete import would introduce a cycle.
13
+ */
14
+ export declare function isNerdamerNativeType(obj: unknown, dataType: string): boolean;
15
+ /**
16
+ * The supported operator actions
17
+ */
18
+ export type BinaryArithmeticOperation = 'pow' | 'times' | 'div' | 'minus' | 'plus';
19
+ export type ComparisonOperation = 'eq' | 'lt' | 'lte' | 'gt' | 'gte';
20
+ export type OperatorAction = 'dot' | 'doubleFactorial' | 'factorial' | 'mod' | 'percent' | BinaryArithmeticOperation | 'setEqual' | ComparisonOperation | 'mapTo' | 'comma' | 'assign' | 'functionAssign' | 'in';
21
+ /**
22
+ * Operator metadata accepted by the parser registry.
23
+ *
24
+ * Registration accepts custom action names and the legacy `prefix`/`postfix` aliases.
25
+ * Prefix, postfix, and iteration flags are optional because the parser supplies defaults.
26
+ */
27
+ export interface OperatorDefinition {
28
+ precedence: number;
29
+ operator: string;
30
+ action: string;
31
+ isPrefix?: boolean;
32
+ isPostfix?: boolean;
33
+ leftAssoc: boolean;
34
+ iterates?: boolean;
35
+ prefix?: boolean;
36
+ postfix?: boolean;
37
+ assertiveAction?: string;
38
+ deferLHSResolution?: boolean;
39
+ deferRHSResolution?: boolean;
40
+ postfixVariant?: Operator;
41
+ }
42
+ /** Fully normalized operator metadata stored by the parser. */
43
+ export interface Operator extends OperatorDefinition {
44
+ isPrefix: boolean;
45
+ isPostfix: boolean;
46
+ iterates: boolean;
47
+ prefix?: never;
48
+ postfix?: never;
49
+ }
50
+ export interface Bracket {
51
+ type: string;
52
+ id: number;
53
+ isOpen: boolean;
54
+ isClose: boolean;
55
+ matches: string;
56
+ }
57
+ export declare const brackets: {
58
+ [key: string]: Bracket;
59
+ };
60
+ export declare const operators: Record<string, Operator & {
61
+ action: OperatorAction;
62
+ }>;
63
+ export declare const ASSERTIVE_FUNCTIONS: string[];