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.
- package/LICENSE.md +184 -0
- package/README.md +293 -312
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +1960 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +33 -0
- package/output/algebra/adapters.js +109 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +323 -0
- package/output/algebra/algorithms/factor.d.ts +3 -0
- package/output/algebra/algorithms/factor.js +5 -0
- package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
- package/output/algebra/algorithms/factorMultivariate.js +2393 -0
- package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
- package/output/algebra/algorithms/factorUnivariate.js +1072 -0
- package/output/algebra/algorithms/gcd.d.ts +22 -0
- package/output/algebra/algorithms/gcd.js +690 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
- package/output/algebra/algorithms/groebnerBase.js +1166 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
- package/output/algebra/algorithms/poly.d.ts +228 -0
- package/output/algebra/algorithms/poly.js +1299 -0
- package/output/algebra/algorithms/rational.d.ts +17 -0
- package/output/algebra/algorithms/rational.js +115 -0
- package/output/algebra/factor/factor.d.ts +62 -0
- package/output/algebra/factor/factor.js +158 -0
- package/output/algebra/gcd/gcd.d.ts +29 -0
- package/output/algebra/gcd/gcd.js +141 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +42 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +398 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +24 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +228 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +7 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +32 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +9 -0
- package/output/api/calculus.js +21 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- package/output/api/parser.d.ts +85 -0
- package/output/api/parser.js +16 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +16 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +22 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +238 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/adapters.d.ts +18 -0
- package/output/core/adapters.js +40 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +605 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +231 -0
- package/output/core/classes/complex/Complex.d.ts +99 -0
- package/output/core/classes/complex/Complex.js +135 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +453 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +213 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +198 -0
- package/output/core/classes/expression/Expression.d.ts +1674 -0
- package/output/core/classes/expression/Expression.js +2332 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +45 -0
- package/output/core/classes/expression/format.js +217 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +52 -0
- package/output/core/classes/expression/utils.js +189 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +889 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- package/output/core/classes/matrix/functions.d.ts +26 -0
- package/output/core/classes/matrix/functions.js +52 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +480 -0
- package/output/core/classes/parser/Parser.js +1812 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +160 -0
- package/output/core/classes/parser/constants.js +227 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +238 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +461 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +430 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +321 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +35 -0
- package/output/core/classes/parser/preprocess.d.ts +14 -0
- package/output/core/classes/parser/preprocess.js +259 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
- package/output/core/classes/parser/scripting/controlFlow.js +355 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
- package/output/core/classes/parser/scripting/evaluate.js +112 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +35 -0
- package/output/core/classes/parser/scripting/scope.js +155 -0
- package/output/core/classes/parser/types.d.ts +125 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
- package/output/core/classes/polynomial/Polynomial.js +1149 -0
- package/output/core/classes/polynomial/Term.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/functions.d.ts +69 -0
- package/output/core/classes/polynomial/functions.js +126 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +206 -0
- package/output/core/classes/rational/Rational.d.ts +504 -0
- package/output/core/classes/rational/Rational.js +779 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
- package/output/core/classes/valuesSet/ValuesSet.js +381 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +497 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +140 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +63 -0
- package/output/core/common/common.js +279 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +802 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +34 -0
- package/output/core/dispatch.js +304 -0
- package/output/core/errors.d.ts +531 -0
- package/output/core/errors.js +621 -0
- package/output/core/functions/bigint/bigint.d.ts +121 -0
- package/output/core/functions/bigint/bigint.js +392 -0
- package/output/core/functions/bigint/primeFactor.d.ts +49 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +133 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +664 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +101 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +498 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +339 -0
- package/output/index.js +715 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +320 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +292 -0
- package/output/math/geometry.d.ts +8 -0
- package/output/math/geometry.js +32 -0
- package/output/math/math.d.ts +655 -0
- package/output/math/math.js +1811 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +60 -0
- package/output/math/utils.js +180 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +85 -0
- package/output/solve/classes/PolynomialSolver.js +292 -0
- package/output/solve/classes/SolutionSet.d.ts +153 -0
- package/output/solve/classes/SolutionSet.js +357 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/linsolve.d.ts +51 -0
- package/output/solve/linsolve.js +225 -0
- package/output/solve/solve.d.ts +34 -0
- package/output/solve/solve.js +260 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +290 -0
- package/output/solve/utils.d.ts +9 -0
- package/output/solve/utils.js +62 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +295 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +213 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/BREAKING_CHANGES.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DecimalSet = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
/**
|
|
9
|
+
* A high-performance set implementation for Decimal.js numbers.
|
|
10
|
+
*
|
|
11
|
+
* This class provides a complete set of operations for working with sets of
|
|
12
|
+
* arbitrary-precision decimal numbers. It uses string representation internally
|
|
13
|
+
* for efficient equality comparison and hashing.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const setA = new DecimalSet([1, 2, 3]);
|
|
18
|
+
* const setB = new DecimalSet([2, 3, 4]);
|
|
19
|
+
* const union = setA.union(setB); // {1, 2, 3, 4}
|
|
20
|
+
* const intersection = setA.intersection(setB); // {2, 3}
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class DecimalSet {
|
|
24
|
+
elements;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new DecimalSet.
|
|
27
|
+
*
|
|
28
|
+
* @param values - Optional array of values to initialize the set
|
|
29
|
+
*/
|
|
30
|
+
constructor(values) {
|
|
31
|
+
this.elements = new Map();
|
|
32
|
+
if (values) {
|
|
33
|
+
for (const value of values) {
|
|
34
|
+
this.add(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a DecimalSet from an array of values.
|
|
40
|
+
*
|
|
41
|
+
* @param values - Array of values
|
|
42
|
+
* @returns A new DecimalSet
|
|
43
|
+
*/
|
|
44
|
+
static from(values) {
|
|
45
|
+
return new DecimalSet(values);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a DecimalSet from a range of values.
|
|
49
|
+
*
|
|
50
|
+
* @param start - Start value (inclusive)
|
|
51
|
+
* @param end - End value (exclusive)
|
|
52
|
+
* @param step - Step size (default 1)
|
|
53
|
+
* @returns A new DecimalSet
|
|
54
|
+
* @throws If a bound or step is non-finite, the step is zero, or the configured
|
|
55
|
+
* Decimal precision is too low for the step to advance the current value.
|
|
56
|
+
*/
|
|
57
|
+
static range(start, end, step = 1) {
|
|
58
|
+
const result = new DecimalSet();
|
|
59
|
+
const startDec = new decimal_js_1.default(start);
|
|
60
|
+
const endDec = new decimal_js_1.default(end);
|
|
61
|
+
const stepDec = new decimal_js_1.default(step);
|
|
62
|
+
if (!startDec.isFinite() || !endDec.isFinite() || !stepDec.isFinite()) {
|
|
63
|
+
throw new Error('Range values must be finite');
|
|
64
|
+
}
|
|
65
|
+
if (stepDec.isZero()) {
|
|
66
|
+
throw new Error('Step cannot be zero');
|
|
67
|
+
}
|
|
68
|
+
if (stepDec.isPositive()) {
|
|
69
|
+
let current = startDec;
|
|
70
|
+
while (current.lessThan(endDec)) {
|
|
71
|
+
result.add(current);
|
|
72
|
+
const next = current.plus(stepDec);
|
|
73
|
+
if (next.equals(current)) {
|
|
74
|
+
throw new Error('Step does not advance range at current precision');
|
|
75
|
+
}
|
|
76
|
+
current = next;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
let current = startDec;
|
|
81
|
+
while (current.greaterThan(endDec)) {
|
|
82
|
+
result.add(current);
|
|
83
|
+
const next = current.plus(stepDec);
|
|
84
|
+
if (next.equals(current)) {
|
|
85
|
+
throw new Error('Step does not advance range at current precision');
|
|
86
|
+
}
|
|
87
|
+
current = next;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Adds a value to the set.
|
|
94
|
+
*
|
|
95
|
+
* @param value - The value to add
|
|
96
|
+
* @returns The set instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
add(value) {
|
|
99
|
+
const decimal = new decimal_js_1.default(value);
|
|
100
|
+
const key = decimal.toString();
|
|
101
|
+
this.elements.set(key, decimal);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Removes all elements from the set.
|
|
106
|
+
*/
|
|
107
|
+
clear() {
|
|
108
|
+
this.elements.clear();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates a shallow copy of the set.
|
|
112
|
+
*/
|
|
113
|
+
clone() {
|
|
114
|
+
const result = new DecimalSet();
|
|
115
|
+
for (const [key, value] of this.elements) {
|
|
116
|
+
result.elements.set(key, value);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Removes a value from the set.
|
|
122
|
+
*
|
|
123
|
+
* @param value - The value to remove
|
|
124
|
+
* @returns True if the value was present and removed, false otherwise
|
|
125
|
+
*/
|
|
126
|
+
delete(value) {
|
|
127
|
+
const key = new decimal_js_1.default(value).toString();
|
|
128
|
+
return this.elements.delete(key);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new set containing the difference (this \ other).
|
|
132
|
+
*
|
|
133
|
+
* @param other - The other set
|
|
134
|
+
* @returns A new set containing elements in this set but not in the other
|
|
135
|
+
*/
|
|
136
|
+
difference(other) {
|
|
137
|
+
const result = new DecimalSet();
|
|
138
|
+
for (const [key, value] of this.elements) {
|
|
139
|
+
if (!other.elements.has(key)) {
|
|
140
|
+
result.elements.set(key, value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Checks if this set equals another set.
|
|
147
|
+
*
|
|
148
|
+
* @param other - The other set
|
|
149
|
+
* @returns True if both sets contain the same elements
|
|
150
|
+
*/
|
|
151
|
+
equals(other) {
|
|
152
|
+
if (this.size !== other.size) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
for (const key of this.elements.keys()) {
|
|
156
|
+
if (!other.elements.has(key)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Tests whether all elements pass the predicate test.
|
|
164
|
+
*
|
|
165
|
+
* @param predicate - Function to test each element
|
|
166
|
+
* @returns True if all elements pass the test
|
|
167
|
+
*/
|
|
168
|
+
every(predicate) {
|
|
169
|
+
for (const value of this.elements.values()) {
|
|
170
|
+
if (!predicate(value)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Filters the set based on a predicate function.
|
|
178
|
+
*
|
|
179
|
+
* @param predicate - Function to test each element
|
|
180
|
+
* @returns A new set containing only elements that pass the test
|
|
181
|
+
*/
|
|
182
|
+
filter(predicate) {
|
|
183
|
+
const result = new DecimalSet();
|
|
184
|
+
for (const [key, value] of this.elements) {
|
|
185
|
+
if (predicate(value)) {
|
|
186
|
+
result.elements.set(key, value);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Executes a callback for each element in the set.
|
|
193
|
+
*
|
|
194
|
+
* @param callback - Function to execute for each element
|
|
195
|
+
* @param thisArg - Value to use as 'this' when executing callback
|
|
196
|
+
*/
|
|
197
|
+
forEach(callback, thisArg) {
|
|
198
|
+
for (const value of this.elements.values()) {
|
|
199
|
+
callback.call(thisArg, value, value, this);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Checks if a value is in the set.
|
|
204
|
+
*
|
|
205
|
+
* @param value - The value to check
|
|
206
|
+
* @returns True if the value is in the set
|
|
207
|
+
*/
|
|
208
|
+
has(value) {
|
|
209
|
+
const key = new decimal_js_1.default(value).toString();
|
|
210
|
+
return this.elements.has(key);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Creates a new set containing the intersection of this set and another.
|
|
214
|
+
*
|
|
215
|
+
* @param other - The other set
|
|
216
|
+
* @returns A new set containing only elements present in both sets
|
|
217
|
+
*/
|
|
218
|
+
intersection(other) {
|
|
219
|
+
const result = new DecimalSet();
|
|
220
|
+
// Iterate over the smaller set for better performance
|
|
221
|
+
const [smaller, larger] = this.size <= other.size ? [this, other] : [other, this];
|
|
222
|
+
for (const [key, value] of smaller.elements) {
|
|
223
|
+
if (larger.elements.has(key)) {
|
|
224
|
+
result.elements.set(key, value);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Checks if this set is disjoint with another set.
|
|
231
|
+
*
|
|
232
|
+
* @param other - The other set
|
|
233
|
+
* @returns True if the sets have no elements in common
|
|
234
|
+
*/
|
|
235
|
+
isDisjointFrom(other) {
|
|
236
|
+
// Iterate over the smaller set for better performance
|
|
237
|
+
const [smaller, larger] = this.size <= other.size ? [this, other] : [other, this];
|
|
238
|
+
for (const key of smaller.elements.keys()) {
|
|
239
|
+
if (larger.elements.has(key)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Checks if the set is empty.
|
|
247
|
+
*/
|
|
248
|
+
isEmpty() {
|
|
249
|
+
return this.elements.size === 0;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Checks if this set is a proper subset of another set.
|
|
253
|
+
*
|
|
254
|
+
* @param other - The other set
|
|
255
|
+
* @returns True if this is a subset but not equal to the other set
|
|
256
|
+
*/
|
|
257
|
+
isProperSubsetOf(other) {
|
|
258
|
+
return this.size < other.size && this.isSubsetOf(other);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Checks if this set is a proper superset of another set.
|
|
262
|
+
*
|
|
263
|
+
* @param other - The other set
|
|
264
|
+
* @returns True if this is a superset but not equal to the other set
|
|
265
|
+
*/
|
|
266
|
+
isProperSupersetOf(other) {
|
|
267
|
+
return this.size > other.size && this.isSupersetOf(other);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Checks if this set is a subset of another set.
|
|
271
|
+
*
|
|
272
|
+
* @param other - The other set
|
|
273
|
+
* @returns True if all elements of this set are in the other set
|
|
274
|
+
*/
|
|
275
|
+
isSubsetOf(other) {
|
|
276
|
+
if (this.size > other.size) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
for (const key of this.elements.keys()) {
|
|
280
|
+
if (!other.elements.has(key)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Checks if this set is a superset of another set.
|
|
288
|
+
*
|
|
289
|
+
* @param other - The other set
|
|
290
|
+
* @returns True if all elements of the other set are in this set
|
|
291
|
+
*/
|
|
292
|
+
isSupersetOf(other) {
|
|
293
|
+
return other.isSubsetOf(this);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Maps each element to a new value using a transform function.
|
|
297
|
+
*
|
|
298
|
+
* @param transform - Function to transform each element
|
|
299
|
+
* @returns A new set containing the transformed elements
|
|
300
|
+
*/
|
|
301
|
+
map(transform) {
|
|
302
|
+
const result = new DecimalSet();
|
|
303
|
+
for (const value of this.elements.values()) {
|
|
304
|
+
result.add(transform(value));
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Returns the maximum value in the set.
|
|
310
|
+
*
|
|
311
|
+
* @returns The maximum value, or undefined if the set is empty
|
|
312
|
+
*/
|
|
313
|
+
max() {
|
|
314
|
+
if (this.elements.size === 0) {
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
let maxValue;
|
|
318
|
+
for (const value of this.elements.values()) {
|
|
319
|
+
if (maxValue === undefined || value.greaterThan(maxValue)) {
|
|
320
|
+
maxValue = value;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return maxValue;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Returns the minimum value in the set.
|
|
327
|
+
*
|
|
328
|
+
* @returns The minimum value, or undefined if the set is empty
|
|
329
|
+
*/
|
|
330
|
+
min() {
|
|
331
|
+
if (this.elements.size === 0) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
let minValue;
|
|
335
|
+
for (const value of this.elements.values()) {
|
|
336
|
+
if (minValue === undefined || value.lessThan(minValue)) {
|
|
337
|
+
minValue = value;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return minValue;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Returns the number of elements in the set.
|
|
344
|
+
*/
|
|
345
|
+
get size() {
|
|
346
|
+
return this.elements.size;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Tests whether some element passes the predicate test.
|
|
350
|
+
*
|
|
351
|
+
* @param predicate - Function to test each element
|
|
352
|
+
* @returns True if at least one element passes the test
|
|
353
|
+
*/
|
|
354
|
+
some(predicate) {
|
|
355
|
+
for (const value of this.elements.values()) {
|
|
356
|
+
if (predicate(value)) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Returns the sum of all values in the set.
|
|
364
|
+
*
|
|
365
|
+
* @returns The sum, or zero if the set is empty
|
|
366
|
+
*/
|
|
367
|
+
sum() {
|
|
368
|
+
let total = new decimal_js_1.default(0);
|
|
369
|
+
for (const value of this.elements.values()) {
|
|
370
|
+
total = total.plus(value);
|
|
371
|
+
}
|
|
372
|
+
return total;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Returns an iterator over the values in the set (same as values()).
|
|
376
|
+
*/
|
|
377
|
+
*[Symbol.iterator]() {
|
|
378
|
+
yield* this.values();
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Creates a new set containing the symmetric difference.
|
|
382
|
+
*
|
|
383
|
+
* @param other - The other set
|
|
384
|
+
* @returns A new set containing elements in either set but not both
|
|
385
|
+
*/
|
|
386
|
+
symmetricDifference(other) {
|
|
387
|
+
const result = new DecimalSet();
|
|
388
|
+
for (const [key, value] of this.elements) {
|
|
389
|
+
if (!other.elements.has(key)) {
|
|
390
|
+
result.elements.set(key, value);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
for (const [key, value] of other.elements) {
|
|
394
|
+
if (!this.elements.has(key)) {
|
|
395
|
+
result.elements.set(key, value);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Converts the set to an array.
|
|
402
|
+
*/
|
|
403
|
+
toArray() {
|
|
404
|
+
return Array.from(this.elements.values());
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Returns a sorted array of the set's elements.
|
|
408
|
+
*
|
|
409
|
+
* @param compareFn - Optional comparison function
|
|
410
|
+
* @returns Sorted array of elements
|
|
411
|
+
*/
|
|
412
|
+
toSorted(compareFn) {
|
|
413
|
+
const array = this.toArray();
|
|
414
|
+
if (compareFn) {
|
|
415
|
+
return array.sort(compareFn);
|
|
416
|
+
}
|
|
417
|
+
return array.sort((a, b) => a.comparedTo(b));
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Creates a string representation of the set.
|
|
421
|
+
*/
|
|
422
|
+
toString() {
|
|
423
|
+
const elements = this.toSorted()
|
|
424
|
+
.map(d => d.toString())
|
|
425
|
+
.join(', ');
|
|
426
|
+
return `DecimalSet { ${elements} }`;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Creates a new set containing the union of this set and another.
|
|
430
|
+
*
|
|
431
|
+
* @param other - The other set
|
|
432
|
+
* @returns A new set containing all elements from both sets
|
|
433
|
+
*/
|
|
434
|
+
union(other) {
|
|
435
|
+
const result = new DecimalSet();
|
|
436
|
+
for (const [key, value] of this.elements) {
|
|
437
|
+
result.elements.set(key, value);
|
|
438
|
+
}
|
|
439
|
+
for (const [key, value] of other.elements) {
|
|
440
|
+
result.elements.set(key, value);
|
|
441
|
+
}
|
|
442
|
+
return result;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Returns an iterator over the values in the set.
|
|
446
|
+
*/
|
|
447
|
+
*values() {
|
|
448
|
+
for (const decimal of this.elements.values()) {
|
|
449
|
+
yield decimal;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
exports.DecimalSet = DecimalSet;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { StructuredEntity } from '../../common/classes/StructuredEntity';
|
|
2
|
+
import { DICTIONARY } from '../parser/constants';
|
|
3
|
+
import type { ParserEntity } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* A key-value container where keys are strings (variable names) and values
|
|
6
|
+
* are any ParserEntity. Supports element-wise arithmetic operations.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The optional constructor Map is retained rather than copied. {@link set} and
|
|
10
|
+
* {@link merge} also retain value references, while {@link copy} copies every
|
|
11
|
+
* stored parser entity. Arrays returned by {@link keys}, {@link values}, and
|
|
12
|
+
* {@link entries} are new arrays, but their values still refer to the stored
|
|
13
|
+
* entities.
|
|
14
|
+
*
|
|
15
|
+
* Iteration and text output preserve Map insertion order. Replacing an existing
|
|
16
|
+
* key does not move it. {@link each} can replace values in place; returning
|
|
17
|
+
* nothing from its callback leaves a value unchanged. Use {@link forEach} for
|
|
18
|
+
* observation-only traversal. Evaluation and expansion return deep copies.
|
|
19
|
+
* Dictionaries support structural equality by key and value but define no
|
|
20
|
+
* greater-than or less-than ordering.
|
|
21
|
+
*
|
|
22
|
+
* Syntax: {x => 1, y => 2, z => x+3}
|
|
23
|
+
* Access: d[x] → 1, d[y] → 2
|
|
24
|
+
* Assign: d[y]: 10
|
|
25
|
+
*/
|
|
26
|
+
export declare class Dictionary extends StructuredEntity<Dictionary> {
|
|
27
|
+
/**
|
|
28
|
+
* Internal storage. The ordered map preserves insertion order for
|
|
29
|
+
* deterministic iteration and text output.
|
|
30
|
+
*/
|
|
31
|
+
private _entries;
|
|
32
|
+
dataType: typeof DICTIONARY;
|
|
33
|
+
isEnumerable: boolean;
|
|
34
|
+
precision?: number | undefined;
|
|
35
|
+
/** Creates a Dictionary, retaining the supplied Map when present. */
|
|
36
|
+
constructor(entries?: Map<string, ParserEntity>);
|
|
37
|
+
static isDictionary(obj: unknown): obj is Dictionary;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the element for the given string key.
|
|
40
|
+
* Used by the parser for bracket indexing: d[x] → d.getter('x')
|
|
41
|
+
*/
|
|
42
|
+
__get__(indices: number[] | string): ParserEntity;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the element for the given string key.
|
|
45
|
+
* Used by the parser for bracket assignment: d[x]: 5
|
|
46
|
+
*/
|
|
47
|
+
__set__(indices: number[] | string, value: ParserEntity): void;
|
|
48
|
+
/** Copies the Dictionary, including every stored value. */
|
|
49
|
+
copy(): Dictionary;
|
|
50
|
+
/** Number of entries. */
|
|
51
|
+
count(): number;
|
|
52
|
+
/** Removes a key-value pair. */
|
|
53
|
+
delete(key: string): boolean;
|
|
54
|
+
dimensions(): number[];
|
|
55
|
+
/**
|
|
56
|
+
* Visits or replaces entries in insertion order.
|
|
57
|
+
*
|
|
58
|
+
* Returning a ParserEntity replaces the current value. Returning `void` leaves
|
|
59
|
+
* that value unchanged, so callers can inspect a Dictionary without a dummy return.
|
|
60
|
+
* The callback receives the value and string key.
|
|
61
|
+
*/
|
|
62
|
+
each(callback: (e: ParserEntity, i?: string | number, j?: string | number) => ParserEntity | void): Dictionary;
|
|
63
|
+
/**
|
|
64
|
+
* Satisfies the StructuredEntity abstract property.
|
|
65
|
+
* Returns the values as an array for compatibility with element-wise operations.
|
|
66
|
+
*/
|
|
67
|
+
get elements(): ParserEntity[];
|
|
68
|
+
set elements(values: ParserEntity[]);
|
|
69
|
+
/**
|
|
70
|
+
* Returns all entries in insertion order as a new pair array.
|
|
71
|
+
* Stored value objects are not copied.
|
|
72
|
+
*/
|
|
73
|
+
entries(): [string, ParserEntity][];
|
|
74
|
+
eq(other: ParserEntity): boolean;
|
|
75
|
+
/** Evaluates a copied Dictionary, leaving this one unchanged. */
|
|
76
|
+
evaluate(): Dictionary;
|
|
77
|
+
expand(): Dictionary;
|
|
78
|
+
/** Visits stored value references without changing the Dictionary. */
|
|
79
|
+
forEach(callback: (value: ParserEntity, key: string) => void): void;
|
|
80
|
+
/** Gets the stored value reference by key, or `undefined` when absent. */
|
|
81
|
+
get(key: string): ParserEntity | undefined;
|
|
82
|
+
gt(_other: ParserEntity): boolean;
|
|
83
|
+
gte(other: ParserEntity): boolean;
|
|
84
|
+
/** Checks if a key exists. */
|
|
85
|
+
has(key: string): boolean;
|
|
86
|
+
/** Returns all keys. */
|
|
87
|
+
keys(): string[];
|
|
88
|
+
lt(_other: ParserEntity): boolean;
|
|
89
|
+
lte(other: ParserEntity): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Merges another Dictionary into this one. Existing keys are overwritten and
|
|
92
|
+
* incoming value references are retained.
|
|
93
|
+
*/
|
|
94
|
+
merge(other: Dictionary): Dictionary;
|
|
95
|
+
/** Sets a key-value pair by reference and returns this Dictionary. */
|
|
96
|
+
set(key: string, value: ParserEntity): Dictionary;
|
|
97
|
+
/** Iterates over `[key, value]` pairs in insertion order. */
|
|
98
|
+
[Symbol.iterator](): IterableIterator<[string, ParserEntity]>;
|
|
99
|
+
text(): string;
|
|
100
|
+
/** Returns stored value references in insertion order in a new array. */
|
|
101
|
+
values(): ParserEntity[];
|
|
102
|
+
}
|