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,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dictionary = void 0;
|
|
4
|
+
const StructuredEntity_1 = require("../../common/classes/StructuredEntity");
|
|
5
|
+
const common_1 = require("../../common/common");
|
|
6
|
+
const errors_1 = require("../../errors");
|
|
7
|
+
const constants_1 = require("../parser/constants");
|
|
8
|
+
/**
|
|
9
|
+
* A key-value container where keys are strings (variable names) and values
|
|
10
|
+
* are any ParserEntity. Supports element-wise arithmetic operations.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* The optional constructor Map is retained rather than copied. {@link set} and
|
|
14
|
+
* {@link merge} also retain value references, while {@link copy} copies every
|
|
15
|
+
* stored parser entity. Arrays returned by {@link keys}, {@link values}, and
|
|
16
|
+
* {@link entries} are new arrays, but their values still refer to the stored
|
|
17
|
+
* entities.
|
|
18
|
+
*
|
|
19
|
+
* Iteration and text output preserve Map insertion order. Replacing an existing
|
|
20
|
+
* key does not move it. {@link each} can replace values in place; returning
|
|
21
|
+
* nothing from its callback leaves a value unchanged. Use {@link forEach} for
|
|
22
|
+
* observation-only traversal. Evaluation and expansion return deep copies.
|
|
23
|
+
* Dictionaries support structural equality by key and value but define no
|
|
24
|
+
* greater-than or less-than ordering.
|
|
25
|
+
*
|
|
26
|
+
* Syntax: {x => 1, y => 2, z => x+3}
|
|
27
|
+
* Access: d[x] → 1, d[y] → 2
|
|
28
|
+
* Assign: d[y]: 10
|
|
29
|
+
*/
|
|
30
|
+
class Dictionary extends StructuredEntity_1.StructuredEntity {
|
|
31
|
+
/**
|
|
32
|
+
* Internal storage. The ordered map preserves insertion order for
|
|
33
|
+
* deterministic iteration and text output.
|
|
34
|
+
*/
|
|
35
|
+
_entries = new Map();
|
|
36
|
+
dataType = constants_1.DICTIONARY;
|
|
37
|
+
isEnumerable = true;
|
|
38
|
+
precision;
|
|
39
|
+
/** Creates a Dictionary, retaining the supplied Map when present. */
|
|
40
|
+
constructor(entries) {
|
|
41
|
+
super();
|
|
42
|
+
if (entries) {
|
|
43
|
+
this._entries = entries;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static isDictionary(obj) {
|
|
47
|
+
return (0, common_1.isNerdamerNativeType)(obj, constants_1.DICTIONARY);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the element for the given string key.
|
|
51
|
+
* Used by the parser for bracket indexing: d[x] → d.getter('x')
|
|
52
|
+
*/
|
|
53
|
+
__get__(indices) {
|
|
54
|
+
const key = typeof indices === 'string' ? indices : String(indices[0]);
|
|
55
|
+
const value = this._entries.get(key);
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
throw new errors_1.UnexpectedDataType(`Key "${key}" not found in Dictionary. Available keys: ${this.keys().join(', ')}`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the element for the given string key.
|
|
63
|
+
* Used by the parser for bracket assignment: d[x]: 5
|
|
64
|
+
*/
|
|
65
|
+
__set__(indices, value) {
|
|
66
|
+
const key = typeof indices === 'string' ? indices : String(indices[0]);
|
|
67
|
+
this._entries.set(key, value);
|
|
68
|
+
}
|
|
69
|
+
/** Copies the Dictionary, including every stored value. */
|
|
70
|
+
copy() {
|
|
71
|
+
const entries = new Map();
|
|
72
|
+
for (const [key, value] of this._entries) {
|
|
73
|
+
entries.set(key, value.copy());
|
|
74
|
+
}
|
|
75
|
+
return new Dictionary(entries);
|
|
76
|
+
}
|
|
77
|
+
/** Number of entries. */
|
|
78
|
+
count() {
|
|
79
|
+
return this._entries.size;
|
|
80
|
+
}
|
|
81
|
+
/** Removes a key-value pair. */
|
|
82
|
+
delete(key) {
|
|
83
|
+
return this._entries.delete(key);
|
|
84
|
+
}
|
|
85
|
+
dimensions() {
|
|
86
|
+
return [this._entries.size];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Visits or replaces entries in insertion order.
|
|
90
|
+
*
|
|
91
|
+
* Returning a ParserEntity replaces the current value. Returning `void` leaves
|
|
92
|
+
* that value unchanged, so callers can inspect a Dictionary without a dummy return.
|
|
93
|
+
* The callback receives the value and string key.
|
|
94
|
+
*/
|
|
95
|
+
each(callback) {
|
|
96
|
+
for (const [key, value] of this._entries) {
|
|
97
|
+
const result = callback(value, key);
|
|
98
|
+
if (result !== undefined) {
|
|
99
|
+
this._entries.set(key, result);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Satisfies the StructuredEntity abstract property.
|
|
106
|
+
* Returns the values as an array for compatibility with element-wise operations.
|
|
107
|
+
*/
|
|
108
|
+
get elements() {
|
|
109
|
+
return [...this._entries.values()];
|
|
110
|
+
}
|
|
111
|
+
set elements(values) {
|
|
112
|
+
// When StructuredEntity.binaryOp calls copy().each(...), the each method
|
|
113
|
+
// mutates values in place via the keys, so this setter is mainly for
|
|
114
|
+
// structural compatibility. Rebuild from existing keys.
|
|
115
|
+
const keys = [...this._entries.keys()];
|
|
116
|
+
this._entries.clear();
|
|
117
|
+
for (let i = 0; i < keys.length && i < values.length; i++) {
|
|
118
|
+
this._entries.set(keys[i], values[i]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns all entries in insertion order as a new pair array.
|
|
123
|
+
* Stored value objects are not copied.
|
|
124
|
+
*/
|
|
125
|
+
entries() {
|
|
126
|
+
return [...this._entries.entries()];
|
|
127
|
+
}
|
|
128
|
+
eq(other) {
|
|
129
|
+
if (!Dictionary.isDictionary(other)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (this._entries.size !== other._entries.size) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
for (const [key, value] of this._entries) {
|
|
136
|
+
const otherValue = other._entries.get(key);
|
|
137
|
+
if (!otherValue || !value.eq(otherValue)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
/** Evaluates a copied Dictionary, leaving this one unchanged. */
|
|
144
|
+
evaluate() {
|
|
145
|
+
return this.copy().each(e => e.evaluate());
|
|
146
|
+
}
|
|
147
|
+
expand() {
|
|
148
|
+
const copy = this.copy();
|
|
149
|
+
copy.each(e => e.expand());
|
|
150
|
+
return copy;
|
|
151
|
+
}
|
|
152
|
+
/** Visits stored value references without changing the Dictionary. */
|
|
153
|
+
forEach(callback) {
|
|
154
|
+
for (const [key, value] of this._entries) {
|
|
155
|
+
callback(value, key);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** Gets the stored value reference by key, or `undefined` when absent. */
|
|
159
|
+
get(key) {
|
|
160
|
+
return this._entries.get(key);
|
|
161
|
+
}
|
|
162
|
+
gt(_other) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
gte(other) {
|
|
166
|
+
return this.eq(other);
|
|
167
|
+
}
|
|
168
|
+
/** Checks if a key exists. */
|
|
169
|
+
has(key) {
|
|
170
|
+
return this._entries.has(key);
|
|
171
|
+
}
|
|
172
|
+
/** Returns all keys. */
|
|
173
|
+
keys() {
|
|
174
|
+
return [...this._entries.keys()];
|
|
175
|
+
}
|
|
176
|
+
lt(_other) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
lte(other) {
|
|
180
|
+
return this.eq(other);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Merges another Dictionary into this one. Existing keys are overwritten and
|
|
184
|
+
* incoming value references are retained.
|
|
185
|
+
*/
|
|
186
|
+
merge(other) {
|
|
187
|
+
for (const [key, value] of other._entries) {
|
|
188
|
+
this._entries.set(key, value);
|
|
189
|
+
}
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/** Sets a key-value pair by reference and returns this Dictionary. */
|
|
193
|
+
set(key, value) {
|
|
194
|
+
this._entries.set(key, value);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/** Iterates over `[key, value]` pairs in insertion order. */
|
|
198
|
+
[Symbol.iterator]() {
|
|
199
|
+
return this._entries[Symbol.iterator]();
|
|
200
|
+
}
|
|
201
|
+
text() {
|
|
202
|
+
const pairs = [];
|
|
203
|
+
for (const [key, value] of this._entries) {
|
|
204
|
+
pairs.push(`${key} => ${value.text()}`);
|
|
205
|
+
}
|
|
206
|
+
return `{${pairs.join(', ')}}`;
|
|
207
|
+
}
|
|
208
|
+
/** Returns stored value references in insertion order in a new array. */
|
|
209
|
+
values() {
|
|
210
|
+
return [...this._entries.values()];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.Dictionary = Dictionary;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Expression } from '../expression/Expression';
|
|
2
|
+
import { EQUATION } from '../parser/constants';
|
|
3
|
+
import type { ExpressionInput, ParserEntity } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a symbolic equality between two expression sides.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* An `Equation` stores its left- and right-hand sides as public {@link Expression}
|
|
9
|
+
* references. The constructor does not copy those expressions, so mutating a supplied
|
|
10
|
+
* expression later, or mutating {@link Equation.LHS} or {@link Equation.RHS} directly,
|
|
11
|
+
* changes the equation. Use {@link Equation.copy} when an independent equation is needed.
|
|
12
|
+
*
|
|
13
|
+
* Arithmetic methods apply an operation to both sides, but that does not by itself prove
|
|
14
|
+
* that the transformed equation has exactly the same solution set. For example, multiplying
|
|
15
|
+
* or dividing by an expression whose value may be zero requires additional domain reasoning.
|
|
16
|
+
* Solver-facing code should account for those mathematical conditions.
|
|
17
|
+
*
|
|
18
|
+
* Absolute value is not supported as an equation rewrite because applying it
|
|
19
|
+
* independently to both sides can change the solution set. {@link Equation.abs} remains only
|
|
20
|
+
* as a compatibility member of the general parser-entity surface and always throws. Callers
|
|
21
|
+
* performing a non-equivalent transformation can use {@link Equation.each} explicitly.
|
|
22
|
+
*
|
|
23
|
+
* Equation comparisons reduce each equation to its residual `LHS - RHS` and then use the
|
|
24
|
+
* corresponding {@link Expression} comparison. They compare those residual expressions;
|
|
25
|
+
* they do not establish logical or solution-set equivalence between arbitrary equations.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const equation = new Equation(Expression.create('x + 1'), Expression.create(3));
|
|
30
|
+
* equation.text(); // "1+x=3"
|
|
31
|
+
* equation.toLHS().text(); // "-2+x=0"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class Equation {
|
|
35
|
+
/** Parser entity tag used to identify equation values. */
|
|
36
|
+
dataType: typeof EQUATION;
|
|
37
|
+
/** Indicates that equations are not elementwise enumerable parser aggregates. */
|
|
38
|
+
isEnumerable: boolean;
|
|
39
|
+
/** Mutable left-hand side expression stored by this equation. */
|
|
40
|
+
LHS: Expression;
|
|
41
|
+
/**
|
|
42
|
+
* Optional parser-entity precision metadata.
|
|
43
|
+
*
|
|
44
|
+
* `Equation` itself does not currently use this value when performing equation
|
|
45
|
+
* operations or formatting its sides.
|
|
46
|
+
*/
|
|
47
|
+
precision?: number | undefined;
|
|
48
|
+
/** Mutable right-hand side expression stored by this equation. */
|
|
49
|
+
RHS: Expression;
|
|
50
|
+
/**
|
|
51
|
+
* Creates an equation from two expression objects.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* The supplied expressions are stored by reference rather than copied. This preserves
|
|
55
|
+
* object identity but also means subsequent mutation of either expression is visible
|
|
56
|
+
* through the equation.
|
|
57
|
+
*
|
|
58
|
+
* @param lhs - Expression to store on the left-hand side.
|
|
59
|
+
* @param rhs - Expression to store on the right-hand side.
|
|
60
|
+
*/
|
|
61
|
+
constructor(lhs: Expression, rhs: Expression);
|
|
62
|
+
/**
|
|
63
|
+
* Tests whether a value carries Nerdamer's equation parser-entity tag.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* This is a tag-based type guard rather than an `instanceof` check. It therefore
|
|
67
|
+
* recognizes compatible equation objects by their `dataType` value.
|
|
68
|
+
*
|
|
69
|
+
* @param obj - Value to inspect.
|
|
70
|
+
* @returns `true` when the value is tagged as an equation.
|
|
71
|
+
*/
|
|
72
|
+
static isEquation(obj: unknown): obj is Equation;
|
|
73
|
+
/**
|
|
74
|
+
* Rejects absolute value as an equation transformation.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Replacing `a = b` with `|a| = |b|` is not generally solution-set preserving. This
|
|
78
|
+
* method remains on `Equation` so the general {@link ParserEntity} surface can retain
|
|
79
|
+
* its historical `abs()` member without reintroducing the unsafe transformation.
|
|
80
|
+
*
|
|
81
|
+
* Use {@link Equation.each} explicitly to transform
|
|
82
|
+
* each side and accepts responsibility for the changed equation semantics.
|
|
83
|
+
*
|
|
84
|
+
* @throws {@link core!UnsupportedOperationError} Always; absolute value is not a supported
|
|
85
|
+
* equation operation.
|
|
86
|
+
* @deprecated Absolute value is not supported for equations.
|
|
87
|
+
*/
|
|
88
|
+
abs(): Equation;
|
|
89
|
+
/**
|
|
90
|
+
* Legacy alias for {@link Equation.plus}.
|
|
91
|
+
*
|
|
92
|
+
* @param x - Value to add to both sides.
|
|
93
|
+
* @returns A new equation; the current equation is not modified.
|
|
94
|
+
*/
|
|
95
|
+
add(x: ExpressionInput): Equation;
|
|
96
|
+
/**
|
|
97
|
+
* Creates an independent copy of this equation and both expression sides.
|
|
98
|
+
*
|
|
99
|
+
* @returns A new equation whose left- and right-hand expressions are deep copies.
|
|
100
|
+
*/
|
|
101
|
+
copy(): Equation;
|
|
102
|
+
/**
|
|
103
|
+
* Divides both sides by the same nonzero number.
|
|
104
|
+
*
|
|
105
|
+
* A symbolic divisor is rejected because Nerdamer cannot assume that it is nonzero for
|
|
106
|
+
* every solution of the equation.
|
|
107
|
+
*
|
|
108
|
+
* @param x - Nonzero numeric value by which both sides are divided.
|
|
109
|
+
* @returns A new equation; the current equation is not modified.
|
|
110
|
+
* @throws {@link core!UnsupportedOperationError} If `x` is zero or is not numeric.
|
|
111
|
+
*/
|
|
112
|
+
div(x: ExpressionInput): Equation;
|
|
113
|
+
/**
|
|
114
|
+
* Applies a callback to the two equation sides and rebuilds the equation from its results.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* The callback receives the stored left- and right-hand {@link Expression} references
|
|
118
|
+
* directly, with indices `0` and `1` respectively. Returned expressions are stored by
|
|
119
|
+
* reference in a new equation. The callback can therefore mutate the original equation
|
|
120
|
+
* if it mutates either argument before returning.
|
|
121
|
+
*
|
|
122
|
+
* Both callback results must be expressions. Other parser entities are rejected after
|
|
123
|
+
* the callback has run.
|
|
124
|
+
*
|
|
125
|
+
* @param fn - Transformation applied to the left and right sides.
|
|
126
|
+
* @returns A new equation containing the callback results.
|
|
127
|
+
* @throws {@link core!UnexpectedDataType}
|
|
128
|
+
* Thrown when either callback result is not an {@link Expression}.
|
|
129
|
+
*/
|
|
130
|
+
each(fn: (e: ParserEntity, i?: number | string) => ParserEntity): Equation;
|
|
131
|
+
/**
|
|
132
|
+
* Compares this equation with another equation by comparing their residual expressions.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Each equation is copied and rewritten as `LHS - RHS = 0`, then the two residual
|
|
136
|
+
* expressions are compared with {@link Expression.eq}. Equations with the same
|
|
137
|
+
* solution set are not necessarily equal by this method; for example, scaling an
|
|
138
|
+
* equation by a nonzero constant changes its residual expression.
|
|
139
|
+
*
|
|
140
|
+
* @param eq - Parser entity to compare with this equation.
|
|
141
|
+
* @returns `true` when `eq` is an equation and the two residual expressions compare equal.
|
|
142
|
+
*/
|
|
143
|
+
eq(eq: ParserEntity): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Numerically re-evaluates both equation sides.
|
|
146
|
+
*
|
|
147
|
+
* @returns A new equation containing evaluated copies of the two sides.
|
|
148
|
+
*/
|
|
149
|
+
evaluate(): Equation;
|
|
150
|
+
/**
|
|
151
|
+
* Expands both sides of a copied equation.
|
|
152
|
+
*
|
|
153
|
+
* @returns A new equation containing the expanded left- and right-hand sides.
|
|
154
|
+
*/
|
|
155
|
+
expand(): Equation;
|
|
156
|
+
/**
|
|
157
|
+
* Orders this equation against another equation by comparing their residual expressions.
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* Both equations are rewritten as `LHS - RHS = 0`, and the resulting expressions are
|
|
161
|
+
* compared with {@link Expression.gt}. This is an ordering of residual expressions,
|
|
162
|
+
* not a statement that one equation or solution set is logically greater than another.
|
|
163
|
+
*
|
|
164
|
+
* @param eq - Parser entity to compare with this equation.
|
|
165
|
+
* @returns `true` when `eq` is an equation and this residual compares greater.
|
|
166
|
+
*/
|
|
167
|
+
gt(eq: ParserEntity): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Residual-expression comparison corresponding to `>=`.
|
|
170
|
+
*
|
|
171
|
+
* @param x - Parser entity to compare with this equation.
|
|
172
|
+
* @returns `true` when {@link Equation.gt} or {@link Equation.eq} succeeds.
|
|
173
|
+
*/
|
|
174
|
+
gte(x: ParserEntity): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Orders this equation against another equation by comparing their residual expressions.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Both equations are rewritten as `LHS - RHS = 0`, and the resulting expressions are
|
|
180
|
+
* compared with {@link Expression.lt}. This is an ordering of residual expressions,
|
|
181
|
+
* not a statement that one equation or solution set is logically less than another.
|
|
182
|
+
*
|
|
183
|
+
* @param eq - Parser entity to compare with this equation.
|
|
184
|
+
* @returns `true` when `eq` is an equation and this residual compares less.
|
|
185
|
+
*/
|
|
186
|
+
lt(eq: ParserEntity): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Residual-expression comparison corresponding to `<=`.
|
|
189
|
+
*
|
|
190
|
+
* @param x - Parser entity to compare with this equation.
|
|
191
|
+
* @returns `true` when {@link Equation.lt} or {@link Equation.eq} succeeds.
|
|
192
|
+
*/
|
|
193
|
+
lte(x: ParserEntity): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Subtracts the same value from both sides.
|
|
196
|
+
*
|
|
197
|
+
* @param x - Value to subtract from the left- and right-hand sides.
|
|
198
|
+
* @returns A new equation; the current equation is not modified.
|
|
199
|
+
*/
|
|
200
|
+
minus(x: ExpressionInput): Equation;
|
|
201
|
+
/**
|
|
202
|
+
* Legacy alias for {@link Equation.times}.
|
|
203
|
+
*
|
|
204
|
+
* @param x - Nonzero numeric value by which both sides are multiplied.
|
|
205
|
+
* @returns This equation after mutation.
|
|
206
|
+
*/
|
|
207
|
+
multiply(x: ExpressionInput): Equation;
|
|
208
|
+
/**
|
|
209
|
+
* Adds the same value to both sides.
|
|
210
|
+
*
|
|
211
|
+
* @param x - Value to add to the left- and right-hand sides.
|
|
212
|
+
* @returns A new equation; the current equation is not modified.
|
|
213
|
+
*/
|
|
214
|
+
plus(x: ExpressionInput): Equation;
|
|
215
|
+
/**
|
|
216
|
+
* Legacy alias for {@link Equation.minus}.
|
|
217
|
+
*
|
|
218
|
+
* @param x - Value to subtract from both sides.
|
|
219
|
+
* @returns A new equation; the current equation is not modified.
|
|
220
|
+
*/
|
|
221
|
+
subtract(x: ExpressionInput): Equation;
|
|
222
|
+
/**
|
|
223
|
+
* Returns the canonical text form `LHS=RHS`.
|
|
224
|
+
*
|
|
225
|
+
* @returns The two side representations joined by `=`.
|
|
226
|
+
*/
|
|
227
|
+
text(): string;
|
|
228
|
+
/**
|
|
229
|
+
* Multiplies both sides by the same nonzero number.
|
|
230
|
+
*
|
|
231
|
+
* A symbolic multiplier is rejected because it may be zero for some solutions and add
|
|
232
|
+
* solutions that were not present in the original equation.
|
|
233
|
+
*
|
|
234
|
+
* @param x - Nonzero numeric value by which both sides are multiplied.
|
|
235
|
+
* @returns This equation after mutation.
|
|
236
|
+
* @throws {@link core!UnsupportedOperationError} If `x` is zero or is not numeric.
|
|
237
|
+
*/
|
|
238
|
+
times(x: ExpressionInput): Equation;
|
|
239
|
+
/**
|
|
240
|
+
* Rewrites this equation as an equivalent residual form with zero on the right.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* The equation and both sides are copied before `RHS` is subtracted from `LHS`, so the
|
|
244
|
+
* current equation is not modified. The result has the form `LHS - RHS = 0` and is used
|
|
245
|
+
* by solver preparation and the equation comparison methods.
|
|
246
|
+
*
|
|
247
|
+
* @returns A new equation with the residual expression on the left and zero on the right.
|
|
248
|
+
*/
|
|
249
|
+
toLHS(): Equation;
|
|
250
|
+
/**
|
|
251
|
+
* Returns the same canonical equation text as {@link Equation.text}.
|
|
252
|
+
*
|
|
253
|
+
* @returns The equation text representation.
|
|
254
|
+
*/
|
|
255
|
+
toString(): string;
|
|
256
|
+
}
|