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,135 @@
|
|
|
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.Complex = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
/**
|
|
10
|
+
* Represents a numerical complex value backed by `decimal.js` components.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This class is a numerical helper used by algorithms such as polynomial root solving. It is
|
|
14
|
+
* distinct from Nerdamer's symbolic complex expressions: it does not parse expressions, carry
|
|
15
|
+
* symbolic structure, or implement branch-sensitive transcendental functions. Component
|
|
16
|
+
* arithmetic follows the active global `decimal.js` precision.
|
|
17
|
+
*
|
|
18
|
+
* Arithmetic methods return new `Complex` objects rather than modifying the receiver. The
|
|
19
|
+
* {@link Complex.re} and {@link Complex.im} fields are public, however, so callers can reassign
|
|
20
|
+
* components directly.
|
|
21
|
+
*/
|
|
22
|
+
class Complex {
|
|
23
|
+
/** Imaginary component. */
|
|
24
|
+
im;
|
|
25
|
+
/** Real component. */
|
|
26
|
+
re;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a numerical complex value.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Existing Decimal components are retained by reference; numeric inputs are converted to
|
|
32
|
+
* new Decimal values. `decimal.js` arithmetic itself returns new Decimal objects.
|
|
33
|
+
*
|
|
34
|
+
* @param re - Real component.
|
|
35
|
+
* @param im - Imaginary component; defaults to zero.
|
|
36
|
+
*/
|
|
37
|
+
constructor(re, im = 0) {
|
|
38
|
+
this.re = typeof re === 'number' ? new decimal_js_1.default(re) : re;
|
|
39
|
+
this.im = typeof im === 'number' ? new decimal_js_1.default(im) : im;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a numerical complex value from Decimal or native-number components.
|
|
43
|
+
*
|
|
44
|
+
* @param re - Real component.
|
|
45
|
+
* @param im - Imaginary component; defaults to zero.
|
|
46
|
+
* @returns A new `Complex` value.
|
|
47
|
+
*/
|
|
48
|
+
static create(re, im = 0) {
|
|
49
|
+
return new Complex(re instanceof decimal_js_1.default ? re : new decimal_js_1.default(re), im instanceof decimal_js_1.default ? im : new decimal_js_1.default(im));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Computes the modulus `sqrt(re^2 + im^2)`.
|
|
53
|
+
*
|
|
54
|
+
* @returns A new Decimal containing the nonnegative magnitude.
|
|
55
|
+
*/
|
|
56
|
+
abs() {
|
|
57
|
+
return this.re.mul(this.re).plus(this.im.mul(this.im)).sqrt();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Adds another complex value component-wise.
|
|
61
|
+
*
|
|
62
|
+
* @param other - Complex value to add.
|
|
63
|
+
* @returns A new complex sum.
|
|
64
|
+
*/
|
|
65
|
+
add(other) {
|
|
66
|
+
return new Complex(this.re.plus(other.re), this.im.plus(other.im));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the complex conjugate `re - im*i`.
|
|
70
|
+
*
|
|
71
|
+
* @returns A new complex value with the imaginary component negated.
|
|
72
|
+
*/
|
|
73
|
+
conjugate() {
|
|
74
|
+
return new Complex(this.re, this.im.neg());
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Divides this complex value by another using the standard rectangular formula.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Division rejects an exactly zero squared modulus. No numerical tolerance is applied at
|
|
81
|
+
* this arithmetic layer; iterative algorithms are responsible for choosing any tolerance
|
|
82
|
+
* appropriate to their convergence logic.
|
|
83
|
+
*
|
|
84
|
+
* @param other - Complex divisor.
|
|
85
|
+
* @returns A new complex quotient.
|
|
86
|
+
* @throws {@link core!DivisionByZeroError}
|
|
87
|
+
* Thrown when both components of `other` are exactly zero at the current Decimal value.
|
|
88
|
+
*/
|
|
89
|
+
div(other) {
|
|
90
|
+
const denom = other.re.mul(other.re).plus(other.im.mul(other.im));
|
|
91
|
+
// Exact division by zero is undefined. Numerical tolerances belong to
|
|
92
|
+
// the algorithms using Complex rather than this arithmetic primitive.
|
|
93
|
+
if (denom.isZero()) {
|
|
94
|
+
throw new errors_1.DivisionByZeroError((0, errors_1.message)('divisionByZero'));
|
|
95
|
+
}
|
|
96
|
+
return new Complex(this.re.mul(other.re).plus(this.im.mul(other.im)).div(denom), this.im.mul(other.re).minus(this.re.mul(other.im)).div(denom));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Multiplies two rectangular complex values.
|
|
100
|
+
*
|
|
101
|
+
* @param other - Complex factor.
|
|
102
|
+
* @returns A new complex product.
|
|
103
|
+
*/
|
|
104
|
+
mul(other) {
|
|
105
|
+
return new Complex(this.re.mul(other.re).minus(this.im.mul(other.im)), this.re.mul(other.im).plus(this.im.mul(other.re)));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the additive inverse of this complex value.
|
|
109
|
+
*
|
|
110
|
+
* @returns A new complex value with both components negated.
|
|
111
|
+
*/
|
|
112
|
+
neg() {
|
|
113
|
+
return new Complex(this.re.neg(), this.im.neg());
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Multiplies both complex components by a real scalar.
|
|
117
|
+
*
|
|
118
|
+
* @param s - Decimal or native-number scale factor.
|
|
119
|
+
* @returns A new scaled complex value.
|
|
120
|
+
*/
|
|
121
|
+
scale(s) {
|
|
122
|
+
const scalar = s instanceof decimal_js_1.default ? s : new decimal_js_1.default(s);
|
|
123
|
+
return new Complex(this.re.mul(scalar), this.im.mul(scalar));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Subtracts another complex value component-wise.
|
|
127
|
+
*
|
|
128
|
+
* @param other - Complex value to subtract.
|
|
129
|
+
* @returns A new complex difference.
|
|
130
|
+
*/
|
|
131
|
+
sub(other) {
|
|
132
|
+
return new Complex(this.re.minus(other.re), this.im.minus(other.im));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.Complex = Complex;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* A high-performance set implementation for Decimal.js numbers.
|
|
4
|
+
*
|
|
5
|
+
* This class provides a complete set of operations for working with sets of
|
|
6
|
+
* arbitrary-precision decimal numbers. It uses string representation internally
|
|
7
|
+
* for efficient equality comparison and hashing.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const setA = new DecimalSet([1, 2, 3]);
|
|
12
|
+
* const setB = new DecimalSet([2, 3, 4]);
|
|
13
|
+
* const union = setA.union(setB); // {1, 2, 3, 4}
|
|
14
|
+
* const intersection = setA.intersection(setB); // {2, 3}
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class DecimalSet {
|
|
18
|
+
private readonly elements;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new DecimalSet.
|
|
21
|
+
*
|
|
22
|
+
* @param values - Optional array of values to initialize the set
|
|
23
|
+
*/
|
|
24
|
+
constructor(values?: Iterable<Decimal.Value>);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a DecimalSet from an array of values.
|
|
27
|
+
*
|
|
28
|
+
* @param values - Array of values
|
|
29
|
+
* @returns A new DecimalSet
|
|
30
|
+
*/
|
|
31
|
+
static from(values: Iterable<Decimal.Value>): DecimalSet;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a DecimalSet from a range of values.
|
|
34
|
+
*
|
|
35
|
+
* @param start - Start value (inclusive)
|
|
36
|
+
* @param end - End value (exclusive)
|
|
37
|
+
* @param step - Step size (default 1)
|
|
38
|
+
* @returns A new DecimalSet
|
|
39
|
+
* @throws If a bound or step is non-finite, the step is zero, or the configured
|
|
40
|
+
* Decimal precision is too low for the step to advance the current value.
|
|
41
|
+
*/
|
|
42
|
+
static range(start: Decimal.Value, end: Decimal.Value, step?: Decimal.Value): DecimalSet;
|
|
43
|
+
/**
|
|
44
|
+
* Adds a value to the set.
|
|
45
|
+
*
|
|
46
|
+
* @param value - The value to add
|
|
47
|
+
* @returns The set instance for chaining
|
|
48
|
+
*/
|
|
49
|
+
add(value: Decimal.Value): this;
|
|
50
|
+
/**
|
|
51
|
+
* Removes all elements from the set.
|
|
52
|
+
*/
|
|
53
|
+
clear(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a shallow copy of the set.
|
|
56
|
+
*/
|
|
57
|
+
clone(): DecimalSet;
|
|
58
|
+
/**
|
|
59
|
+
* Removes a value from the set.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to remove
|
|
62
|
+
* @returns True if the value was present and removed, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
delete(value: Decimal.Value): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new set containing the difference (this \ other).
|
|
67
|
+
*
|
|
68
|
+
* @param other - The other set
|
|
69
|
+
* @returns A new set containing elements in this set but not in the other
|
|
70
|
+
*/
|
|
71
|
+
difference(other: DecimalSet): DecimalSet;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if this set equals another set.
|
|
74
|
+
*
|
|
75
|
+
* @param other - The other set
|
|
76
|
+
* @returns True if both sets contain the same elements
|
|
77
|
+
*/
|
|
78
|
+
equals(other: DecimalSet): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Tests whether all elements pass the predicate test.
|
|
81
|
+
*
|
|
82
|
+
* @param predicate - Function to test each element
|
|
83
|
+
* @returns True if all elements pass the test
|
|
84
|
+
*/
|
|
85
|
+
every(predicate: (value: Decimal) => boolean): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Filters the set based on a predicate function.
|
|
88
|
+
*
|
|
89
|
+
* @param predicate - Function to test each element
|
|
90
|
+
* @returns A new set containing only elements that pass the test
|
|
91
|
+
*/
|
|
92
|
+
filter(predicate: (value: Decimal) => boolean): DecimalSet;
|
|
93
|
+
/**
|
|
94
|
+
* Executes a callback for each element in the set.
|
|
95
|
+
*
|
|
96
|
+
* @param callback - Function to execute for each element
|
|
97
|
+
* @param thisArg - Value to use as 'this' when executing callback
|
|
98
|
+
*/
|
|
99
|
+
forEach(callback: (value: Decimal, value2: Decimal, set: DecimalSet) => void, thisArg?: unknown): void;
|
|
100
|
+
/**
|
|
101
|
+
* Checks if a value is in the set.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The value to check
|
|
104
|
+
* @returns True if the value is in the set
|
|
105
|
+
*/
|
|
106
|
+
has(value: Decimal.Value): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Creates a new set containing the intersection of this set and another.
|
|
109
|
+
*
|
|
110
|
+
* @param other - The other set
|
|
111
|
+
* @returns A new set containing only elements present in both sets
|
|
112
|
+
*/
|
|
113
|
+
intersection(other: DecimalSet): DecimalSet;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if this set is disjoint with another set.
|
|
116
|
+
*
|
|
117
|
+
* @param other - The other set
|
|
118
|
+
* @returns True if the sets have no elements in common
|
|
119
|
+
*/
|
|
120
|
+
isDisjointFrom(other: DecimalSet): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the set is empty.
|
|
123
|
+
*/
|
|
124
|
+
isEmpty(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Checks if this set is a proper subset of another set.
|
|
127
|
+
*
|
|
128
|
+
* @param other - The other set
|
|
129
|
+
* @returns True if this is a subset but not equal to the other set
|
|
130
|
+
*/
|
|
131
|
+
isProperSubsetOf(other: DecimalSet): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Checks if this set is a proper superset of another set.
|
|
134
|
+
*
|
|
135
|
+
* @param other - The other set
|
|
136
|
+
* @returns True if this is a superset but not equal to the other set
|
|
137
|
+
*/
|
|
138
|
+
isProperSupersetOf(other: DecimalSet): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Checks if this set is a subset of another set.
|
|
141
|
+
*
|
|
142
|
+
* @param other - The other set
|
|
143
|
+
* @returns True if all elements of this set are in the other set
|
|
144
|
+
*/
|
|
145
|
+
isSubsetOf(other: DecimalSet): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Checks if this set is a superset of another set.
|
|
148
|
+
*
|
|
149
|
+
* @param other - The other set
|
|
150
|
+
* @returns True if all elements of the other set are in this set
|
|
151
|
+
*/
|
|
152
|
+
isSupersetOf(other: DecimalSet): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Maps each element to a new value using a transform function.
|
|
155
|
+
*
|
|
156
|
+
* @param transform - Function to transform each element
|
|
157
|
+
* @returns A new set containing the transformed elements
|
|
158
|
+
*/
|
|
159
|
+
map(transform: (value: Decimal) => Decimal.Value): DecimalSet;
|
|
160
|
+
/**
|
|
161
|
+
* Returns the maximum value in the set.
|
|
162
|
+
*
|
|
163
|
+
* @returns The maximum value, or undefined if the set is empty
|
|
164
|
+
*/
|
|
165
|
+
max(): Decimal | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Returns the minimum value in the set.
|
|
168
|
+
*
|
|
169
|
+
* @returns The minimum value, or undefined if the set is empty
|
|
170
|
+
*/
|
|
171
|
+
min(): Decimal | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Returns the number of elements in the set.
|
|
174
|
+
*/
|
|
175
|
+
get size(): number;
|
|
176
|
+
/**
|
|
177
|
+
* Tests whether some element passes the predicate test.
|
|
178
|
+
*
|
|
179
|
+
* @param predicate - Function to test each element
|
|
180
|
+
* @returns True if at least one element passes the test
|
|
181
|
+
*/
|
|
182
|
+
some(predicate: (value: Decimal) => boolean): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Returns the sum of all values in the set.
|
|
185
|
+
*
|
|
186
|
+
* @returns The sum, or zero if the set is empty
|
|
187
|
+
*/
|
|
188
|
+
sum(): Decimal;
|
|
189
|
+
/**
|
|
190
|
+
* Returns an iterator over the values in the set (same as values()).
|
|
191
|
+
*/
|
|
192
|
+
[Symbol.iterator](): IterableIterator<Decimal>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new set containing the symmetric difference.
|
|
195
|
+
*
|
|
196
|
+
* @param other - The other set
|
|
197
|
+
* @returns A new set containing elements in either set but not both
|
|
198
|
+
*/
|
|
199
|
+
symmetricDifference(other: DecimalSet): DecimalSet;
|
|
200
|
+
/**
|
|
201
|
+
* Converts the set to an array.
|
|
202
|
+
*/
|
|
203
|
+
toArray(): Decimal[];
|
|
204
|
+
/**
|
|
205
|
+
* Returns a sorted array of the set's elements.
|
|
206
|
+
*
|
|
207
|
+
* @param compareFn - Optional comparison function
|
|
208
|
+
* @returns Sorted array of elements
|
|
209
|
+
*/
|
|
210
|
+
toSorted(compareFn?: (a: Decimal, b: Decimal) => number): Decimal[];
|
|
211
|
+
/**
|
|
212
|
+
* Creates a string representation of the set.
|
|
213
|
+
*/
|
|
214
|
+
toString(): string;
|
|
215
|
+
/**
|
|
216
|
+
* Creates a new set containing the union of this set and another.
|
|
217
|
+
*
|
|
218
|
+
* @param other - The other set
|
|
219
|
+
* @returns A new set containing all elements from both sets
|
|
220
|
+
*/
|
|
221
|
+
union(other: DecimalSet): DecimalSet;
|
|
222
|
+
/**
|
|
223
|
+
* Returns an iterator over the values in the set.
|
|
224
|
+
*/
|
|
225
|
+
values(): IterableIterator<Decimal>;
|
|
226
|
+
}
|