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,381 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValuesSet = void 0;
4
+ const MathematicalAggregate_1 = require("../../common/classes/MathematicalAggregate");
5
+ const common_1 = require("../../common/common");
6
+ const errors_1 = require("../../errors");
7
+ const constants_1 = require("../parser/constants");
8
+ /**
9
+ * A finite mathematical set of Nerdamer parser values.
10
+ *
11
+ * @remarks
12
+ * Membership and uniqueness use each element's `eq()` method rather than JavaScript
13
+ * reference identity. Two members are considered equal only when both directional equality
14
+ * checks agree, which keeps mixed-type membership independent of insertion order. This treatment is
15
+ * conservative for symbolic values: if Nerdamer cannot establish that two
16
+ * elements are equal, they remain distinct. Values whose entity types cannot be compared are
17
+ * likewise treated as distinct members. In particular, set membership does not attempt theorem
18
+ * proving beyond the equality semantics of the stored values.
19
+ *
20
+ * `ValuesSet` owns its elements. Values passed to the constructor or {@link add} are copied,
21
+ * and {@link elements}, {@link at}, and indexed reads return copies. This prevents a caller
22
+ * from changing a stored mutable object behind the set and silently violating uniqueness.
23
+ * Mutation therefore goes through the set methods, which re-establish set uniqueness
24
+ * after every supported change.
25
+ *
26
+ * Iteration order is deterministic insertion order so text output and direct traversal are
27
+ * reproducible, but that order has no mathematical meaning. Equality and subset/superset
28
+ * comparisons are membership-based and ignore order.
29
+ *
30
+ * The arithmetic methods inherited by other structured entities are rejected
31
+ * here. Pairing two sets by insertion index would make arithmetic depend on a non-mathematical
32
+ * ordering. Use the explicit finite-set operations on this class instead.
33
+ */
34
+ class ValuesSet extends MathematicalAggregate_1.MathematicalAggregate {
35
+ _elements = [];
36
+ dataType = constants_1.SET;
37
+ isEnumerable = true;
38
+ precision;
39
+ constructor(values) {
40
+ super();
41
+ if (values) {
42
+ for (const v of values) {
43
+ this.add(v);
44
+ }
45
+ }
46
+ }
47
+ /**
48
+ * Tests whether a value is a `ValuesSet` or a specialized `ValuesSet` subtype such as
49
+ * `SolutionSet`.
50
+ */
51
+ static isValuesSet(obj) {
52
+ return ((0, common_1.isNerdamerNativeType)(obj, constants_1.SET) || (0, common_1.isNerdamerNativeType)(obj, constants_1.SOLUTIONS_SET));
53
+ }
54
+ getValuesArray() {
55
+ return this.elements;
56
+ }
57
+ setValuesArray(values) {
58
+ this.clear();
59
+ for (const v of values) {
60
+ this.add(v);
61
+ }
62
+ }
63
+ indexOf(x) {
64
+ for (let i = 0; i < this._elements.length; i++) {
65
+ if (this.membersEqual(this._elements[i], x)) {
66
+ return i;
67
+ }
68
+ }
69
+ return -1;
70
+ }
71
+ membersEqual(a, b) {
72
+ let retval = false;
73
+ try {
74
+ // Parser-entity equality is not guaranteed to be symmetric across different
75
+ // entity types. A set must not deduplicate values based on insertion direction,
76
+ // so require both entities to agree that they represent the same member.
77
+ retval = a.eq(b) && b.eq(a);
78
+ }
79
+ catch (e) {
80
+ if (!(e instanceof errors_1.UnexpectedDataType)) {
81
+ throw e;
82
+ }
83
+ }
84
+ return retval;
85
+ }
86
+ /**
87
+ * Reads an element for parser indexing.
88
+ *
89
+ * @throws A `RangeError` if the index is outside the current set size.
90
+ */
91
+ __get__(indices) {
92
+ const index = indices[0];
93
+ if (index < 0 || index >= this._elements.length) {
94
+ throw new RangeError(`Index ${index} out of bounds for ${this.dataType} of length ${this._elements.length}`);
95
+ }
96
+ return this._elements[index].copy();
97
+ }
98
+ /**
99
+ * Replaces the insertion-order element at an index while preserving uniqueness.
100
+ *
101
+ * @remarks
102
+ * If the replacement is already present elsewhere in the set, the indexed element is
103
+ * removed instead of creating a duplicate. Indexed mutation is provided for parser
104
+ * compatibility; the index is not part of the mathematical identity of a set.
105
+ *
106
+ * @throws A `RangeError` if the index is outside the current set size.
107
+ */
108
+ __set__(indices, value) {
109
+ const index = indices[0];
110
+ if (index < 0 || index >= this._elements.length) {
111
+ throw new RangeError(`Index ${index} out of bounds for ${this.dataType} of length ${this._elements.length}`);
112
+ }
113
+ const replacement = value.copy();
114
+ const duplicateIndex = this.indexOf(replacement);
115
+ if (duplicateIndex !== -1 && duplicateIndex !== index) {
116
+ this._elements.splice(index, 1);
117
+ }
118
+ else {
119
+ this._elements[index] = replacement;
120
+ }
121
+ }
122
+ /** Adds an element if no semantically equal member is already present. */
123
+ add(x) {
124
+ if (!this.has(x)) {
125
+ this._elements.push(x.copy());
126
+ }
127
+ return this;
128
+ }
129
+ /** Adds every value in the iterable while preserving set uniqueness. */
130
+ addMany(x) {
131
+ for (const e of x) {
132
+ this.add(e);
133
+ }
134
+ return this;
135
+ }
136
+ /**
137
+ * Returns a copy of the element at the requested insertion-order index.
138
+ *
139
+ * @returns A copy of the stored value, or `undefined` when the index is out of range.
140
+ */
141
+ at(i) {
142
+ const value = this._elements[i];
143
+ return value ? value.copy() : undefined;
144
+ }
145
+ /** Removes every member from the set. */
146
+ clear() {
147
+ this._elements.length = 0;
148
+ return this;
149
+ }
150
+ /** Returns an independent set containing independent copies of all members. */
151
+ copy() {
152
+ return new ValuesSet(this._elements);
153
+ }
154
+ /** Returns the current number of set members. */
155
+ count() {
156
+ return this._elements.length;
157
+ }
158
+ /** Removes the member semantically equal to `x`, if one is present. */
159
+ delete(x) {
160
+ const i = this.indexOf(x);
161
+ if (i === -1) {
162
+ return false;
163
+ }
164
+ this._elements.splice(i, 1);
165
+ return true;
166
+ }
167
+ /** Returns a new set containing members of this set that are absent from `other`. */
168
+ difference(other) {
169
+ const retval = new ValuesSet();
170
+ for (const value of this._elements) {
171
+ if (!other.has(value)) {
172
+ retval.add(value);
173
+ }
174
+ }
175
+ return retval;
176
+ }
177
+ /** Returns the one-dimensional storage size used by parser indexing. */
178
+ dimensions() {
179
+ return [this._elements.length];
180
+ }
181
+ /**
182
+ * Rejects binary division because finite sets do not define elementwise quotients.
183
+ *
184
+ * @throws {@link core!UnsupportedOperationError} Always.
185
+ */
186
+ div(_x) {
187
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
188
+ }
189
+ /**
190
+ * Visits or maps the current members in insertion order.
191
+ *
192
+ * Duplicate mapped values collapse to their first occurrence. The callback receives a
193
+ * copy of each stored member, so mutating an input inside the callback cannot alter the
194
+ * set unless that value is returned. Returning `void` leaves the current member unchanged.
195
+ */
196
+ each(callback) {
197
+ const next = [];
198
+ for (let i = 0; i < this._elements.length; i++) {
199
+ const current = this._elements[i].copy();
200
+ const mapped = callback(current, i);
201
+ const value = mapped === undefined ? this._elements[i] : mapped;
202
+ // Preserve insertion order for first occurrences only.
203
+ let exists = false;
204
+ for (let k = 0; k < next.length; k++) {
205
+ if (this.membersEqual(next[k], value)) {
206
+ exists = true;
207
+ break;
208
+ }
209
+ }
210
+ if (!exists) {
211
+ next.push(value.copy());
212
+ }
213
+ }
214
+ this._elements = next;
215
+ return this;
216
+ }
217
+ /**
218
+ * Returns a deep-copied snapshot of the set's current elements.
219
+ *
220
+ * Mutating the returned array or its members does not change this set. Use the set's
221
+ * mutation methods when the stored membership should change.
222
+ */
223
+ get elements() {
224
+ return this._elements.map(e => e.copy());
225
+ }
226
+ /** Tests set equality by membership, independent of insertion order. */
227
+ eq(other) {
228
+ if (!ValuesSet.isValuesSet(other)) {
229
+ return false;
230
+ }
231
+ if (other.count() !== this.count()) {
232
+ return false;
233
+ }
234
+ return this.isSubsetOf(other);
235
+ }
236
+ /** Evaluates every member and returns a new set, collapsing equal results. */
237
+ evaluate() {
238
+ return this.copy().each(e => e.evaluate());
239
+ }
240
+ /** Expands every member and returns a new set, collapsing equal results. */
241
+ expand() {
242
+ return this.copy().each(e => e.expand());
243
+ }
244
+ /**
245
+ * Returns the proper-superset relation for compatibility with parser comparison syntax.
246
+ * Prefer {@link isProperSupersetOf} in direct set-oriented code.
247
+ */
248
+ gt(other) {
249
+ return ValuesSet.isValuesSet(other) && this.isProperSupersetOf(other);
250
+ }
251
+ /**
252
+ * Returns the superset relation for compatibility with parser comparison syntax.
253
+ * Prefer {@link isSupersetOf} in direct set-oriented code.
254
+ */
255
+ gte(other) {
256
+ return ValuesSet.isValuesSet(other) && this.isSupersetOf(other);
257
+ }
258
+ /** Tests whether a semantically equal member is present. */
259
+ has(x) {
260
+ return this.indexOf(x) !== -1;
261
+ }
262
+ /** Returns a new set containing only members present in both sets. */
263
+ intersection(other) {
264
+ const retval = new ValuesSet();
265
+ for (const value of this._elements) {
266
+ if (other.has(value)) {
267
+ retval.add(value);
268
+ }
269
+ }
270
+ return retval;
271
+ }
272
+ /** Returns `true` when this set has no member in common with `other`. */
273
+ isDisjointFrom(other) {
274
+ for (const value of this._elements) {
275
+ if (other.has(value)) {
276
+ return false;
277
+ }
278
+ }
279
+ return true;
280
+ }
281
+ /** Returns `true` when this set is a strict subset of `other`. */
282
+ isProperSubsetOf(other) {
283
+ return this.count() < other.count() && this.isSubsetOf(other);
284
+ }
285
+ /** Returns `true` when this set is a strict superset of `other`. */
286
+ isProperSupersetOf(other) {
287
+ return this.count() > other.count() && this.isSupersetOf(other);
288
+ }
289
+ /** Returns `true` when every member of this set is present in `other`. */
290
+ isSubsetOf(other) {
291
+ for (const value of this._elements) {
292
+ if (!other.has(value)) {
293
+ return false;
294
+ }
295
+ }
296
+ return true;
297
+ }
298
+ /** Returns `true` when every member of `other` is present in this set. */
299
+ isSupersetOf(other) {
300
+ return other.isSubsetOf(this);
301
+ }
302
+ /**
303
+ * Returns the proper-subset relation for compatibility with parser comparison syntax.
304
+ * Prefer {@link isProperSubsetOf} in direct set-oriented code.
305
+ */
306
+ lt(other) {
307
+ return ValuesSet.isValuesSet(other) && this.isProperSubsetOf(other);
308
+ }
309
+ /**
310
+ * Returns the subset relation for compatibility with parser comparison syntax.
311
+ * Prefer {@link isSubsetOf} in direct set-oriented code.
312
+ */
313
+ lte(other) {
314
+ return ValuesSet.isValuesSet(other) && this.isSubsetOf(other);
315
+ }
316
+ /**
317
+ * Rejects binary subtraction because finite sets do not define elementwise subtraction.
318
+ *
319
+ * @throws {@link core!UnsupportedOperationError} Always.
320
+ */
321
+ minus(_x) {
322
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
323
+ }
324
+ /**
325
+ * Binary addition is not defined for finite sets. Use {@link union} for set union.
326
+ *
327
+ * @throws {@link core!UnsupportedOperationError} Always.
328
+ */
329
+ plus(_x) {
330
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
331
+ }
332
+ /**
333
+ * Rejects binary exponentiation because finite sets do not define elementwise powers.
334
+ *
335
+ * @throws {@link core!UnsupportedOperationError} Always.
336
+ */
337
+ pow(_x) {
338
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
339
+ }
340
+ /**
341
+ * Sorts the deterministic iteration order without changing mathematical membership.
342
+ * A custom comparator receives copies so it cannot mutate stored members as a side effect.
343
+ */
344
+ sort(compareFn) {
345
+ if (compareFn) {
346
+ this._elements.sort((a, b) => compareFn(a.copy(), b.copy()));
347
+ }
348
+ else {
349
+ this._elements.sort((a, b) => {
350
+ const ta = a && typeof a.text === 'function' ? a.text() : String(a);
351
+ const tb = b && typeof b.text === 'function' ? b.text() : String(b);
352
+ return ta < tb ? -1 : ta > tb ? 1 : 0;
353
+ });
354
+ }
355
+ return this;
356
+ }
357
+ /** Returns a new set containing members present in exactly one of the two sets. */
358
+ symmetricDifference(other) {
359
+ const retval = this.difference(other);
360
+ retval.addMany(other.difference(this)._elements);
361
+ return retval;
362
+ }
363
+ text() {
364
+ return `{${this._elements.map(e => e.text()).join(', ')}}`;
365
+ }
366
+ /**
367
+ * Rejects binary multiplication because finite sets do not define elementwise products.
368
+ *
369
+ * @throws {@link core!UnsupportedOperationError} Always.
370
+ */
371
+ times(_x) {
372
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
373
+ }
374
+ /** Returns a new set containing members present in either set. */
375
+ union(other) {
376
+ const retval = new ValuesSet(this._elements);
377
+ retval.addMany(other._elements);
378
+ return retval;
379
+ }
380
+ }
381
+ exports.ValuesSet = ValuesSet;
@@ -0,0 +1,222 @@
1
+ import { MathematicalAggregate } from '../../common/classes/MathematicalAggregate';
2
+ import { Collection } from '../collection/Collection';
3
+ import { Expression } from '../expression/Expression';
4
+ import { VECTOR } from '../parser/constants';
5
+ import { Polynomial } from '../polynomial/Polynomial';
6
+ import type { ParserEntity, ExpressionInput, NerdamerInput } from '../../types';
7
+ import type { ParserValuesObject } from '../parser/types';
8
+ /**
9
+ * An ordered, operable parser aggregate with heterogeneous {@link ParserEntity} elements.
10
+ *
11
+ * @remarks
12
+ * Vector is not restricted to numeric linear-algebra values. General arithmetic
13
+ * is element-wise: scalar operands are broadcast across the Vector, while Vector
14
+ * operands are paired by position and must have the same length. Vector-to-Vector
15
+ * {@link times} remains an element-wise product rather than an alias for {@link dot}.
16
+ * A Matrix operand interprets this Vector as a row vector for the standard
17
+ * `Vector * Matrix` product; orientation is supplied by operand position rather
18
+ * than stored on the Vector.
19
+ * Structural methods such as {@link append}, {@link insert}, {@link extend},
20
+ * {@link reverse}, and {@link trim} mutate this Vector.
21
+ *
22
+ * True linear-algebra operations ({@link dot}, {@link cross}, and {@link norm})
23
+ * require Expression elements. `dot` requires equal lengths, while `cross`
24
+ * requires two three-element Vectors. These operations throw rather than
25
+ * assigning arithmetic meaning to arbitrary aggregate elements.
26
+ *
27
+ * Construction from a Collection copies its elements. Construction from an
28
+ * array normalizes inputs but retains existing parser entities; {@link copy}
29
+ * deep-copies every element. Comparisons are component-wise predicates, not a
30
+ * total ordering, and return false for a type or length mismatch.
31
+ */
32
+ export declare class Vector extends MathematicalAggregate<Vector> {
33
+ dataType: typeof VECTOR;
34
+ elements: ParserEntity[];
35
+ isEnumerable: boolean;
36
+ precision?: number | undefined;
37
+ /** Creates a Vector from normalized input values or a copied Collection. */
38
+ constructor(elements?: NerdamerInput[] | Collection);
39
+ /** Creates an Expression-only Vector from expression-compatible inputs. */
40
+ static create(v: ExpressionInput[]): Vector;
41
+ static isVector(obj: unknown): obj is Vector;
42
+ protected getValuesArray(): ParserEntity[];
43
+ protected setValuesArray(values: ParserEntity[]): void;
44
+ /**
45
+ * Returns the element at the given zero-based index.
46
+ * Used by the parser for bracket indexing, e.g. [a, b, c][1] returns b.
47
+ *
48
+ * @param indices - Zero-based parser indices after index-base adjustment.
49
+ * @returns The stored parser entity.
50
+ * @throws {@link core!UnexpectedDataType} If the index is out of bounds.
51
+ */
52
+ __get__(indices: number[]): ParserEntity;
53
+ /** Appends an existing parser entity by reference and returns this Vector. */
54
+ add(x: ParserEntity): this;
55
+ /**
56
+ * Appends an existing parser entity by reference.
57
+ * @param e - Element to append.
58
+ */
59
+ append(e: ParserEntity): this;
60
+ arrayMap(callback: (e: ParserEntity) => unknown): unknown[];
61
+ /**
62
+ * Returns the stored entity at a zero-based index without copying it.
63
+ * @param i - Zero-based index.
64
+ * @returns The entity, or `undefined` when the index is out of range.
65
+ */
66
+ at(i: number): ParserEntity | undefined;
67
+ /**
68
+ * Removes all elements from the vector.
69
+ */
70
+ clear(): this;
71
+ /** Copies the Vector and every contained entity. */
72
+ copy(): Vector;
73
+ /**
74
+ * Gets the number of current elements in the Vector.
75
+ * @returns Current length.
76
+ */
77
+ count(): number;
78
+ /**
79
+ * Computes the three-dimensional cross product.
80
+ *
81
+ * @throws {@link core!DimensionError} Unless both Vectors have exactly three elements.
82
+ * @throws {@link core!UnexpectedDataType} If any required element is not an Expression.
83
+ */
84
+ cross(v: Vector): Vector;
85
+ delete(x: ParserEntity): boolean;
86
+ dimensions(): number[];
87
+ /**
88
+ * Divides corresponding elements, or broadcasts a scalar divisor.
89
+ *
90
+ * @remarks
91
+ * Vector-to-Vector division is element-wise and requires equal lengths. This is
92
+ * distinct from scalar division, which applies the same divisor to every element.
93
+ *
94
+ * @throws {@link core!DimensionError} If a Vector divisor has a different length.
95
+ */
96
+ div(x: NerdamerInput): Vector;
97
+ /**
98
+ * Computes the sum of pairwise products.
99
+ *
100
+ * @throws {@link core!DimensionError} If the Vector lengths differ.
101
+ * @throws {@link core!UnexpectedDataType} If a required element is not an Expression.
102
+ */
103
+ dot(v: Vector): Expression;
104
+ /**
105
+ * Visits or replaces elements in ascending index order.
106
+ * Returning `void` leaves the current element unchanged.
107
+ */
108
+ each(callback: (e: ParserEntity, i: number) => ParserEntity | void): this;
109
+ eq(V: ParserEntity): boolean;
110
+ /** Evaluates a copied Vector, resolving symbolic bracket access when values are supplied. */
111
+ evaluate(): Vector;
112
+ evaluate(values: ParserValuesObject): ParserEntity;
113
+ /** Expands a copied Vector, leaving this one unchanged. */
114
+ expand(): Vector;
115
+ /**
116
+ * Appends another Vector's element references, mutating this Vector.
117
+ * @param v - Vector whose elements should be appended.
118
+ * @returns This Vector.
119
+ * @throws {@link core!UnexpectedDataType} If `v` is not a Vector.
120
+ */
121
+ extend(v: ParserEntity): this;
122
+ /**
123
+ * Returns an element after verifying that it is an Expression.
124
+ * @param n - Zero-based index.
125
+ * @returns The stored Expression reference.
126
+ * @throws {@link core!UnexpectedDataType} If the stored entity is not an Expression.
127
+ */
128
+ getExpressionAt(n: number): Expression;
129
+ gt(V: ParserEntity): boolean;
130
+ gte(V: ParserEntity): boolean;
131
+ /**
132
+ * Gets the index of the first element structurally equal to `x`.
133
+ * @param x - Value to locate.
134
+ * @returns The zero-based index, or `-1` when absent.
135
+ */
136
+ indexOf(x: ParserEntity): number;
137
+ /**
138
+ * Inserts an entity by reference before the provided index.
139
+ * @param i - Zero-based insertion index.
140
+ * @param x - Entity to insert.
141
+ * @returns This mutated Vector.
142
+ */
143
+ insert(i: number, x: ParserEntity): this;
144
+ lt(V: ParserEntity): boolean;
145
+ lte(V: ParserEntity): boolean;
146
+ /**
147
+ * Subtracts corresponding elements, or broadcasts a scalar subtrahend.
148
+ *
149
+ * @throws {@link core!DimensionError} If a Vector operand has a different length.
150
+ */
151
+ minus(x: NerdamerInput): Vector;
152
+ /**
153
+ * Returns the Euclidean norm `sqrt(sum(abs(element)^2))`.
154
+ * @throws {@link core!UnexpectedDataType} If any element is not an Expression.
155
+ */
156
+ norm(): Expression;
157
+ /**
158
+ * Adds corresponding elements, or broadcasts a scalar addend.
159
+ *
160
+ * @throws {@link core!DimensionError} If a Vector operand has a different length.
161
+ */
162
+ plus(x: NerdamerInput): Vector;
163
+ /**
164
+ * Removes an element given an index. If none is provided it removes the last element.
165
+ * Indices are zero-based.
166
+ * @param index - Optional zero-based index.
167
+ * @returns The removed entity, or `undefined` when no entity is present.
168
+ */
169
+ pop(index?: number): ParserEntity | undefined;
170
+ /**
171
+ * Raises corresponding elements to powers, or broadcasts a scalar exponent.
172
+ *
173
+ * @throws {@link core!DimensionError} If a Vector exponent has a different length.
174
+ */
175
+ pow(x: NerdamerInput): Vector;
176
+ /**
177
+ * Multiplies all Expression elements in order.
178
+ * @returns Their product, or one for an empty Vector.
179
+ * @throws {@link core!UnexpectedDataType} If an element is not an Expression.
180
+ */
181
+ prod(): Expression;
182
+ /**
183
+ * Removes the first element equal to `x`, rather than matching by reference.
184
+ * @param x - Value to remove.
185
+ * @returns This Vector, whether or not a match was found.
186
+ */
187
+ remove(x: ParserEntity): this;
188
+ /**
189
+ * Reverses the Vector in place.
190
+ * @returns This Vector.
191
+ */
192
+ reverse(): this;
193
+ /**
194
+ * Adds all Expression elements in order.
195
+ * @returns Their sum, or zero for an empty Vector.
196
+ * @throws {@link core!UnexpectedDataType} If an element is not an Expression.
197
+ */
198
+ sum(): Expression;
199
+ text(): string;
200
+ /**
201
+ * Multiplies corresponding Vector elements, broadcasts a scalar factor, or
202
+ * multiplies this Vector from the left of a Matrix.
203
+ *
204
+ * @remarks
205
+ * Vector-to-Vector multiplication is the element-wise (Hadamard) product. Use
206
+ * {@link dot} when a scalar inner product is intended. For a Matrix operand,
207
+ * this Vector is interpreted as a row vector. Nonzero-width products reuse the
208
+ * existing Matrix-vector product through the transpose; a compatible zero-width
209
+ * Matrix has the empty Vector as its result because its transpose cannot be represented.
210
+ *
211
+ * @throws {@link core!DimensionError} If Vector dimensions are incompatible.
212
+ * @throws {@link core!MathError} If Matrix dimensions are incompatible.
213
+ */
214
+ times(x: NerdamerInput): Vector;
215
+ /** Interprets ordered elements as ascending polynomial coefficients. */
216
+ toPolynomial(vars?: string[]): Polynomial;
217
+ /**
218
+ * Removes every element equal to zero.
219
+ * @returns This mutated Vector.
220
+ */
221
+ trim(): this;
222
+ }