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,90 @@
|
|
|
1
|
+
import { Expression } from '../expression/Expression';
|
|
2
|
+
import { Assumption } from './Assumption';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare function hasAssumptions(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Registers a numeric interval assumption in Nerdamer's global assumption state.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A one-argument call parses a complete constraint such as `x >= 0`. The two-argument
|
|
10
|
+
* form associates a plain variable with either another complete constraint for that
|
|
11
|
+
* same variable or an existing {@link Assumption} instance. Built-in constants and the
|
|
12
|
+
* configured imaginary-unit symbol cannot receive real interval assumptions.
|
|
13
|
+
*
|
|
14
|
+
* Repeated assumptions for the same variable are intersected. If the intersection is
|
|
15
|
+
* empty, the new constraint is rejected and the previously registered assumption is
|
|
16
|
+
* left unchanged.
|
|
17
|
+
*
|
|
18
|
+
* Assumption state is process-wide. It is consulted by expression comparisons and by
|
|
19
|
+
* algorithms that rely on those comparisons, including positivity-sensitive
|
|
20
|
+
* simplifications. Call {@link clearAssumptions} when that state should no longer
|
|
21
|
+
* affect later work. Scoped assumption contexts are not simulated in 2.0 because a
|
|
22
|
+
* correct scoped design must be threaded through the parser and algorithms rather
|
|
23
|
+
* than wrapping only this registry.
|
|
24
|
+
*
|
|
25
|
+
* @param expr - Complete constraint in the supported assumption grammar.
|
|
26
|
+
* @returns The registered interval after intersection with any existing constraint.
|
|
27
|
+
* @throws Error
|
|
28
|
+
* Thrown when the constraint is malformed or its bound is not numeric.
|
|
29
|
+
* @throws UnexpectedInputError
|
|
30
|
+
* Thrown when a new constraint contradicts the existing assumption.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* assume('x >= 0');
|
|
35
|
+
* assume('x < 10');
|
|
36
|
+
* getAssumptionFor('x')?.toString(); // "[0, 10)"
|
|
37
|
+
* clearAssumptions();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function assume(expr: string): Assumption;
|
|
41
|
+
/**
|
|
42
|
+
* Registers an assumption for a named variable.
|
|
43
|
+
*
|
|
44
|
+
* @param symbol - Plain variable name receiving the constraint.
|
|
45
|
+
* @param exprOrAssumption - Constraint for the same symbol or a prebuilt interval.
|
|
46
|
+
* @returns The registered interval after intersection with any existing constraint.
|
|
47
|
+
*/
|
|
48
|
+
export declare function assume(symbol: string, exprOrAssumption: string | Assumption): Assumption;
|
|
49
|
+
/**
|
|
50
|
+
* Clears Nerdamer's process-wide assumption registry.
|
|
51
|
+
*
|
|
52
|
+
* This does not modify expressions that have already been constructed; it only
|
|
53
|
+
* changes the assumptions consulted by later comparison and simplification work.
|
|
54
|
+
*/
|
|
55
|
+
export declare function clearAssumptions(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Removes the registered assumption for one plain variable.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* Passing an expression that is not a plain variable, or a name with no registered
|
|
61
|
+
* assumption, is a no-op. Other assumptions are left unchanged.
|
|
62
|
+
*
|
|
63
|
+
* @param x - Plain variable expression or variable name to forget.
|
|
64
|
+
*/
|
|
65
|
+
export declare function forgetAssumptionFor(x: Expression | string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the interval currently registered for a plain variable.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* `Assumption` instances are immutable, so the returned object can be inspected
|
|
71
|
+
* without exposing mutable registry state. Non-variable expressions have no direct
|
|
72
|
+
* assumption and return `undefined`.
|
|
73
|
+
*
|
|
74
|
+
* @param x - Plain variable expression or variable name.
|
|
75
|
+
* @returns The registered interval, or `undefined` when no assumption is available.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getAssumptionFor(x: Expression | string): Assumption | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Parser marker used by `assume(...)` so comparison operators register constraints
|
|
80
|
+
* instead of evaluating ordinary boolean relations.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export declare function assuming(x: Expression): Expression;
|
|
85
|
+
/**
|
|
86
|
+
* Parser-facing compatibility function for `forget(variable)` and `forget(all)`.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export declare function forget(x: Expression): Expression;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasAssumptions = hasAssumptions;
|
|
4
|
+
exports.assume = assume;
|
|
5
|
+
exports.clearAssumptions = clearAssumptions;
|
|
6
|
+
exports.forgetAssumptionFor = forgetAssumptionFor;
|
|
7
|
+
exports.getAssumptionFor = getAssumptionFor;
|
|
8
|
+
exports.assuming = assuming;
|
|
9
|
+
exports.forget = forget;
|
|
10
|
+
const errors_1 = require("../../errors");
|
|
11
|
+
const Settings_1 = require("../../Settings");
|
|
12
|
+
const Expression_1 = require("../expression/Expression");
|
|
13
|
+
const constants_1 = require("../parser/constants");
|
|
14
|
+
const Assumption_1 = require("./Assumption");
|
|
15
|
+
// Assumptions remain process-wide compatibility state in 2.0. A useful scoped
|
|
16
|
+
// context would have to be threaded through parser, comparison, and simplification
|
|
17
|
+
// calls; wrapping this Map without doing that would only create the appearance of
|
|
18
|
+
// isolation. Keep the state explicit here until that larger API can be designed.
|
|
19
|
+
const ASSUMPTIONS = new Map();
|
|
20
|
+
/** @internal */
|
|
21
|
+
function hasAssumptions() {
|
|
22
|
+
return ASSUMPTIONS.size !== 0;
|
|
23
|
+
}
|
|
24
|
+
function setAssumption(symbol, assumption) {
|
|
25
|
+
if (Expression_1.Expression.RESERVED.includes(symbol) ||
|
|
26
|
+
Settings_1.RESTRICTED.includes(symbol) ||
|
|
27
|
+
symbol === Expression_1.Expression.imaginary) {
|
|
28
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: symbol }));
|
|
29
|
+
}
|
|
30
|
+
const prev = ASSUMPTIONS.get(symbol);
|
|
31
|
+
let retval = assumption;
|
|
32
|
+
if (prev) {
|
|
33
|
+
const intersection = prev.intersect(assumption);
|
|
34
|
+
if (!intersection) {
|
|
35
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('inconsistentAssumptions'));
|
|
36
|
+
}
|
|
37
|
+
retval = intersection;
|
|
38
|
+
}
|
|
39
|
+
ASSUMPTIONS.set(symbol, retval);
|
|
40
|
+
return retval;
|
|
41
|
+
}
|
|
42
|
+
function assume(a, b) {
|
|
43
|
+
let retval;
|
|
44
|
+
if (arguments.length === 1) {
|
|
45
|
+
const parsed = Assumption_1.Assumption.parse(a);
|
|
46
|
+
retval = setAssumption(parsed.symbol, parsed.assumption);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const symbol = String(a);
|
|
50
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(symbol)) {
|
|
51
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: symbol }));
|
|
52
|
+
}
|
|
53
|
+
if (typeof b === 'string') {
|
|
54
|
+
const parsed = Assumption_1.Assumption.parse(b);
|
|
55
|
+
if (parsed.symbol !== symbol) {
|
|
56
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('wrongInput', { expected: symbol, received: parsed.symbol }));
|
|
57
|
+
}
|
|
58
|
+
retval = setAssumption(symbol, parsed.assumption);
|
|
59
|
+
}
|
|
60
|
+
else if (Assumption_1.Assumption.isAssumption(b)) {
|
|
61
|
+
retval = setAssumption(symbol, b);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('wrongInput', {
|
|
65
|
+
expected: 'string or Assumption',
|
|
66
|
+
received: typeof b,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return retval;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Clears Nerdamer's process-wide assumption registry.
|
|
74
|
+
*
|
|
75
|
+
* This does not modify expressions that have already been constructed; it only
|
|
76
|
+
* changes the assumptions consulted by later comparison and simplification work.
|
|
77
|
+
*/
|
|
78
|
+
function clearAssumptions() {
|
|
79
|
+
ASSUMPTIONS.clear();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Removes the registered assumption for one plain variable.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Passing an expression that is not a plain variable, or a name with no registered
|
|
86
|
+
* assumption, is a no-op. Other assumptions are left unchanged.
|
|
87
|
+
*
|
|
88
|
+
* @param x - Plain variable expression or variable name to forget.
|
|
89
|
+
*/
|
|
90
|
+
function forgetAssumptionFor(x) {
|
|
91
|
+
let symbol;
|
|
92
|
+
if (Expression_1.Expression.isExpression(x) && x.isPlainVariable()) {
|
|
93
|
+
symbol = x.value;
|
|
94
|
+
}
|
|
95
|
+
else if (typeof x === 'string') {
|
|
96
|
+
symbol = x;
|
|
97
|
+
}
|
|
98
|
+
if (symbol !== undefined) {
|
|
99
|
+
ASSUMPTIONS.delete(symbol);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the interval currently registered for a plain variable.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* `Assumption` instances are immutable, so the returned object can be inspected
|
|
107
|
+
* without exposing mutable registry state. Non-variable expressions have no direct
|
|
108
|
+
* assumption and return `undefined`.
|
|
109
|
+
*
|
|
110
|
+
* @param x - Plain variable expression or variable name.
|
|
111
|
+
* @returns The registered interval, or `undefined` when no assumption is available.
|
|
112
|
+
*/
|
|
113
|
+
function getAssumptionFor(x) {
|
|
114
|
+
let symbol;
|
|
115
|
+
if (Expression_1.Expression.isExpression(x) && x.isPlainVariable()) {
|
|
116
|
+
symbol = x.value;
|
|
117
|
+
}
|
|
118
|
+
else if (typeof x === 'string') {
|
|
119
|
+
symbol = x;
|
|
120
|
+
}
|
|
121
|
+
return symbol === undefined ? undefined : ASSUMPTIONS.get(symbol);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Parser marker used by `assume(...)` so comparison operators register constraints
|
|
125
|
+
* instead of evaluating ordinary boolean relations.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
function assuming(x) {
|
|
130
|
+
return x;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Parser-facing compatibility function for `forget(variable)` and `forget(all)`.
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
function forget(x) {
|
|
138
|
+
if (x.eq(constants_1.ALL_SYMBOL)) {
|
|
139
|
+
clearAssumptions();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
forgetAssumptionFor(x);
|
|
143
|
+
}
|
|
144
|
+
return x;
|
|
145
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { StructuredEntity } from '../../common/classes/StructuredEntity';
|
|
2
|
+
import { COLLECTION } from '../parser/constants';
|
|
3
|
+
import type { ParserEntity } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* An ordered heterogeneous collection of parser entities.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The constructor retains the supplied array and its element references.
|
|
9
|
+
* {@link getElements} likewise exposes the live backing array. Use {@link copy}
|
|
10
|
+
* for an independent collection; it copies every contained parser entity.
|
|
11
|
+
*
|
|
12
|
+
* {@link each} and indexed assignment mutate the collection. A callback passed
|
|
13
|
+
* to `each` may return a replacement value or return nothing to leave the
|
|
14
|
+
* current value unchanged. Use {@link forEach} for observation-only iteration.
|
|
15
|
+
* Evaluation and expansion operate on a deep copy. Equality and relational
|
|
16
|
+
* predicates compare corresponding elements and return false for a non-Collection
|
|
17
|
+
* or length mismatch; these component-wise predicates do not define a
|
|
18
|
+
* lexicographic ordering for heterogeneous values.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Collection extends StructuredEntity<Collection> {
|
|
21
|
+
/** Runtime type discriminator for collections. */
|
|
22
|
+
dataType: typeof COLLECTION;
|
|
23
|
+
/** Live array containing the collection's values. */
|
|
24
|
+
elements: ParserEntity[];
|
|
25
|
+
/** Indicates that parser operations may be applied to each element. */
|
|
26
|
+
isEnumerable: boolean;
|
|
27
|
+
/** Precision metadata when the collection carries an approximate result. */
|
|
28
|
+
precision?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a Collection, retaining `elements` when it is supplied.
|
|
31
|
+
* @param elements - Initial backing array.
|
|
32
|
+
*/
|
|
33
|
+
constructor(elements?: ParserEntity[]);
|
|
34
|
+
/**
|
|
35
|
+
* Returns whether a value is a Collection.
|
|
36
|
+
* @param obj - Value to test.
|
|
37
|
+
*/
|
|
38
|
+
static isCollection(obj: unknown): obj is Collection;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the element at the given index.
|
|
41
|
+
* @param indices A single-element array [i]
|
|
42
|
+
*/
|
|
43
|
+
__get__(indices: number[]): ParserEntity;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the element at the given index.
|
|
46
|
+
* @param indices A single-element array [i]
|
|
47
|
+
* @param value The value to set
|
|
48
|
+
*/
|
|
49
|
+
__set__(indices: number[], value: ParserEntity): void;
|
|
50
|
+
/** Returns the stored entity reference at a zero-based index, or `undefined` when absent. */
|
|
51
|
+
at(index: number): ParserEntity | undefined;
|
|
52
|
+
/** Copies the collection and every contained entity. */
|
|
53
|
+
copy(): Collection;
|
|
54
|
+
/** Returns the number of values in the collection. */
|
|
55
|
+
count(): number;
|
|
56
|
+
/** Returns the collection length as a one-dimensional shape. */
|
|
57
|
+
dimensions(): number[];
|
|
58
|
+
/**
|
|
59
|
+
* Visits or replaces values in ascending index order.
|
|
60
|
+
*
|
|
61
|
+
* Returning a ParserEntity replaces the current value. Returning `void` leaves
|
|
62
|
+
* that value unchanged, so callers can inspect a collection without a dummy return.
|
|
63
|
+
* Use {@link forEach} when no transformation is intended.
|
|
64
|
+
*
|
|
65
|
+
* @param callback - Function receiving each value and index.
|
|
66
|
+
*/
|
|
67
|
+
each(callback: (a: ParserEntity, b: number) => ParserEntity | void): this;
|
|
68
|
+
/**
|
|
69
|
+
* Tests whether another Collection has equal values in the same order.
|
|
70
|
+
* @param x - Value to compare.
|
|
71
|
+
*/
|
|
72
|
+
eq(x: ParserEntity): boolean;
|
|
73
|
+
/** Evaluates a copied collection, leaving this one unchanged. */
|
|
74
|
+
evaluate(): Collection;
|
|
75
|
+
/** Expands every value in a copied collection. */
|
|
76
|
+
expand(): Collection;
|
|
77
|
+
/** Visits stored entity references without changing the collection. */
|
|
78
|
+
forEach(callback: (value: ParserEntity, index: number) => void): void;
|
|
79
|
+
/** Returns the live backing array; mutations to it affect this Collection. */
|
|
80
|
+
getElements(): ParserEntity[];
|
|
81
|
+
/**
|
|
82
|
+
* Tests whether every value is greater than its corresponding value.
|
|
83
|
+
* @param x - Value to compare.
|
|
84
|
+
*/
|
|
85
|
+
gt(x: ParserEntity): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Tests component-wise greater-than-or-equal comparison.
|
|
88
|
+
* @param x - Value to compare.
|
|
89
|
+
*/
|
|
90
|
+
gte(x: ParserEntity): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Tests whether every value is less than its corresponding value.
|
|
93
|
+
* @param x - Value to compare.
|
|
94
|
+
*/
|
|
95
|
+
lt(x: ParserEntity): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Tests component-wise less-than-or-equal comparison.
|
|
98
|
+
* @param x - Value to compare.
|
|
99
|
+
*/
|
|
100
|
+
lte(x: ParserEntity): boolean;
|
|
101
|
+
/** Iterates over the stored entity references in insertion order. */
|
|
102
|
+
[Symbol.iterator](): Iterator<ParserEntity>;
|
|
103
|
+
/** Returns the collection in Nerdamer notation. */
|
|
104
|
+
text(): string;
|
|
105
|
+
/** Returns a new array containing the stored entity references in insertion order. */
|
|
106
|
+
toArray(): ParserEntity[];
|
|
107
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collection = void 0;
|
|
4
|
+
const StructuredEntity_1 = require("../../common/classes/StructuredEntity");
|
|
5
|
+
const common_1 = require("../../common/common");
|
|
6
|
+
const constants_1 = require("../parser/constants");
|
|
7
|
+
/**
|
|
8
|
+
* An ordered heterogeneous collection of parser entities.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The constructor retains the supplied array and its element references.
|
|
12
|
+
* {@link getElements} likewise exposes the live backing array. Use {@link copy}
|
|
13
|
+
* for an independent collection; it copies every contained parser entity.
|
|
14
|
+
*
|
|
15
|
+
* {@link each} and indexed assignment mutate the collection. A callback passed
|
|
16
|
+
* to `each` may return a replacement value or return nothing to leave the
|
|
17
|
+
* current value unchanged. Use {@link forEach} for observation-only iteration.
|
|
18
|
+
* Evaluation and expansion operate on a deep copy. Equality and relational
|
|
19
|
+
* predicates compare corresponding elements and return false for a non-Collection
|
|
20
|
+
* or length mismatch; these component-wise predicates do not define a
|
|
21
|
+
* lexicographic ordering for heterogeneous values.
|
|
22
|
+
*/
|
|
23
|
+
class Collection extends StructuredEntity_1.StructuredEntity {
|
|
24
|
+
/** Runtime type discriminator for collections. */
|
|
25
|
+
dataType = constants_1.COLLECTION;
|
|
26
|
+
/** Live array containing the collection's values. */
|
|
27
|
+
elements = [];
|
|
28
|
+
/** Indicates that parser operations may be applied to each element. */
|
|
29
|
+
isEnumerable = true;
|
|
30
|
+
/** Precision metadata when the collection carries an approximate result. */
|
|
31
|
+
precision;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a Collection, retaining `elements` when it is supplied.
|
|
34
|
+
* @param elements - Initial backing array.
|
|
35
|
+
*/
|
|
36
|
+
constructor(elements) {
|
|
37
|
+
super();
|
|
38
|
+
if (elements) {
|
|
39
|
+
this.elements = elements;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.elements = [];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns whether a value is a Collection.
|
|
47
|
+
* @param obj - Value to test.
|
|
48
|
+
*/
|
|
49
|
+
static isCollection(obj) {
|
|
50
|
+
return (0, common_1.isNerdamerNativeType)(obj, constants_1.COLLECTION);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns the element at the given index.
|
|
54
|
+
* @param indices A single-element array [i]
|
|
55
|
+
*/
|
|
56
|
+
__get__(indices) {
|
|
57
|
+
const index = indices[0];
|
|
58
|
+
if (index < 0 || index >= this.elements.length) {
|
|
59
|
+
throw new RangeError(`Index ${index} out of bounds for Collection of length ${this.elements.length}`);
|
|
60
|
+
}
|
|
61
|
+
return this.elements[index];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sets the element at the given index.
|
|
65
|
+
* @param indices A single-element array [i]
|
|
66
|
+
* @param value The value to set
|
|
67
|
+
*/
|
|
68
|
+
__set__(indices, value) {
|
|
69
|
+
const index = indices[0];
|
|
70
|
+
if (index < 0 || index >= this.elements.length) {
|
|
71
|
+
throw new RangeError(`Index ${index} out of bounds for Collection of length ${this.elements.length}`);
|
|
72
|
+
}
|
|
73
|
+
this.elements[index] = value;
|
|
74
|
+
}
|
|
75
|
+
/** Returns the stored entity reference at a zero-based index, or `undefined` when absent. */
|
|
76
|
+
at(index) {
|
|
77
|
+
return this.elements[index];
|
|
78
|
+
}
|
|
79
|
+
/** Copies the collection and every contained entity. */
|
|
80
|
+
copy() {
|
|
81
|
+
const copy = new Collection();
|
|
82
|
+
this.each((e, i) => {
|
|
83
|
+
copy.elements[i] = e.copy();
|
|
84
|
+
return e;
|
|
85
|
+
});
|
|
86
|
+
return copy;
|
|
87
|
+
}
|
|
88
|
+
/** Returns the number of values in the collection. */
|
|
89
|
+
count() {
|
|
90
|
+
return this.elements.length;
|
|
91
|
+
}
|
|
92
|
+
/** Returns the collection length as a one-dimensional shape. */
|
|
93
|
+
dimensions() {
|
|
94
|
+
return [this.elements.length];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Visits or replaces values in ascending index order.
|
|
98
|
+
*
|
|
99
|
+
* Returning a ParserEntity replaces the current value. Returning `void` leaves
|
|
100
|
+
* that value unchanged, so callers can inspect a collection without a dummy return.
|
|
101
|
+
* Use {@link forEach} when no transformation is intended.
|
|
102
|
+
*
|
|
103
|
+
* @param callback - Function receiving each value and index.
|
|
104
|
+
*/
|
|
105
|
+
each(callback) {
|
|
106
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
107
|
+
const current = this.elements[i];
|
|
108
|
+
const result = callback(current, i);
|
|
109
|
+
if (result !== undefined) {
|
|
110
|
+
this.elements[i] = result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Tests whether another Collection has equal values in the same order.
|
|
117
|
+
* @param x - Value to compare.
|
|
118
|
+
*/
|
|
119
|
+
eq(x) {
|
|
120
|
+
if (!Collection.isCollection(x) || x.elements.length !== this.elements.length) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
124
|
+
const a = this.elements[i];
|
|
125
|
+
const b = x.elements[i];
|
|
126
|
+
if (!a.eq(b)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/** Evaluates a copied collection, leaving this one unchanged. */
|
|
133
|
+
evaluate() {
|
|
134
|
+
const copy = this.copy();
|
|
135
|
+
copy.each(e => e.evaluate());
|
|
136
|
+
return copy;
|
|
137
|
+
}
|
|
138
|
+
/** Expands every value in a copied collection. */
|
|
139
|
+
expand() {
|
|
140
|
+
const copy = this.copy();
|
|
141
|
+
copy.each(e => e.expand());
|
|
142
|
+
return copy;
|
|
143
|
+
}
|
|
144
|
+
/** Visits stored entity references without changing the collection. */
|
|
145
|
+
forEach(callback) {
|
|
146
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
147
|
+
callback(this.elements[i], i);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Returns the live backing array; mutations to it affect this Collection. */
|
|
151
|
+
getElements() {
|
|
152
|
+
return this.elements;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Tests whether every value is greater than its corresponding value.
|
|
156
|
+
* @param x - Value to compare.
|
|
157
|
+
*/
|
|
158
|
+
gt(x) {
|
|
159
|
+
if (!Collection.isCollection(x) || x.elements.length !== this.elements.length) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
163
|
+
const a = this.elements[i];
|
|
164
|
+
const b = x.elements[i];
|
|
165
|
+
if (!a.gt(b)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Tests component-wise greater-than-or-equal comparison.
|
|
173
|
+
* @param x - Value to compare.
|
|
174
|
+
*/
|
|
175
|
+
gte(x) {
|
|
176
|
+
if (!Collection.isCollection(x) || x.elements.length !== this.elements.length) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
180
|
+
if (!this.elements[i].gte(x.elements[i])) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Tests whether every value is less than its corresponding value.
|
|
188
|
+
* @param x - Value to compare.
|
|
189
|
+
*/
|
|
190
|
+
lt(x) {
|
|
191
|
+
if (!Collection.isCollection(x) || x.elements.length !== this.elements.length) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
195
|
+
const a = this.elements[i];
|
|
196
|
+
const b = x.elements[i];
|
|
197
|
+
if (!a.lt(b)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Tests component-wise less-than-or-equal comparison.
|
|
205
|
+
* @param x - Value to compare.
|
|
206
|
+
*/
|
|
207
|
+
lte(x) {
|
|
208
|
+
if (!Collection.isCollection(x) || x.elements.length !== this.elements.length) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
212
|
+
if (!this.elements[i].lte(x.elements[i])) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
/** Iterates over the stored entity references in insertion order. */
|
|
219
|
+
[Symbol.iterator]() {
|
|
220
|
+
return this.elements[Symbol.iterator]();
|
|
221
|
+
}
|
|
222
|
+
/** Returns the collection in Nerdamer notation. */
|
|
223
|
+
text() {
|
|
224
|
+
return `(${this.elements.map(e => e.text()).join(', ')})`;
|
|
225
|
+
}
|
|
226
|
+
/** Returns a new array containing the stored entity references in insertion order. */
|
|
227
|
+
toArray() {
|
|
228
|
+
return [...this.elements];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.Collection = Collection;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a numerical complex value backed by `decimal.js` components.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This class is a numerical helper used by algorithms such as polynomial root solving. It is
|
|
7
|
+
* distinct from Nerdamer's symbolic complex expressions: it does not parse expressions, carry
|
|
8
|
+
* symbolic structure, or implement branch-sensitive transcendental functions. Component
|
|
9
|
+
* arithmetic follows the active global `decimal.js` precision.
|
|
10
|
+
*
|
|
11
|
+
* Arithmetic methods return new `Complex` objects rather than modifying the receiver. The
|
|
12
|
+
* {@link Complex.re} and {@link Complex.im} fields are public, however, so callers can reassign
|
|
13
|
+
* components directly.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Complex {
|
|
16
|
+
/** Imaginary component. */
|
|
17
|
+
im: Decimal;
|
|
18
|
+
/** Real component. */
|
|
19
|
+
re: Decimal;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a numerical complex value.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Existing Decimal components are retained by reference; numeric inputs are converted to
|
|
25
|
+
* new Decimal values. `decimal.js` arithmetic itself returns new Decimal objects.
|
|
26
|
+
*
|
|
27
|
+
* @param re - Real component.
|
|
28
|
+
* @param im - Imaginary component; defaults to zero.
|
|
29
|
+
*/
|
|
30
|
+
constructor(re: Decimal | number, im?: Decimal | number);
|
|
31
|
+
/**
|
|
32
|
+
* Creates a numerical complex value from Decimal or native-number components.
|
|
33
|
+
*
|
|
34
|
+
* @param re - Real component.
|
|
35
|
+
* @param im - Imaginary component; defaults to zero.
|
|
36
|
+
* @returns A new `Complex` value.
|
|
37
|
+
*/
|
|
38
|
+
static create(re: Decimal | number, im?: Decimal | number): Complex;
|
|
39
|
+
/**
|
|
40
|
+
* Computes the modulus `sqrt(re^2 + im^2)`.
|
|
41
|
+
*
|
|
42
|
+
* @returns A new Decimal containing the nonnegative magnitude.
|
|
43
|
+
*/
|
|
44
|
+
abs(): Decimal;
|
|
45
|
+
/**
|
|
46
|
+
* Adds another complex value component-wise.
|
|
47
|
+
*
|
|
48
|
+
* @param other - Complex value to add.
|
|
49
|
+
* @returns A new complex sum.
|
|
50
|
+
*/
|
|
51
|
+
add(other: Complex): Complex;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the complex conjugate `re - im*i`.
|
|
54
|
+
*
|
|
55
|
+
* @returns A new complex value with the imaginary component negated.
|
|
56
|
+
*/
|
|
57
|
+
conjugate(): Complex;
|
|
58
|
+
/**
|
|
59
|
+
* Divides this complex value by another using the standard rectangular formula.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Division rejects an exactly zero squared modulus. No numerical tolerance is applied at
|
|
63
|
+
* this arithmetic layer; iterative algorithms are responsible for choosing any tolerance
|
|
64
|
+
* appropriate to their convergence logic.
|
|
65
|
+
*
|
|
66
|
+
* @param other - Complex divisor.
|
|
67
|
+
* @returns A new complex quotient.
|
|
68
|
+
* @throws {@link core!DivisionByZeroError}
|
|
69
|
+
* Thrown when both components of `other` are exactly zero at the current Decimal value.
|
|
70
|
+
*/
|
|
71
|
+
div(other: Complex): Complex;
|
|
72
|
+
/**
|
|
73
|
+
* Multiplies two rectangular complex values.
|
|
74
|
+
*
|
|
75
|
+
* @param other - Complex factor.
|
|
76
|
+
* @returns A new complex product.
|
|
77
|
+
*/
|
|
78
|
+
mul(other: Complex): Complex;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the additive inverse of this complex value.
|
|
81
|
+
*
|
|
82
|
+
* @returns A new complex value with both components negated.
|
|
83
|
+
*/
|
|
84
|
+
neg(): Complex;
|
|
85
|
+
/**
|
|
86
|
+
* Multiplies both complex components by a real scalar.
|
|
87
|
+
*
|
|
88
|
+
* @param s - Decimal or native-number scale factor.
|
|
89
|
+
* @returns A new scaled complex value.
|
|
90
|
+
*/
|
|
91
|
+
scale(s: Decimal | number): Complex;
|
|
92
|
+
/**
|
|
93
|
+
* Subtracts another complex value component-wise.
|
|
94
|
+
*
|
|
95
|
+
* @param other - Complex value to subtract.
|
|
96
|
+
* @returns A new complex difference.
|
|
97
|
+
*/
|
|
98
|
+
sub(other: Complex): Complex;
|
|
99
|
+
}
|