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,430 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._ = void 0;
|
|
4
|
+
exports.callFunction = callFunction;
|
|
5
|
+
exports.distribute = distribute;
|
|
6
|
+
exports.setEqual = setEqual;
|
|
7
|
+
exports.functionAssign = functionAssign;
|
|
8
|
+
exports.route = route;
|
|
9
|
+
const math_1 = require("../../../../math/math");
|
|
10
|
+
const structuredEntityUtils_1 = require("../../../common/functions/structuredEntityUtils");
|
|
11
|
+
const dispatch_1 = require("../../../dispatch");
|
|
12
|
+
const errors_1 = require("../../../errors");
|
|
13
|
+
const setFunction_1 = require("../../../functions/setFunction");
|
|
14
|
+
const Settings_1 = require("../../../Settings");
|
|
15
|
+
const assertiveFunctions_1 = require("../../assumption/assertiveFunctions");
|
|
16
|
+
const Collection_1 = require("../../collection/Collection");
|
|
17
|
+
const Equation_1 = require("../../equation/Equation");
|
|
18
|
+
const Expression_1 = require("../../expression/Expression");
|
|
19
|
+
const utils_1 = require("../../expression/utils");
|
|
20
|
+
const Matrix_1 = require("../../matrix/Matrix");
|
|
21
|
+
const Vector_1 = require("../../vector/Vector");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
23
|
+
const controlFlow_1 = require("../scripting/controlFlow");
|
|
24
|
+
const functions_1 = require("../scripting/functions");
|
|
25
|
+
const scope_1 = require("../scripting/scope");
|
|
26
|
+
const add_1 = require("./add");
|
|
27
|
+
const comma_1 = require("./comma");
|
|
28
|
+
const divide_1 = require("./divide");
|
|
29
|
+
const multiply_1 = require("./multiply");
|
|
30
|
+
const power_1 = require("./power");
|
|
31
|
+
const subtract_1 = require("./subtract");
|
|
32
|
+
/**
|
|
33
|
+
* Invokes a function selected dynamically from the dispatch table. Registered functions do
|
|
34
|
+
* not share one parameter signature, so the parser cannot verify the argument types after
|
|
35
|
+
* resolving a function name at runtime. Arity has already been validated by `callFunction`.
|
|
36
|
+
*/
|
|
37
|
+
function invokeMathFunction(fn, args) {
|
|
38
|
+
const callable = fn;
|
|
39
|
+
return callable(...args);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The wrapper used to call functions within the parser.
|
|
43
|
+
*
|
|
44
|
+
* @param functionName The name of the function being called
|
|
45
|
+
* @param args
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function callFunction(functionName, args) {
|
|
49
|
+
// An empty parser argument scope currently resolves to undefined. Normalize that internal
|
|
50
|
+
// sentinel before arity validation so registered zero-argument functions receive no arguments.
|
|
51
|
+
if (args.length === 1 && args[0] === undefined) {
|
|
52
|
+
args = [];
|
|
53
|
+
}
|
|
54
|
+
// The details regarding the function
|
|
55
|
+
const attributes = dispatch_1.mathFunctionRegistry[functionName];
|
|
56
|
+
if (attributes === undefined) {
|
|
57
|
+
throw new errors_1.ParserError(`Unsupported function ${functionName}`);
|
|
58
|
+
}
|
|
59
|
+
const { fn, minArgs, maxArgs, maxPrecision, equationArgs, distElWise, deferArguments, returnBoundary, } = attributes;
|
|
60
|
+
// Complain if the number of arguments provided is less that what is allowed
|
|
61
|
+
if (minArgs > -1 && args.length < minArgs) {
|
|
62
|
+
throw new errors_1.ParserError(`${functionName} requires a minimum of ${minArgs} arguments but ${args.length} provided!`);
|
|
63
|
+
}
|
|
64
|
+
// Complain if the number of arguments provided is greater than what is allowed
|
|
65
|
+
if (maxArgs > -1 && args.length > maxArgs) {
|
|
66
|
+
throw new errors_1.ParserError(`${functionName} allows a maximum of ${maxArgs} arguments but ${args.length} provided!`);
|
|
67
|
+
}
|
|
68
|
+
let result;
|
|
69
|
+
if (deferArguments) {
|
|
70
|
+
// Deferred functions own the timing and frequency of argument evaluation.
|
|
71
|
+
const invoke = () => invokeMathFunction(fn, args);
|
|
72
|
+
result = returnBoundary ? (0, controlFlow_1.parserReturnBoundary)(invoke) : invoke();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const entityArgs = [];
|
|
76
|
+
for (const arg of args) {
|
|
77
|
+
if (typeof arg === 'function') {
|
|
78
|
+
throw new errors_1.ParserError((0, errors_1.message)('malformedExpression'));
|
|
79
|
+
}
|
|
80
|
+
entityArgs.push(arg);
|
|
81
|
+
}
|
|
82
|
+
// A structured entity carrying symbolic bracket access represents one unresolved
|
|
83
|
+
// scalar value. Normalize it before equation checks, distribution, or invocation.
|
|
84
|
+
const normalizedArgs = entityArgs.map(arg => Expression_1.Expression.fromSymbolicAccess(arg) ?? arg);
|
|
85
|
+
if (attributes.level === 'system') {
|
|
86
|
+
for (let i = 0; i < normalizedArgs.length; i++) {
|
|
87
|
+
if (Equation_1.Equation.isEquation(normalizedArgs[i]) && !equationArgs?.includes(i)) {
|
|
88
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: 'Equation' }));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const elementWiseArgs = distElWise
|
|
93
|
+
? normalizedArgs.filter((arg) => Vector_1.Vector.isVector(arg) || Matrix_1.Matrix.isMatrix(arg))
|
|
94
|
+
: [];
|
|
95
|
+
if (elementWiseArgs.length > 0) {
|
|
96
|
+
const structure = elementWiseArgs[0];
|
|
97
|
+
for (const arg of elementWiseArgs) {
|
|
98
|
+
let dimensionsMatch;
|
|
99
|
+
if (Vector_1.Vector.isVector(structure)) {
|
|
100
|
+
dimensionsMatch = Vector_1.Vector.isVector(arg) && structure.count() === arg.count();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
dimensionsMatch = Matrix_1.Matrix.isMatrix(arg) && structure.dimensionsMatch(arg);
|
|
104
|
+
}
|
|
105
|
+
if (!dimensionsMatch) {
|
|
106
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: functionName }));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
result = distribute((_element, i, j) => {
|
|
110
|
+
const scalarArgs = normalizedArgs.map(arg => {
|
|
111
|
+
let scalarArg = arg;
|
|
112
|
+
if (Vector_1.Vector.isVector(arg)) {
|
|
113
|
+
scalarArg = arg.__get__([i]);
|
|
114
|
+
}
|
|
115
|
+
else if (Matrix_1.Matrix.isMatrix(arg)) {
|
|
116
|
+
scalarArg = arg.get(i, j);
|
|
117
|
+
}
|
|
118
|
+
return scalarArg;
|
|
119
|
+
});
|
|
120
|
+
return callFunction(functionName, scalarArgs);
|
|
121
|
+
}, structure);
|
|
122
|
+
}
|
|
123
|
+
// Call and return
|
|
124
|
+
else if (!fn || Settings_1.Settings.DEFER_SIMPLIFICATION) {
|
|
125
|
+
result = Expression_1.Expression.toFunction(functionName, normalizedArgs);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
result = invokeMathFunction(fn, normalizedArgs);
|
|
129
|
+
}
|
|
130
|
+
// Ensure that this function always returns even if it's a symbolic function. This will
|
|
131
|
+
// occur if the function didn't return a value.
|
|
132
|
+
if (!result) {
|
|
133
|
+
result = Expression_1.Expression.toFunction(functionName, normalizedArgs);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Let all future calls know that an inferior precision was used.
|
|
137
|
+
if (maxPrecision) {
|
|
138
|
+
result.precision = maxPrecision;
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Combines all base operations into one object for parser.
|
|
144
|
+
*/
|
|
145
|
+
exports._ = {
|
|
146
|
+
plus: add_1.add,
|
|
147
|
+
minus: subtract_1.subtract,
|
|
148
|
+
times: multiply_1.multiply,
|
|
149
|
+
div: divide_1.divide,
|
|
150
|
+
pow: power_1.power,
|
|
151
|
+
mod: modulo,
|
|
152
|
+
percent: percentage,
|
|
153
|
+
// ASSERTIVE FUNCTIONS
|
|
154
|
+
assertEQ: assertiveFunctions_1.assertEQ,
|
|
155
|
+
assertGT: assertiveFunctions_1.assertGT,
|
|
156
|
+
assertGTE: assertiveFunctions_1.assertGTE,
|
|
157
|
+
assertLT: assertiveFunctions_1.assertLT,
|
|
158
|
+
assertLTE: assertiveFunctions_1.assertLTE,
|
|
159
|
+
comma: comma_1.comma,
|
|
160
|
+
assign: scope_1.assign,
|
|
161
|
+
functionAssign: functionAssign,
|
|
162
|
+
setEqual: setEqual,
|
|
163
|
+
lt: lt,
|
|
164
|
+
lte: lte,
|
|
165
|
+
eq: eq,
|
|
166
|
+
gt: gt,
|
|
167
|
+
gte: gte,
|
|
168
|
+
minusPrefix: subtract_1.subtractPrefix,
|
|
169
|
+
plusPrefix: add_1.addPrefix,
|
|
170
|
+
factorial: math_1.factorial,
|
|
171
|
+
doubleFactorial: math_1.doubleFactorial,
|
|
172
|
+
// dot: dot,
|
|
173
|
+
// IN: IN,
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Applies a scalar function over a copied Vector or Matrix while preserving its shape.
|
|
177
|
+
* Matrix cells must remain Expressions because Matrix does not permit aggregate elements.
|
|
178
|
+
*/
|
|
179
|
+
function distribute(fn, structure) {
|
|
180
|
+
let retval;
|
|
181
|
+
if (Vector_1.Vector.isVector(structure)) {
|
|
182
|
+
retval = structure.copy().each((v, i) => {
|
|
183
|
+
return fn(v, i);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
retval = structure.copy().each((v, i, j) => {
|
|
188
|
+
const result = fn(v, Number(i), Number(j));
|
|
189
|
+
if (!Expression_1.Expression.isExpression(result)) {
|
|
190
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: constants_1.dataTypes[result.dataType] }));
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return retval;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Set's one expression equal to the other
|
|
199
|
+
* @param a
|
|
200
|
+
* @param b
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
203
|
+
function setEqual(a, b) {
|
|
204
|
+
if (!(Expression_1.Expression.isExpression(a) || Expression_1.Expression.isExpression(b))) {
|
|
205
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
206
|
+
}
|
|
207
|
+
return new Equation_1.Equation(a, b);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Registers a symbolic function from a deferred declaration body.
|
|
211
|
+
*
|
|
212
|
+
* The parser preserves the declaration as the parameter expressions followed by
|
|
213
|
+
* the function name. Each part of the signature must remain a plain variable. The
|
|
214
|
+
* right-hand callback owns compiled parser RPN and is executed only when the registered
|
|
215
|
+
* function is called.
|
|
216
|
+
*
|
|
217
|
+
* @param a - Deferred function signature.
|
|
218
|
+
* @param body - Deferred symbolic function body.
|
|
219
|
+
* @returns The registered function signature.
|
|
220
|
+
*/
|
|
221
|
+
function functionAssign(a, body) {
|
|
222
|
+
if (!Collection_1.Collection.isCollection(a)) {
|
|
223
|
+
throw new errors_1.UnexpectedInputError(`Invalid function declaration ${a.text()}.`);
|
|
224
|
+
}
|
|
225
|
+
const signature = [...a.getElements()];
|
|
226
|
+
const functionExpression = signature.pop();
|
|
227
|
+
if (!Expression_1.Expression.isExpression(functionExpression)) {
|
|
228
|
+
throw new errors_1.UnexpectedInputError(`Invalid function declaration ${a.text()}.`);
|
|
229
|
+
}
|
|
230
|
+
const name = (0, utils_1.assertPlainVariableAndGetString)(functionExpression);
|
|
231
|
+
const args = signature.map(argument => {
|
|
232
|
+
if (!Expression_1.Expression.isExpression(argument)) {
|
|
233
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: argument.text() }));
|
|
234
|
+
}
|
|
235
|
+
return (0, utils_1.assertPlainVariableAndGetString)(argument);
|
|
236
|
+
});
|
|
237
|
+
(0, setFunction_1.setFunction)({
|
|
238
|
+
type: 'symbolic',
|
|
239
|
+
name,
|
|
240
|
+
minArgs: args.length,
|
|
241
|
+
maxArgs: args.length,
|
|
242
|
+
fn: (0, functions_1.wrappedFunction)(body, args),
|
|
243
|
+
});
|
|
244
|
+
return Expression_1.Expression.toFunction(name, args.map(argument => Expression_1.Expression.Variable(argument)));
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Returns 1 if two values are equal otherwise 0
|
|
248
|
+
* @param a
|
|
249
|
+
* @param b
|
|
250
|
+
* @returns
|
|
251
|
+
*/
|
|
252
|
+
function eq(a, b) {
|
|
253
|
+
return Expression_1.Expression.create(Number(a.eq(b)));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Returns 1 if a is greater than b otherwise 0
|
|
257
|
+
* @param a
|
|
258
|
+
* @param b
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
function gt(a, b) {
|
|
262
|
+
return Expression_1.Expression.create(Number(a.gt(b)));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns 1 if a is less than b otherwise 0
|
|
266
|
+
* @param a
|
|
267
|
+
* @param b
|
|
268
|
+
* @returns
|
|
269
|
+
*/
|
|
270
|
+
function lt(a, b) {
|
|
271
|
+
return Expression_1.Expression.create(Number(a.lt(b)));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Computes the remainder for the parser's infix `%` operator.
|
|
275
|
+
*
|
|
276
|
+
* The symbolic implementation already lives on {@link Expression.mod}; this adapter keeps
|
|
277
|
+
* operator dispatch in the same parser layer as the other arithmetic operations.
|
|
278
|
+
*/
|
|
279
|
+
function modulo(a, b) {
|
|
280
|
+
if (!Expression_1.Expression.isExpression(a) || !Expression_1.Expression.isExpression(b)) {
|
|
281
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
282
|
+
}
|
|
283
|
+
return a.mod(b);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Converts an expression from percentage notation to its exact fractional value.
|
|
287
|
+
*/
|
|
288
|
+
function percentage(a) {
|
|
289
|
+
if (!Expression_1.Expression.isExpression(a)) {
|
|
290
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
291
|
+
}
|
|
292
|
+
const retval = a.div(100);
|
|
293
|
+
return retval;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns 1 if a is greater than or equal to b otherwise 0
|
|
297
|
+
* @param a
|
|
298
|
+
* @param b
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
301
|
+
function gte(a, b) {
|
|
302
|
+
return Expression_1.Expression.create(Number(a.gte(b)));
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Returns 1 if a is less than or equal to b otherwise 0
|
|
306
|
+
* @param a
|
|
307
|
+
* @param b
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
function lte(a, b) {
|
|
311
|
+
return Expression_1.Expression.create(Number(a.lte(b)));
|
|
312
|
+
}
|
|
313
|
+
function isRoutedOperation(operation) {
|
|
314
|
+
return (operation === 'pow' ||
|
|
315
|
+
operation === 'times' ||
|
|
316
|
+
operation === 'div' ||
|
|
317
|
+
operation === 'minus' ||
|
|
318
|
+
operation === 'plus' ||
|
|
319
|
+
operation === 'eq' ||
|
|
320
|
+
operation === 'lt' ||
|
|
321
|
+
operation === 'lte' ||
|
|
322
|
+
operation === 'gt' ||
|
|
323
|
+
operation === 'gte');
|
|
324
|
+
}
|
|
325
|
+
function routeOperation(target, operand, operation) {
|
|
326
|
+
const retval = target[operation](operand);
|
|
327
|
+
return typeof retval === 'boolean' ? Expression_1.Expression.create(Number(retval)) : retval;
|
|
328
|
+
}
|
|
329
|
+
function dispatchDynamicOperation(a, b, operation) {
|
|
330
|
+
// Preserve the parser's historically loose dispatch for operator actions outside
|
|
331
|
+
// RoutedOperation. Tightening these actions may change existing runtime behavior.
|
|
332
|
+
const useA = a.isEnumerable || Equation_1.Equation.isEquation(a);
|
|
333
|
+
const target = useA ? a : b;
|
|
334
|
+
const operand = useA ? b : a;
|
|
335
|
+
const dynamicTarget = target;
|
|
336
|
+
const dynamicOperation = dynamicTarget[operation];
|
|
337
|
+
if (!dynamicOperation) {
|
|
338
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
339
|
+
}
|
|
340
|
+
const retval = dynamicOperation.call(target, operand);
|
|
341
|
+
// Wrap booleans since those are used both inside and outside of the parser
|
|
342
|
+
return typeof retval === 'boolean' ? Expression_1.Expression.create(Number(retval)) : retval;
|
|
343
|
+
}
|
|
344
|
+
function route(a, b, operation) {
|
|
345
|
+
let retval;
|
|
346
|
+
if (operation === 'assign') {
|
|
347
|
+
retval = (0, scope_1.assign)(a, b);
|
|
348
|
+
}
|
|
349
|
+
else if (operation === 'comma') {
|
|
350
|
+
retval = (0, comma_1.comma)(a, b);
|
|
351
|
+
}
|
|
352
|
+
else if (operation === 'in') {
|
|
353
|
+
// Membership is the infix form of contains(container, value), so reverse the operands.
|
|
354
|
+
retval = callFunction('contains', [b, a]);
|
|
355
|
+
}
|
|
356
|
+
else if (isRoutedOperation(operation)) {
|
|
357
|
+
if (Equation_1.Equation.isEquation(a) || Equation_1.Equation.isEquation(b)) {
|
|
358
|
+
if (Equation_1.Equation.isEquation(a) && Equation_1.Equation.isEquation(b)) {
|
|
359
|
+
if (['eq', 'lt', 'lte', 'gt', 'gte'].includes(operation)) {
|
|
360
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else if (Equation_1.Equation.isEquation(a)) {
|
|
367
|
+
if (['plus', 'minus', 'times', 'div'].includes(operation)) {
|
|
368
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else if (operation === 'plus' || operation === 'times') {
|
|
375
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else if ((0, structuredEntityUtils_1.isEnumerable)(a)) {
|
|
382
|
+
retval = routeOperation(a, b, operation);
|
|
383
|
+
}
|
|
384
|
+
else if ((Vector_1.Vector.isVector(b) || Matrix_1.Matrix.isMatrix(b)) &&
|
|
385
|
+
(operation === 'minus' || operation === 'div' || operation === 'pow')) {
|
|
386
|
+
// Scalar-left operations are not commutative. Preserve operand order while
|
|
387
|
+
// distributing the operation over the structured right-hand operand.
|
|
388
|
+
if (!Expression_1.Expression.isExpression(a)) {
|
|
389
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
390
|
+
}
|
|
391
|
+
// A scalar base with a Matrix exponent is a matrix-function question. It must
|
|
392
|
+
// not be reversed into Matrix.pow() or silently treated as element-wise power.
|
|
393
|
+
if (Matrix_1.Matrix.isMatrix(b) && operation === 'pow') {
|
|
394
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
395
|
+
}
|
|
396
|
+
retval = distribute(element => {
|
|
397
|
+
let elementResult;
|
|
398
|
+
if (Expression_1.Expression.isExpression(element)) {
|
|
399
|
+
if (operation === 'minus') {
|
|
400
|
+
elementResult = (0, subtract_1.subtract)(a, element);
|
|
401
|
+
}
|
|
402
|
+
else if (operation === 'div') {
|
|
403
|
+
elementResult = (0, divide_1.divide)(a, element);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
elementResult = (0, power_1.power)(a, element);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
const nestedResult = route(a, element, operation);
|
|
411
|
+
if (Array.isArray(nestedResult)) {
|
|
412
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
413
|
+
}
|
|
414
|
+
elementResult = nestedResult;
|
|
415
|
+
}
|
|
416
|
+
return elementResult;
|
|
417
|
+
}, b);
|
|
418
|
+
}
|
|
419
|
+
else if ((0, structuredEntityUtils_1.isEnumerable)(b)) {
|
|
420
|
+
retval = routeOperation(b, a, operation);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
428
|
+
}
|
|
429
|
+
return retval;
|
|
430
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Expression } from '../../expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Multiplies two Expressions
|
|
4
|
+
*
|
|
5
|
+
* @param a
|
|
6
|
+
* @param b
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function multiply(a: Expression, b: Expression): Expression;
|
|
10
|
+
export declare function merge(a: Expression, b: Expression): Expression;
|
|
11
|
+
export declare function canonicalizeRadicals(x: Expression): Expression;
|