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,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printRPN = exports.printTokens = void 0;
|
|
4
|
+
exports.createTypesMap = createTypesMap;
|
|
5
|
+
exports.inspectTokens = inspectTokens;
|
|
6
|
+
exports.inspectExpressionData = inspectExpressionData;
|
|
7
|
+
exports.inspectEntity = inspectEntity;
|
|
8
|
+
exports.inspectParse = inspectParse;
|
|
9
|
+
exports.inspectTermData = inspectTermData;
|
|
10
|
+
exports.inspectPolynomialData = inspectPolynomialData;
|
|
11
|
+
exports.printE = printE;
|
|
12
|
+
exports.inspectExpression = inspectExpression;
|
|
13
|
+
exports.inspectTerm = inspectTerm;
|
|
14
|
+
exports.inspectPolynomial = inspectPolynomial;
|
|
15
|
+
exports.hr = hr;
|
|
16
|
+
exports.simpleSerialize = simpleSerialize;
|
|
17
|
+
const Collection_1 = require("../core/classes/collection/Collection");
|
|
18
|
+
const Dictionary_1 = require("../core/classes/dictionary/Dictionary");
|
|
19
|
+
const Equation_1 = require("../core/classes/equation/Equation");
|
|
20
|
+
const Expression_1 = require("../core/classes/expression/Expression");
|
|
21
|
+
const Matrix_1 = require("../core/classes/matrix/Matrix");
|
|
22
|
+
const Parser_1 = require("../core/classes/parser/Parser");
|
|
23
|
+
const preprocess_1 = require("../core/classes/parser/preprocess");
|
|
24
|
+
const Polynomial_1 = require("../core/classes/polynomial/Polynomial");
|
|
25
|
+
const ValuesSet_1 = require("../core/classes/valuesSet/ValuesSet");
|
|
26
|
+
const Vector_1 = require("../core/classes/vector/Vector");
|
|
27
|
+
const Scope_1 = require("../core/common/classes/Scope");
|
|
28
|
+
const dispatch_1 = require("../core/dispatch");
|
|
29
|
+
function createTypesMap() {
|
|
30
|
+
const map = {};
|
|
31
|
+
for (const [type, value] of Object.entries(Expression_1.Expression.TYPES)) {
|
|
32
|
+
map[value] = type;
|
|
33
|
+
}
|
|
34
|
+
return map;
|
|
35
|
+
}
|
|
36
|
+
/** Converts a parser token scope to JSON-safe diagnostic data. */
|
|
37
|
+
function inspectTokens(scope) {
|
|
38
|
+
const items = [];
|
|
39
|
+
for (const item of scope) {
|
|
40
|
+
let inspected;
|
|
41
|
+
if (Scope_1.Scope.isScope(item)) {
|
|
42
|
+
inspected = inspectTokens(item);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
inspected = {
|
|
46
|
+
kind: 'token',
|
|
47
|
+
value: item.value,
|
|
48
|
+
type: item.type ?? null,
|
|
49
|
+
position: item.position,
|
|
50
|
+
text: item.toString(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
items.push(inspected);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
kind: 'scope',
|
|
57
|
+
type: scope.type,
|
|
58
|
+
depth: scope.depth,
|
|
59
|
+
column: scope.column,
|
|
60
|
+
isOpen: scope.isOpen,
|
|
61
|
+
implicitMultiply: scope.implicitMultiply,
|
|
62
|
+
deferLHSResolution: scope.deferLHSResolution,
|
|
63
|
+
deferRHSResolution: scope.deferRHSResolution,
|
|
64
|
+
text: scope.text(),
|
|
65
|
+
typedText: scope.text(false),
|
|
66
|
+
items,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Converts an Expression tree to JSON-safe diagnostic data without changing it. */
|
|
70
|
+
function inspectExpressionData(obj) {
|
|
71
|
+
const typesMap = createTypesMap();
|
|
72
|
+
let elements = null;
|
|
73
|
+
let args = null;
|
|
74
|
+
if (obj.elements) {
|
|
75
|
+
elements = {};
|
|
76
|
+
for (const [key, element] of Object.entries(obj.elements)) {
|
|
77
|
+
elements[key] = inspectExpressionData(element);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (obj.args) {
|
|
81
|
+
args = obj.args.map(argument => inspectExpressionData(argument));
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
kind: 'Expression',
|
|
85
|
+
type: obj.type,
|
|
86
|
+
typeName: typesMap[obj.type] ?? 'UNKNOWN',
|
|
87
|
+
dataType: obj.dataType,
|
|
88
|
+
text: obj.copy().text(),
|
|
89
|
+
value: obj.value,
|
|
90
|
+
name: obj.name ?? null,
|
|
91
|
+
precision: obj.precision ?? null,
|
|
92
|
+
deferred: obj.deferred,
|
|
93
|
+
multiplier: obj.multiplier ? obj.multiplier.text() : null,
|
|
94
|
+
power: obj.power ? inspectExpressionData(obj.power) : null,
|
|
95
|
+
base: obj.base ? inspectExpressionData(obj.base) : null,
|
|
96
|
+
elements,
|
|
97
|
+
args,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Converts any current parser entity to plain diagnostic data. */
|
|
101
|
+
function inspectEntity(entity) {
|
|
102
|
+
let retval;
|
|
103
|
+
if (Expression_1.Expression.isExpression(entity)) {
|
|
104
|
+
retval = inspectExpressionData(entity);
|
|
105
|
+
}
|
|
106
|
+
else if (Equation_1.Equation.isEquation(entity)) {
|
|
107
|
+
retval = {
|
|
108
|
+
kind: 'Equation',
|
|
109
|
+
dataType: entity.dataType,
|
|
110
|
+
text: entity.copy().text(),
|
|
111
|
+
LHS: inspectExpressionData(entity.LHS),
|
|
112
|
+
RHS: inspectExpressionData(entity.RHS),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
else if (Vector_1.Vector.isVector(entity)) {
|
|
116
|
+
retval = {
|
|
117
|
+
kind: 'Vector',
|
|
118
|
+
dataType: entity.dataType,
|
|
119
|
+
text: entity.copy().text(),
|
|
120
|
+
elements: entity.elements.map(element => inspectEntity(element)),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
else if (Matrix_1.Matrix.isMatrix(entity)) {
|
|
124
|
+
retval = {
|
|
125
|
+
kind: 'Matrix',
|
|
126
|
+
dataType: entity.dataType,
|
|
127
|
+
text: entity.copy().text(),
|
|
128
|
+
elements: entity.elements.map(row => row.map(element => inspectExpressionData(element))),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else if (ValuesSet_1.ValuesSet.isValuesSet(entity)) {
|
|
132
|
+
retval = {
|
|
133
|
+
kind: 'ValuesSet',
|
|
134
|
+
dataType: entity.dataType,
|
|
135
|
+
text: entity.copy().text(),
|
|
136
|
+
elements: entity.elements.map(element => inspectEntity(element)),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else if (Dictionary_1.Dictionary.isDictionary(entity)) {
|
|
140
|
+
retval = {
|
|
141
|
+
kind: 'Dictionary',
|
|
142
|
+
dataType: entity.dataType,
|
|
143
|
+
text: entity.copy().text(),
|
|
144
|
+
entries: entity.entries().map(([key, value]) => ({
|
|
145
|
+
key,
|
|
146
|
+
value: inspectEntity(value),
|
|
147
|
+
})),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else if (Collection_1.Collection.isCollection(entity)) {
|
|
151
|
+
retval = {
|
|
152
|
+
kind: 'Collection',
|
|
153
|
+
dataType: entity.dataType,
|
|
154
|
+
text: entity.copy().text(),
|
|
155
|
+
elements: entity.getElements().map(element => inspectEntity(element)),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
throw new TypeError('Unsupported parser entity');
|
|
160
|
+
}
|
|
161
|
+
return retval;
|
|
162
|
+
}
|
|
163
|
+
/** Inspects one parser input using the same preprocessing as Parser.parse(). */
|
|
164
|
+
function inspectParse(source, values) {
|
|
165
|
+
const normalizedSource = (0, preprocess_1.preprocess)(source, dispatch_1.mathFunctionRegistry);
|
|
166
|
+
const tokenScope = Parser_1.Parser.tokenize(normalizedSource);
|
|
167
|
+
const tokens = inspectTokens(tokenScope);
|
|
168
|
+
const rpn = inspectTokens(Parser_1.Parser.toRPN(tokenScope));
|
|
169
|
+
const result = inspectEntity(Parser_1.Parser.parse(source, values));
|
|
170
|
+
return {
|
|
171
|
+
source,
|
|
172
|
+
normalizedSource,
|
|
173
|
+
tokens,
|
|
174
|
+
rpn,
|
|
175
|
+
result,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Converts a polynomial Term to JSON-safe diagnostic data without touching its caches. */
|
|
179
|
+
function inspectTermData(t) {
|
|
180
|
+
const multidegree = t.variables.map(variable => t.powers[variable] ?? 0);
|
|
181
|
+
const totalPower = multidegree.reduce((sum, power) => sum + power, 0);
|
|
182
|
+
return {
|
|
183
|
+
kind: 'Term',
|
|
184
|
+
text: t.copy().text(),
|
|
185
|
+
coefficient: inspectExpressionData(t.coeff),
|
|
186
|
+
powers: { ...t.powers },
|
|
187
|
+
multidegree,
|
|
188
|
+
totalPower,
|
|
189
|
+
variables: [...t.variables],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** Converts a Polynomial to JSON-safe diagnostic data. */
|
|
193
|
+
function inspectPolynomialData(p) {
|
|
194
|
+
return {
|
|
195
|
+
kind: 'Polynomial',
|
|
196
|
+
text: new Polynomial_1.Polynomial(p).text(),
|
|
197
|
+
expression: inspectExpressionData(p.expression),
|
|
198
|
+
ordering: p.ordering,
|
|
199
|
+
isMultivariate: p.isMultivariate,
|
|
200
|
+
variables: [...p.variables],
|
|
201
|
+
terms: p.terms.map(term => inspectTermData(term)),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// https://stackoverflow.com/questions/57802057/eslint-configuring-no-unused-vars-for-typescript
|
|
205
|
+
function printE(obj) {
|
|
206
|
+
const output = [];
|
|
207
|
+
for (const x in obj) {
|
|
208
|
+
let str = String(obj[x]);
|
|
209
|
+
if (typeof obj === 'object') {
|
|
210
|
+
try {
|
|
211
|
+
// Try to get a better representation that [object Object]
|
|
212
|
+
str = JSON.stringify(obj[x]);
|
|
213
|
+
}
|
|
214
|
+
catch { }
|
|
215
|
+
}
|
|
216
|
+
output.push(`${x}: ${str}`);
|
|
217
|
+
}
|
|
218
|
+
console.log(output.join(', '));
|
|
219
|
+
}
|
|
220
|
+
;
|
|
221
|
+
const printTokens = (tokens, valuesOnly = true) => {
|
|
222
|
+
console.log(tokens.text(valuesOnly));
|
|
223
|
+
};
|
|
224
|
+
exports.printTokens = printTokens;
|
|
225
|
+
const printRPN = (str) => {
|
|
226
|
+
const source = (0, preprocess_1.preprocess)(str, dispatch_1.mathFunctionRegistry);
|
|
227
|
+
(0, exports.printTokens)(Parser_1.Parser.toRPN(Parser_1.Parser.tokenize(source)));
|
|
228
|
+
};
|
|
229
|
+
exports.printRPN = printRPN;
|
|
230
|
+
function inspectExpression(obj, depth = 0) {
|
|
231
|
+
const tab = '\t'.repeat(depth);
|
|
232
|
+
const typesMap = createTypesMap();
|
|
233
|
+
let elementsStr = tab + '{\n';
|
|
234
|
+
if (obj.elements) {
|
|
235
|
+
const elements = obj.getElements();
|
|
236
|
+
for (const x in elements) {
|
|
237
|
+
elementsStr += inspectExpression(elements[x], depth + 1);
|
|
238
|
+
}
|
|
239
|
+
elementsStr += `\n ${tab}}`;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
elementsStr = 'undefined';
|
|
243
|
+
}
|
|
244
|
+
let argsStr = tab + '[\n';
|
|
245
|
+
if (obj.args) {
|
|
246
|
+
const args = obj.getArguments();
|
|
247
|
+
for (const arg of args) {
|
|
248
|
+
argsStr += inspectExpression(arg, depth + 1);
|
|
249
|
+
}
|
|
250
|
+
argsStr += `\n ${tab}]`;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
argsStr = 'undefined';
|
|
254
|
+
}
|
|
255
|
+
return `
|
|
256
|
+
${tab}{
|
|
257
|
+
${tab} type: ${typesMap[obj.type]},
|
|
258
|
+
${tab} dataType: ${obj.dataType},
|
|
259
|
+
${tab} precision: ${obj.precision},
|
|
260
|
+
${tab} value: ${obj.value},
|
|
261
|
+
${tab} multiplier: ${obj.multiplier ? obj.multiplier?.text() : obj.multiplier},
|
|
262
|
+
${tab} power: ${obj.power ? obj.power?.text() : obj.power},
|
|
263
|
+
${tab} name: ${obj.name},
|
|
264
|
+
${tab} deferred: ${obj.deferred},
|
|
265
|
+
${tab} elements: ${elementsStr},
|
|
266
|
+
${tab} args: ${argsStr},
|
|
267
|
+
${tab}}`;
|
|
268
|
+
}
|
|
269
|
+
function inspectTerm(t) {
|
|
270
|
+
return `<Term(${t.text()}) coeff: ${t.coeff}, mdg: ${t.getMultidegArray()}, total power: ${t.getTotalPower()}, vars: ${t.variables}>`;
|
|
271
|
+
}
|
|
272
|
+
function inspectPolynomial(p) {
|
|
273
|
+
let terms = '';
|
|
274
|
+
for (const t of p.terms) {
|
|
275
|
+
terms += `\t ${inspectTerm(t)}\n`;
|
|
276
|
+
}
|
|
277
|
+
return `<Polynomial(${p.text()})
|
|
278
|
+
terms:
|
|
279
|
+
${terms}\tLM: ${p.LM()}
|
|
280
|
+
ordering: ${p.ordering}
|
|
281
|
+
>`;
|
|
282
|
+
}
|
|
283
|
+
function hr(symbol = '_', length = 70) {
|
|
284
|
+
console.log(symbol.repeat(length));
|
|
285
|
+
}
|
|
286
|
+
function simpleSerialize(obj) {
|
|
287
|
+
let retval = '{';
|
|
288
|
+
for (const x in obj) {
|
|
289
|
+
retval += `${x}: ${obj[x]},`;
|
|
290
|
+
}
|
|
291
|
+
if (retval.at(-1) === ',') {
|
|
292
|
+
retval = retval.slice(0, -1);
|
|
293
|
+
}
|
|
294
|
+
return retval + '}';
|
|
295
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gcd = gcd;
|
|
4
|
+
exports.isEven = isEven;
|
|
5
|
+
const decimal_js_1 = require("decimal.js");
|
|
6
|
+
function gcd(a, b) {
|
|
7
|
+
while (!b.equals(0)) {
|
|
8
|
+
const t = a;
|
|
9
|
+
a = b;
|
|
10
|
+
b = t.mod(b);
|
|
11
|
+
}
|
|
12
|
+
return a;
|
|
13
|
+
}
|
|
14
|
+
function isEven(n) {
|
|
15
|
+
return decimal_js_1.Decimal.mod(n, 2).eq(0);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a pair of numbers given a set of prime numbers
|
|
3
|
+
* @param factors The list of prime factors to be used to generate the pairs
|
|
4
|
+
* @param target The target number that the pairs must equal
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function factorPairs(factors: number[], target: number): number[][];
|
|
8
|
+
/**
|
|
9
|
+
* Gets the largest factor pair given a set of prime factors and a target
|
|
10
|
+
* @param factors The list of prime factors to be used to generate the pairs
|
|
11
|
+
* @param target The target number that the pairs must equal
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function maxPair(factors: number[], target: number): number[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.factorPairs = factorPairs;
|
|
4
|
+
exports.maxPair = maxPair;
|
|
5
|
+
/**
|
|
6
|
+
* Generates a pair of numbers given a set of prime numbers
|
|
7
|
+
* @param factors The list of prime factors to be used to generate the pairs
|
|
8
|
+
* @param target The target number that the pairs must equal
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function factorPairs(factors, target) {
|
|
12
|
+
const products = new Set();
|
|
13
|
+
// Generate all subset products
|
|
14
|
+
function backtrack(index, currentProduct) {
|
|
15
|
+
if (index === factors.length) {
|
|
16
|
+
products.add(currentProduct);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Skip current number
|
|
20
|
+
backtrack(index + 1, currentProduct);
|
|
21
|
+
// Include current number
|
|
22
|
+
backtrack(index + 1, currentProduct * factors[index]);
|
|
23
|
+
}
|
|
24
|
+
backtrack(0, 1);
|
|
25
|
+
const result = [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const p of products) {
|
|
28
|
+
if (p > 0 && target % p === 0) {
|
|
29
|
+
const q = target / p;
|
|
30
|
+
const key = Math.min(p, q); // prevent mirrored duplicates
|
|
31
|
+
if (!seen.has(key)) {
|
|
32
|
+
seen.add(key);
|
|
33
|
+
result.push([Math.min(p, q), Math.max(p, q)]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result.sort((a, b) => a[0] - b[0]);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the largest factor pair given a set of prime factors and a target
|
|
41
|
+
* @param factors The list of prime factors to be used to generate the pairs
|
|
42
|
+
* @param target The target number that the pairs must equal
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
function maxPair(factors, target) {
|
|
46
|
+
const pair = factorPairs(factors, target).at(-1);
|
|
47
|
+
if (!pair) {
|
|
48
|
+
return [1, target];
|
|
49
|
+
}
|
|
50
|
+
return pair;
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the first encountered element in an object
|
|
3
|
+
*
|
|
4
|
+
* @param obj Any object
|
|
5
|
+
* @returns The first element encountered
|
|
6
|
+
*/
|
|
7
|
+
export declare function anyObject<T>(obj: Record<string, T>): T | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Converts an array to an object with the key specified as a callback.
|
|
10
|
+
*
|
|
11
|
+
* @param arr
|
|
12
|
+
* @param key
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function arrayToObject<T>(arr: T[], key: (k: T, i: number) => number | string): Record<string | number, T>;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a random object that can be used to evaluate a function
|
|
18
|
+
*
|
|
19
|
+
* @param vars
|
|
20
|
+
* @param min
|
|
21
|
+
* @param max
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function randomEvalObj(vars: string[], min?: number, max?: number): {
|
|
25
|
+
[variable: string]: number;
|
|
26
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Get the first encountered element in an object
|
|
4
|
+
*
|
|
5
|
+
* @param obj Any object
|
|
6
|
+
* @returns The first element encountered
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.anyObject = anyObject;
|
|
10
|
+
exports.arrayToObject = arrayToObject;
|
|
11
|
+
exports.randomEvalObj = randomEvalObj;
|
|
12
|
+
const numeric_1 = require("../core/functions/numeric");
|
|
13
|
+
function anyObject(obj) {
|
|
14
|
+
for (const x in obj) {
|
|
15
|
+
return obj[x];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts an array to an object with the key specified as a callback.
|
|
20
|
+
*
|
|
21
|
+
* @param arr
|
|
22
|
+
* @param key
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function arrayToObject(arr, key) {
|
|
26
|
+
const obj = {};
|
|
27
|
+
for (let i = 0; i < arr.length; i++) {
|
|
28
|
+
const e = arr[i];
|
|
29
|
+
obj[key(e, i)] = e;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generates a random object that can be used to evaluate a function
|
|
35
|
+
*
|
|
36
|
+
* @param vars
|
|
37
|
+
* @param min
|
|
38
|
+
* @param max
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
function randomEvalObj(vars, min = 2, max) {
|
|
42
|
+
const evalObj = {};
|
|
43
|
+
max ??= (vars.length + 2) * 2;
|
|
44
|
+
// Avoid duplicate numbers
|
|
45
|
+
const values = [];
|
|
46
|
+
for (const v of vars) {
|
|
47
|
+
let randomInt = (0, numeric_1.getRandomInt)(min, max);
|
|
48
|
+
// Select a random number which hasn't been chosen already
|
|
49
|
+
while (values.includes(randomInt)) {
|
|
50
|
+
randomInt = (0, numeric_1.getRandomInt)(min, max);
|
|
51
|
+
}
|
|
52
|
+
values.push(randomInt);
|
|
53
|
+
evalObj[v] = randomInt;
|
|
54
|
+
}
|
|
55
|
+
return evalObj;
|
|
56
|
+
}
|