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,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vector = void 0;
|
|
4
|
+
const MathematicalAggregate_1 = require("../../common/classes/MathematicalAggregate");
|
|
5
|
+
const common_1 = require("../../common/common");
|
|
6
|
+
const structuredEntityUtils_1 = require("../../common/functions/structuredEntityUtils");
|
|
7
|
+
const errors_1 = require("../../errors");
|
|
8
|
+
const Collection_1 = require("../collection/Collection");
|
|
9
|
+
const Expression_1 = require("../expression/Expression");
|
|
10
|
+
const shortcuts_1 = require("../expression/shortcuts");
|
|
11
|
+
const constants_1 = require("../parser/constants");
|
|
12
|
+
const Polynomial_1 = require("../polynomial/Polynomial");
|
|
13
|
+
/**
|
|
14
|
+
* An ordered, operable parser aggregate with heterogeneous {@link ParserEntity} elements.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Vector is not restricted to numeric linear-algebra values. General arithmetic
|
|
18
|
+
* is element-wise: scalar operands are broadcast across the Vector, while Vector
|
|
19
|
+
* operands are paired by position and must have the same length. Vector-to-Vector
|
|
20
|
+
* {@link times} remains an element-wise product rather than an alias for {@link dot}.
|
|
21
|
+
* A Matrix operand interprets this Vector as a row vector for the standard
|
|
22
|
+
* `Vector * Matrix` product; orientation is supplied by operand position rather
|
|
23
|
+
* than stored on the Vector.
|
|
24
|
+
* Structural methods such as {@link append}, {@link insert}, {@link extend},
|
|
25
|
+
* {@link reverse}, and {@link trim} mutate this Vector.
|
|
26
|
+
*
|
|
27
|
+
* True linear-algebra operations ({@link dot}, {@link cross}, and {@link norm})
|
|
28
|
+
* require Expression elements. `dot` requires equal lengths, while `cross`
|
|
29
|
+
* requires two three-element Vectors. These operations throw rather than
|
|
30
|
+
* assigning arithmetic meaning to arbitrary aggregate elements.
|
|
31
|
+
*
|
|
32
|
+
* Construction from a Collection copies its elements. Construction from an
|
|
33
|
+
* array normalizes inputs but retains existing parser entities; {@link copy}
|
|
34
|
+
* deep-copies every element. Comparisons are component-wise predicates, not a
|
|
35
|
+
* total ordering, and return false for a type or length mismatch.
|
|
36
|
+
*/
|
|
37
|
+
class Vector extends MathematicalAggregate_1.MathematicalAggregate {
|
|
38
|
+
dataType = constants_1.VECTOR;
|
|
39
|
+
elements;
|
|
40
|
+
isEnumerable = true;
|
|
41
|
+
precision;
|
|
42
|
+
/** Creates a Vector from normalized input values or a copied Collection. */
|
|
43
|
+
constructor(elements) {
|
|
44
|
+
super();
|
|
45
|
+
if (Collection_1.Collection.isCollection(elements)) {
|
|
46
|
+
this.elements = elements.elements.map(e => e.copy());
|
|
47
|
+
}
|
|
48
|
+
else if (elements) {
|
|
49
|
+
this.elements = (0, structuredEntityUtils_1.toParserEntities)(elements);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.elements = [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Creates an Expression-only Vector from expression-compatible inputs. */
|
|
56
|
+
static create(v) {
|
|
57
|
+
return new Vector(v.map(x => Expression_1.Expression.create(x)));
|
|
58
|
+
}
|
|
59
|
+
static isVector(obj) {
|
|
60
|
+
return (0, common_1.isNerdamerNativeType)(obj, constants_1.VECTOR);
|
|
61
|
+
}
|
|
62
|
+
getValuesArray() {
|
|
63
|
+
return [...this.elements];
|
|
64
|
+
}
|
|
65
|
+
setValuesArray(values) {
|
|
66
|
+
this.elements = values;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the element at the given zero-based index.
|
|
70
|
+
* Used by the parser for bracket indexing, e.g. [a, b, c][1] returns b.
|
|
71
|
+
*
|
|
72
|
+
* @param indices - Zero-based parser indices after index-base adjustment.
|
|
73
|
+
* @returns The stored parser entity.
|
|
74
|
+
* @throws {@link core!UnexpectedDataType} If the index is out of bounds.
|
|
75
|
+
*/
|
|
76
|
+
__get__(indices) {
|
|
77
|
+
const index = indices[0];
|
|
78
|
+
if (index < 0 || index >= this.elements.length) {
|
|
79
|
+
throw new errors_1.UnexpectedDataType(`Index ${index} out of bounds for Vector of length ${this.elements.length}`);
|
|
80
|
+
}
|
|
81
|
+
return this.elements[index];
|
|
82
|
+
}
|
|
83
|
+
/** Appends an existing parser entity by reference and returns this Vector. */
|
|
84
|
+
add(x) {
|
|
85
|
+
return this.append(x);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Appends an existing parser entity by reference.
|
|
89
|
+
* @param e - Element to append.
|
|
90
|
+
*/
|
|
91
|
+
append(e) {
|
|
92
|
+
this.elements.push(e);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
arrayMap(callback) {
|
|
96
|
+
const retval = [];
|
|
97
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
98
|
+
retval.push(callback(this.elements[i]));
|
|
99
|
+
}
|
|
100
|
+
return retval;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the stored entity at a zero-based index without copying it.
|
|
104
|
+
* @param i - Zero-based index.
|
|
105
|
+
* @returns The entity, or `undefined` when the index is out of range.
|
|
106
|
+
*/
|
|
107
|
+
at(i) {
|
|
108
|
+
return this.elements[i];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Removes all elements from the vector.
|
|
112
|
+
*/
|
|
113
|
+
clear() {
|
|
114
|
+
this.elements = [];
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/** Copies the Vector and every contained entity. */
|
|
118
|
+
copy() {
|
|
119
|
+
const copy = new Vector();
|
|
120
|
+
this.each((e, i) => {
|
|
121
|
+
copy.elements[i] = e.copy();
|
|
122
|
+
return e;
|
|
123
|
+
});
|
|
124
|
+
return this.copySymbolicAccessTo(copy);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets the number of current elements in the Vector.
|
|
128
|
+
* @returns Current length.
|
|
129
|
+
*/
|
|
130
|
+
count() {
|
|
131
|
+
return this.elements.length;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Computes the three-dimensional cross product.
|
|
135
|
+
*
|
|
136
|
+
* @throws {@link core!DimensionError} Unless both Vectors have exactly three elements.
|
|
137
|
+
* @throws {@link core!UnexpectedDataType} If any required element is not an Expression.
|
|
138
|
+
*/
|
|
139
|
+
cross(v) {
|
|
140
|
+
if (this.elements.length !== 3 || v.elements.length !== 3) {
|
|
141
|
+
throw new errors_1.DimensionError((0, errors_1.message)('incorrectCrossDimension'));
|
|
142
|
+
}
|
|
143
|
+
const a = this.getExpressionAt(0);
|
|
144
|
+
const b = this.getExpressionAt(1);
|
|
145
|
+
const c = this.getExpressionAt(2);
|
|
146
|
+
const d = v.getExpressionAt(0);
|
|
147
|
+
const e = v.getExpressionAt(1);
|
|
148
|
+
const f = v.getExpressionAt(2);
|
|
149
|
+
return Vector.create([
|
|
150
|
+
b.times(f).minus(c.times(e)),
|
|
151
|
+
c.times(d).minus(a.times(f)),
|
|
152
|
+
a.times(e).minus(b.times(d)),
|
|
153
|
+
]);
|
|
154
|
+
}
|
|
155
|
+
delete(x) {
|
|
156
|
+
const index = this.indexOf(x);
|
|
157
|
+
if (index === -1) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
this.elements.splice(index, 1);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
dimensions() {
|
|
164
|
+
return [this.elements.length];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Divides corresponding elements, or broadcasts a scalar divisor.
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* Vector-to-Vector division is element-wise and requires equal lengths. This is
|
|
171
|
+
* distinct from scalar division, which applies the same divisor to every element.
|
|
172
|
+
*
|
|
173
|
+
* @throws {@link core!DimensionError} If a Vector divisor has a different length.
|
|
174
|
+
*/
|
|
175
|
+
div(x) {
|
|
176
|
+
if (Vector.isVector(x) && !this.dimensionsMatch(x)) {
|
|
177
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.div' }));
|
|
178
|
+
}
|
|
179
|
+
return super.div(x);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Computes the sum of pairwise products.
|
|
183
|
+
*
|
|
184
|
+
* @throws {@link core!DimensionError} If the Vector lengths differ.
|
|
185
|
+
* @throws {@link core!UnexpectedDataType} If a required element is not an Expression.
|
|
186
|
+
*/
|
|
187
|
+
dot(v) {
|
|
188
|
+
if (this.elements.length !== v.elements.length) {
|
|
189
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.dot' }));
|
|
190
|
+
}
|
|
191
|
+
let product = (0, shortcuts_1.zero)();
|
|
192
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
193
|
+
product = product.plus(this.getExpressionAt(i).times(v.getExpressionAt(i)));
|
|
194
|
+
}
|
|
195
|
+
return product;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Visits or replaces elements in ascending index order.
|
|
199
|
+
* Returning `void` leaves the current element unchanged.
|
|
200
|
+
*/
|
|
201
|
+
each(callback) {
|
|
202
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
203
|
+
const result = callback(this.elements[i], i);
|
|
204
|
+
if (result !== undefined) {
|
|
205
|
+
this.elements[i] = result;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
eq(V) {
|
|
211
|
+
if (!Vector.isVector(V) || V.elements.length !== this.elements.length) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
215
|
+
if (!this.elements[i].eq(V.elements[i])) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
evaluate(values) {
|
|
222
|
+
let retval;
|
|
223
|
+
const symbolicAccess = Expression_1.Expression.fromSymbolicAccess(this);
|
|
224
|
+
if (symbolicAccess && values) {
|
|
225
|
+
retval = symbolicAccess.evaluate(values);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const copy = this.copy();
|
|
229
|
+
copy.each(e => (Expression_1.Expression.isExpression(e) ? e.evaluate(values) : e.evaluate()));
|
|
230
|
+
retval = copy;
|
|
231
|
+
}
|
|
232
|
+
return retval;
|
|
233
|
+
}
|
|
234
|
+
/** Expands a copied Vector, leaving this one unchanged. */
|
|
235
|
+
expand() {
|
|
236
|
+
const copy = this.copy();
|
|
237
|
+
copy.each(e => e.expand());
|
|
238
|
+
return copy;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Appends another Vector's element references, mutating this Vector.
|
|
242
|
+
* @param v - Vector whose elements should be appended.
|
|
243
|
+
* @returns This Vector.
|
|
244
|
+
* @throws {@link core!UnexpectedDataType} If `v` is not a Vector.
|
|
245
|
+
*/
|
|
246
|
+
extend(v) {
|
|
247
|
+
if (!Vector.isVector(v)) {
|
|
248
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('vectorExpected', { type: constants_1.dataTypes[v.dataType] }));
|
|
249
|
+
}
|
|
250
|
+
this.elements.push(...v.elements);
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns an element after verifying that it is an Expression.
|
|
255
|
+
* @param n - Zero-based index.
|
|
256
|
+
* @returns The stored Expression reference.
|
|
257
|
+
* @throws {@link core!UnexpectedDataType} If the stored entity is not an Expression.
|
|
258
|
+
*/
|
|
259
|
+
getExpressionAt(n) {
|
|
260
|
+
const e = this.elements[n];
|
|
261
|
+
if (!Expression_1.Expression.isExpression(e)) {
|
|
262
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: constants_1.dataTypes[e.dataType] }));
|
|
263
|
+
}
|
|
264
|
+
return e;
|
|
265
|
+
}
|
|
266
|
+
gt(V) {
|
|
267
|
+
if (!Vector.isVector(V) || V.elements.length !== this.elements.length) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
271
|
+
if (!this.elements[i].gt(V.elements[i])) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
gte(V) {
|
|
278
|
+
if (!Vector.isVector(V) || V.elements.length !== this.elements.length) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
282
|
+
if (!this.elements[i].gte(V.elements[i])) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Gets the index of the first element structurally equal to `x`.
|
|
290
|
+
* @param x - Value to locate.
|
|
291
|
+
* @returns The zero-based index, or `-1` when absent.
|
|
292
|
+
*/
|
|
293
|
+
indexOf(x) {
|
|
294
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
295
|
+
const e = this.elements[i];
|
|
296
|
+
if (e.eq(x)) {
|
|
297
|
+
return i;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return -1;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Inserts an entity by reference before the provided index.
|
|
304
|
+
* @param i - Zero-based insertion index.
|
|
305
|
+
* @param x - Entity to insert.
|
|
306
|
+
* @returns This mutated Vector.
|
|
307
|
+
*/
|
|
308
|
+
insert(i, x) {
|
|
309
|
+
this.elements.splice(i, 0, x);
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
lt(V) {
|
|
313
|
+
if (!Vector.isVector(V) || V.elements.length !== this.elements.length) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
317
|
+
if (!this.elements[i].lt(V.elements[i])) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
lte(V) {
|
|
324
|
+
if (!Vector.isVector(V) || V.elements.length !== this.elements.length) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
328
|
+
if (!this.elements[i].lte(V.elements[i])) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Subtracts corresponding elements, or broadcasts a scalar subtrahend.
|
|
336
|
+
*
|
|
337
|
+
* @throws {@link core!DimensionError} If a Vector operand has a different length.
|
|
338
|
+
*/
|
|
339
|
+
minus(x) {
|
|
340
|
+
if (Vector.isVector(x) && !this.dimensionsMatch(x)) {
|
|
341
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.minus' }));
|
|
342
|
+
}
|
|
343
|
+
return super.minus(x);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Returns the Euclidean norm `sqrt(sum(abs(element)^2))`.
|
|
347
|
+
* @throws {@link core!UnexpectedDataType} If any element is not an Expression.
|
|
348
|
+
*/
|
|
349
|
+
norm() {
|
|
350
|
+
let sum = (0, shortcuts_1.zero)();
|
|
351
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
352
|
+
sum = sum.plus(this.getExpressionAt(i).abs().sq());
|
|
353
|
+
}
|
|
354
|
+
return sum.pow('1/2');
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Adds corresponding elements, or broadcasts a scalar addend.
|
|
358
|
+
*
|
|
359
|
+
* @throws {@link core!DimensionError} If a Vector operand has a different length.
|
|
360
|
+
*/
|
|
361
|
+
plus(x) {
|
|
362
|
+
if (Vector.isVector(x) && !this.dimensionsMatch(x)) {
|
|
363
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.plus' }));
|
|
364
|
+
}
|
|
365
|
+
return super.plus(x);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Removes an element given an index. If none is provided it removes the last element.
|
|
369
|
+
* Indices are zero-based.
|
|
370
|
+
* @param index - Optional zero-based index.
|
|
371
|
+
* @returns The removed entity, or `undefined` when no entity is present.
|
|
372
|
+
*/
|
|
373
|
+
pop(index) {
|
|
374
|
+
let removed;
|
|
375
|
+
if (typeof index !== 'undefined') {
|
|
376
|
+
removed = this.elements.splice(index, 1)[0];
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
removed = this.elements.pop();
|
|
380
|
+
}
|
|
381
|
+
return removed;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Raises corresponding elements to powers, or broadcasts a scalar exponent.
|
|
385
|
+
*
|
|
386
|
+
* @throws {@link core!DimensionError} If a Vector exponent has a different length.
|
|
387
|
+
*/
|
|
388
|
+
pow(x) {
|
|
389
|
+
if (Vector.isVector(x) && !this.dimensionsMatch(x)) {
|
|
390
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.pow' }));
|
|
391
|
+
}
|
|
392
|
+
return super.pow(x);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Multiplies all Expression elements in order.
|
|
396
|
+
* @returns Their product, or one for an empty Vector.
|
|
397
|
+
* @throws {@link core!UnexpectedDataType} If an element is not an Expression.
|
|
398
|
+
*/
|
|
399
|
+
prod() {
|
|
400
|
+
let retval = (0, shortcuts_1.one)();
|
|
401
|
+
this.each(e => {
|
|
402
|
+
retval = retval.times(Expression_1.Expression.create(e));
|
|
403
|
+
});
|
|
404
|
+
return retval;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Removes the first element equal to `x`, rather than matching by reference.
|
|
408
|
+
* @param x - Value to remove.
|
|
409
|
+
* @returns This Vector, whether or not a match was found.
|
|
410
|
+
*/
|
|
411
|
+
remove(x) {
|
|
412
|
+
const index = this.indexOf(x);
|
|
413
|
+
if (index !== -1) {
|
|
414
|
+
this.elements.splice(index, 1);
|
|
415
|
+
}
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Reverses the Vector in place.
|
|
420
|
+
* @returns This Vector.
|
|
421
|
+
*/
|
|
422
|
+
reverse() {
|
|
423
|
+
this.elements.reverse();
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Adds all Expression elements in order.
|
|
428
|
+
* @returns Their sum, or zero for an empty Vector.
|
|
429
|
+
* @throws {@link core!UnexpectedDataType} If an element is not an Expression.
|
|
430
|
+
*/
|
|
431
|
+
sum() {
|
|
432
|
+
let retval = (0, shortcuts_1.zero)();
|
|
433
|
+
this.each(e => {
|
|
434
|
+
retval = retval.plus(Expression_1.Expression.create(e));
|
|
435
|
+
});
|
|
436
|
+
return retval;
|
|
437
|
+
}
|
|
438
|
+
text() {
|
|
439
|
+
const text = `[${this.elements.map(e => e.text()).join(', ')}]`;
|
|
440
|
+
return this.formatSymbolicAccess(text);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Multiplies corresponding Vector elements, broadcasts a scalar factor, or
|
|
444
|
+
* multiplies this Vector from the left of a Matrix.
|
|
445
|
+
*
|
|
446
|
+
* @remarks
|
|
447
|
+
* Vector-to-Vector multiplication is the element-wise (Hadamard) product. Use
|
|
448
|
+
* {@link dot} when a scalar inner product is intended. For a Matrix operand,
|
|
449
|
+
* this Vector is interpreted as a row vector. Nonzero-width products reuse the
|
|
450
|
+
* existing Matrix-vector product through the transpose; a compatible zero-width
|
|
451
|
+
* Matrix has the empty Vector as its result because its transpose cannot be represented.
|
|
452
|
+
*
|
|
453
|
+
* @throws {@link core!DimensionError} If Vector dimensions are incompatible.
|
|
454
|
+
* @throws {@link core!MathError} If Matrix dimensions are incompatible.
|
|
455
|
+
*/
|
|
456
|
+
times(x) {
|
|
457
|
+
let retval;
|
|
458
|
+
if ((0, common_1.isNerdamerNativeType)(x, constants_1.MATRIX)) {
|
|
459
|
+
const matrix = x;
|
|
460
|
+
if (matrix.cols() === 0) {
|
|
461
|
+
if (this.count() !== matrix.rows()) {
|
|
462
|
+
throw new errors_1.MathError((0, errors_1.message)('mismatchedDimensions', { function: 'Matrix.times' }));
|
|
463
|
+
}
|
|
464
|
+
retval = new Vector();
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
retval = matrix.transpose().times(this);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
if (Vector.isVector(x) && !this.dimensionsMatch(x)) {
|
|
472
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'Vector.times' }));
|
|
473
|
+
}
|
|
474
|
+
retval = super.times(x);
|
|
475
|
+
}
|
|
476
|
+
return retval;
|
|
477
|
+
}
|
|
478
|
+
/** Interprets ordered elements as ascending polynomial coefficients. */
|
|
479
|
+
toPolynomial(vars = ['x']) {
|
|
480
|
+
return Polynomial_1.Polynomial.fromArray(this.elements, vars);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Removes every element equal to zero.
|
|
484
|
+
* @returns This mutated Vector.
|
|
485
|
+
*/
|
|
486
|
+
trim() {
|
|
487
|
+
const newElements = [];
|
|
488
|
+
for (const e of this.elements) {
|
|
489
|
+
if (!e.eq((0, shortcuts_1.zero)())) {
|
|
490
|
+
newElements.push(e);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
this.elements = newElements;
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
exports.Vector = Vector;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Expression } from '../expression/Expression';
|
|
2
|
+
import { Vector } from './Vector';
|
|
3
|
+
import type { ParserEntity } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Computes the dot product of two Vectors or preserves two symbolic operands.
|
|
6
|
+
*
|
|
7
|
+
* @param a - First Vector, or a symbolic Expression operand.
|
|
8
|
+
* @param b - Second Vector, or a symbolic Expression operand.
|
|
9
|
+
* @returns The scalar dot product for Vectors, or an unevaluated `dot(a, b)`
|
|
10
|
+
* Expression when both operands are Expressions.
|
|
11
|
+
* @throws {@link core!UnexpectedDataType} If exactly one operand is not a Vector or
|
|
12
|
+
* the two operands are of incompatible parser types.
|
|
13
|
+
* @throws {@link core!DimensionError} If Vector lengths differ.
|
|
14
|
+
*/
|
|
15
|
+
export declare function dot(a: ParserEntity, b: ParserEntity): Expression;
|
|
16
|
+
/**
|
|
17
|
+
* Computes a three-dimensional cross product or preserves symbolic operands.
|
|
18
|
+
*
|
|
19
|
+
* @param a - First Vector, or a symbolic Expression operand.
|
|
20
|
+
* @param b - Second Vector, or a symbolic Expression operand.
|
|
21
|
+
* @returns The Vector cross product, or an unevaluated `cross(a, b)` Expression
|
|
22
|
+
* when both operands are Expressions.
|
|
23
|
+
* @throws {@link core!UnexpectedDataType} For incompatible parser operand types.
|
|
24
|
+
* @throws {@link core!DimensionError} Unless both Vectors have exactly three elements.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cross(a: Vector, b: Vector): Vector;
|
|
27
|
+
export declare function cross(a: Expression, b: Expression): Expression;
|
|
28
|
+
export declare function cross(a: ParserEntity, b: ParserEntity): Vector | Expression;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dot = dot;
|
|
4
|
+
exports.cross = cross;
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const Expression_1 = require("../expression/Expression");
|
|
7
|
+
const constants_1 = require("../parser/constants");
|
|
8
|
+
const Vector_1 = require("./Vector");
|
|
9
|
+
/**
|
|
10
|
+
* Computes the dot product of two Vectors or preserves two symbolic operands.
|
|
11
|
+
*
|
|
12
|
+
* @param a - First Vector, or a symbolic Expression operand.
|
|
13
|
+
* @param b - Second Vector, or a symbolic Expression operand.
|
|
14
|
+
* @returns The scalar dot product for Vectors, or an unevaluated `dot(a, b)`
|
|
15
|
+
* Expression when both operands are Expressions.
|
|
16
|
+
* @throws {@link core!UnexpectedDataType} If exactly one operand is not a Vector or
|
|
17
|
+
* the two operands are of incompatible parser types.
|
|
18
|
+
* @throws {@link core!DimensionError} If Vector lengths differ.
|
|
19
|
+
*/
|
|
20
|
+
function dot(a, b) {
|
|
21
|
+
let retval;
|
|
22
|
+
if (Vector_1.Vector.isVector(a) && Vector_1.Vector.isVector(b)) {
|
|
23
|
+
retval = a.dot(b);
|
|
24
|
+
}
|
|
25
|
+
else if (Expression_1.Expression.isExpression(a) && Expression_1.Expression.isExpression(b)) {
|
|
26
|
+
retval = Expression_1.Expression.toFunction(constants_1.DOT_PRODUCT, [a, b]);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const operand = Vector_1.Vector.isVector(a) ? b : a;
|
|
30
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('vectorExpected', { type: constants_1.dataTypes[operand.dataType] }));
|
|
31
|
+
}
|
|
32
|
+
return retval;
|
|
33
|
+
}
|
|
34
|
+
function cross(a, b) {
|
|
35
|
+
let retval;
|
|
36
|
+
if (Vector_1.Vector.isVector(a) && Vector_1.Vector.isVector(b)) {
|
|
37
|
+
retval = a.cross(b);
|
|
38
|
+
}
|
|
39
|
+
else if (Expression_1.Expression.isExpression(a) && Expression_1.Expression.isExpression(b)) {
|
|
40
|
+
retval = Expression_1.Expression.toFunction(constants_1.CROSS, [a, b]);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const operand = Vector_1.Vector.isVector(a) ? b : a;
|
|
44
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('vectorExpected', { type: constants_1.dataTypes[operand.dataType] }));
|
|
45
|
+
}
|
|
46
|
+
return retval;
|
|
47
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StructuredEntity } from './StructuredEntity';
|
|
2
|
+
import type { ParserEntity } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* MathematicalAggregate
|
|
5
|
+
*
|
|
6
|
+
* Base class for linear iterable parser entities (Vector, ValuesSet, SolutionSet, ...).
|
|
7
|
+
*
|
|
8
|
+
* Elements are ParserEntity values at this shared level. Concrete subclasses may
|
|
9
|
+
* narrow their public element storage where their own method guarantees it.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class MathematicalAggregate<TSelf extends MathematicalAggregate<TSelf>> extends StructuredEntity<TSelf> {
|
|
12
|
+
abstract elements: ParserEntity[];
|
|
13
|
+
/**
|
|
14
|
+
* Returns the element at the given index.
|
|
15
|
+
* @param indices A single-element array [i]
|
|
16
|
+
*/
|
|
17
|
+
__get__(indices: number[]): ParserEntity;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the element at the given index.
|
|
20
|
+
* @param indices A single-element array [i]
|
|
21
|
+
* @param value The value to set
|
|
22
|
+
*/
|
|
23
|
+
__set__(indices: number[], value: ParserEntity): void;
|
|
24
|
+
clear(): this;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the number of current elements.
|
|
27
|
+
*/
|
|
28
|
+
count(): number;
|
|
29
|
+
dimensions(): number[];
|
|
30
|
+
/**
|
|
31
|
+
* Visits or replaces elements in place.
|
|
32
|
+
* Returning `void` leaves the current element unchanged.
|
|
33
|
+
*/
|
|
34
|
+
each(this: TSelf, callback: (e: ParserEntity, i?: string | number, j?: string | number) => ParserEntity | void): TSelf;
|
|
35
|
+
eq(other: ParserEntity): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Visits every current element without changing the aggregate.
|
|
38
|
+
*
|
|
39
|
+
* This is the observation-only counterpart to {@link each}. Concrete subclasses may
|
|
40
|
+
* narrow the callback element type when their membership method guarantees a more
|
|
41
|
+
* specific entity.
|
|
42
|
+
*/
|
|
43
|
+
forEach(callback: (e: ParserEntity, index: number) => void): void;
|
|
44
|
+
gt(other: ParserEntity): boolean;
|
|
45
|
+
gte(other: ParserEntity): boolean;
|
|
46
|
+
lt(other: ParserEntity): boolean;
|
|
47
|
+
lte(other: ParserEntity): boolean;
|
|
48
|
+
sort(compareFn?: (a: ParserEntity, b: ParserEntity) => number): this;
|
|
49
|
+
/** Returns an iterator over the aggregate's current public element view. */
|
|
50
|
+
[Symbol.iterator](): Iterator<ParserEntity>;
|
|
51
|
+
/** Returns a new array containing the aggregate's current public element view. */
|
|
52
|
+
toArray(): ParserEntity[];
|
|
53
|
+
}
|