nerdamer 1.1.13 → 2.0.0-rc.2
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/BREAKING_CHANGES.md +244 -5
- package/LICENSE.md +184 -0
- package/README.md +232 -318
- 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 +2248 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +3 -0
- package/output/algebra/adapters.js +11 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +324 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
- package/output/algebra/algorithms/groebnerBase.js +929 -0
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +77 -0
- package/output/algebra/factor/factor.js +245 -0
- package/output/algebra/gcd/gcd.d.ts +30 -0
- package/output/algebra/gcd/gcd.js +95 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +36 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +365 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
- package/output/algebra/polynomial/modularGcd.d.ts +40 -0
- package/output/algebra/polynomial/modularGcd.js +365 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +26 -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 +237 -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 +8 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +35 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +10 -0
- package/output/api/calculus.js +22 -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/languages/deu.d.ts +3 -0
- package/output/api/languages/deu.js +266 -0
- package/output/api/languages/fra.d.ts +3 -0
- package/output/api/languages/fra.js +266 -0
- package/output/api/languages/ita.d.ts +3 -0
- package/output/api/languages/ita.js +266 -0
- package/output/api/languages/nld.d.ts +3 -0
- package/output/api/languages/nld.js +266 -0
- package/output/api/languages/por.d.ts +3 -0
- package/output/api/languages/por.js +266 -0
- package/output/api/languages/spa.d.ts +3 -0
- package/output/api/languages/spa.js +266 -0
- package/output/api/parser.d.ts +93 -0
- package/output/api/parser.js +18 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +17 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +23 -0
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +241 -0
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -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/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +609 -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/assumption/dispatch.d.ts +1 -0
- package/output/core/classes/assumption/dispatch.js +11 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +240 -0
- package/output/core/classes/complex/Complex.d.ts +109 -0
- package/output/core/classes/complex/Complex.js +153 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +454 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +216 -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 +197 -0
- package/output/core/classes/expression/Expression.d.ts +1691 -0
- package/output/core/classes/expression/Expression.js +2381 -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 +54 -0
- package/output/core/classes/expression/format.js +340 -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 +61 -0
- package/output/core/classes/expression/utils.js +235 -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 +901 -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/dispatch.d.ts +1 -0
- package/output/core/classes/matrix/dispatch.js +19 -0
- package/output/core/classes/matrix/functions.d.ts +28 -0
- package/output/core/classes/matrix/functions.js +57 -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 +493 -0
- package/output/core/classes/parser/Parser.js +1863 -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 +162 -0
- package/output/core/classes/parser/constants.js +229 -0
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -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 +236 -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 +474 -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 +438 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +328 -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 +36 -0
- package/output/core/classes/parser/preprocess.d.ts +7 -0
- package/output/core/classes/parser/preprocess.js +246 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
- package/output/core/classes/parser/scripting/controlFlow.js +279 -0
- package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
- package/output/core/classes/parser/scripting/deferred.js +65 -0
- package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
- package/output/core/classes/parser/scripting/dispatch.js +62 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +23 -0
- package/output/core/classes/parser/scripting/evaluate.js +128 -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 +8 -0
- package/output/core/classes/parser/scripting/scope.js +132 -0
- package/output/core/classes/parser/types.d.ts +130 -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 +504 -0
- package/output/core/classes/polynomial/Polynomial.js +1195 -0
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
- package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -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/adapters.d.ts +18 -0
- package/output/core/classes/polynomial/adapters.js +33 -0
- package/output/core/classes/polynomial/dispatch.d.ts +1 -0
- package/output/core/classes/polynomial/dispatch.js +14 -0
- package/output/core/classes/polynomial/functions.d.ts +77 -0
- package/output/core/classes/polynomial/functions.js +189 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +207 -0
- package/output/core/classes/rational/Rational.d.ts +501 -0
- package/output/core/classes/rational/Rational.js +829 -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 +187 -0
- package/output/core/classes/valuesSet/ValuesSet.js +399 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +501 -0
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -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 +149 -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 +62 -0
- package/output/core/common/common.js +74 -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 +806 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +52 -0
- package/output/core/dispatch.js +26 -0
- package/output/core/errors.d.ts +316 -0
- package/output/core/errors.js +349 -0
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +133 -0
- package/output/core/functions/bigint/bigint.js +444 -0
- package/output/core/functions/bigint/primeFactor.d.ts +51 -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 +139 -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.dispatch.d.ts +1 -0
- package/output/core/functions/complex.dispatch.js +16 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +665 -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 +102 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +506 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +359 -0
- package/output/index.js +739 -0
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +321 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +281 -0
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +12 -0
- package/output/math/geometry.js +55 -0
- package/output/math/math.d.ts +695 -0
- package/output/math/math.js +1955 -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 +66 -0
- package/output/math/utils.js +219 -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 +104 -0
- package/output/solve/classes/PolynomialSolver.js +492 -0
- package/output/solve/classes/SolutionSet.d.ts +172 -0
- package/output/solve/classes/SolutionSet.js +434 -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/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +53 -0
- package/output/solve/linsolve.js +233 -0
- package/output/solve/solve.d.ts +44 -0
- package/output/solve/solve.js +368 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +266 -0
- package/output/solve/utils.d.ts +10 -0
- package/output/solve/utils.js +58 -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 +296 -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 +178 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- 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,444 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.factorial = void 0;
|
|
4
|
+
exports.abs = abs;
|
|
5
|
+
exports.uniqueSortedArray = uniqueSortedArray;
|
|
6
|
+
exports.GCD = GCD;
|
|
7
|
+
exports.LCM = LCM;
|
|
8
|
+
exports.simplifyRatio = simplifyRatio;
|
|
9
|
+
exports.convert = convert;
|
|
10
|
+
exports.sign = sign;
|
|
11
|
+
exports.isEven = isEven;
|
|
12
|
+
exports.integerSquareRoot = integerSquareRoot;
|
|
13
|
+
exports.ceilIntegerSquareRoot = ceilIntegerSquareRoot;
|
|
14
|
+
exports.fibonacci = fibonacci;
|
|
15
|
+
exports.mod = mod;
|
|
16
|
+
exports.powMod = powMod;
|
|
17
|
+
exports.invMod = invMod;
|
|
18
|
+
exports.productInRange = productInRange;
|
|
19
|
+
exports.max = max;
|
|
20
|
+
exports.min = min;
|
|
21
|
+
exports.recoverCoeffsZ = recoverCoeffsZ;
|
|
22
|
+
exports.binom = binom;
|
|
23
|
+
exports.bigintLCM = bigintLCM;
|
|
24
|
+
const errors_1 = require("../../errors");
|
|
25
|
+
const string_1 = require("../string");
|
|
26
|
+
const utils_1 = require("../utils");
|
|
27
|
+
/**
|
|
28
|
+
* Returns the absolute value of a bigint
|
|
29
|
+
*
|
|
30
|
+
* @param x
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
function abs(x) {
|
|
34
|
+
return x < 0n ? -x : x;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns an array with unique values, sorted, and in reverse order.
|
|
38
|
+
*
|
|
39
|
+
* @param array
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
function uniqueSortedArray(array) {
|
|
43
|
+
return (0, utils_1.arrayUnique)([].slice.call(array).map(function (x) {
|
|
44
|
+
return abs(x);
|
|
45
|
+
})).sort();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the gcd of a set of bigints
|
|
49
|
+
*
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
function GCD(...args) {
|
|
53
|
+
// Get a unique set and convert to absolute values
|
|
54
|
+
args = uniqueSortedArray(args);
|
|
55
|
+
// Point to the first element
|
|
56
|
+
let a = args[0];
|
|
57
|
+
for (let i = 1; i < args.length; i++) {
|
|
58
|
+
let b = args[i];
|
|
59
|
+
while (true) {
|
|
60
|
+
a %= b;
|
|
61
|
+
if (a === 0n) {
|
|
62
|
+
a = b;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
b %= a;
|
|
66
|
+
if (b === 0n) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Calculates the LCM of a set of bigints
|
|
75
|
+
*
|
|
76
|
+
* @param args
|
|
77
|
+
*/
|
|
78
|
+
function LCM(...args) {
|
|
79
|
+
// Get a unique set and convert to absolute values
|
|
80
|
+
args = uniqueSortedArray(args);
|
|
81
|
+
let a = args[0];
|
|
82
|
+
for (let i = 1; i < args.length; i++) {
|
|
83
|
+
const b = args[i];
|
|
84
|
+
// Get the LCM of that of the last calculated LCM and the new number
|
|
85
|
+
a = (a * b) / GCD(a, b);
|
|
86
|
+
}
|
|
87
|
+
return a;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Simplifies a ratio of two bigints
|
|
91
|
+
*
|
|
92
|
+
* @param numerator
|
|
93
|
+
* @param denominator
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
function simplifyRatio(numerator, denominator) {
|
|
97
|
+
if (denominator !== 1n) {
|
|
98
|
+
const gcd = GCD(denominator, numerator);
|
|
99
|
+
return [numerator / gcd, denominator / gcd];
|
|
100
|
+
}
|
|
101
|
+
return [numerator, denominator];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Converts a decimal number to a rational
|
|
105
|
+
*
|
|
106
|
+
* @param numStr
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
function convert(numStr) {
|
|
110
|
+
//Split the whole and decimal
|
|
111
|
+
const [w, d] = (0, string_1.decimalSplit)(numStr);
|
|
112
|
+
//Create the denominator based on the number of decimal places
|
|
113
|
+
const denominator = 10n ** BigInt(d.length);
|
|
114
|
+
const numerator = BigInt(w + d);
|
|
115
|
+
return simplifyRatio(numerator, denominator);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns the sign of a bigint
|
|
119
|
+
*
|
|
120
|
+
* @param n
|
|
121
|
+
* @returns -1 if negative and 1 for positive and 0 for zero
|
|
122
|
+
*/
|
|
123
|
+
function sign(n) {
|
|
124
|
+
return n === 0n ? 0 : n < 0n ? -1 : 1;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a bigint is an even number
|
|
128
|
+
*
|
|
129
|
+
* @param n
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
function isEven(n) {
|
|
133
|
+
return n % 2n === 0n;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns the floor of the exact square root of a non-negative bigint.
|
|
137
|
+
*/
|
|
138
|
+
function integerSquareRoot(value) {
|
|
139
|
+
if (value < 0n) {
|
|
140
|
+
throw new RangeError((0, errors_1.message)('integerSqrtNonnegative'));
|
|
141
|
+
}
|
|
142
|
+
if (value < 2n) {
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
let root = 1n << ((BigInt(value.toString(2).length) + 1n) >> 1n);
|
|
146
|
+
while (true) {
|
|
147
|
+
const next = (root + value / root) >> 1n;
|
|
148
|
+
if (next >= root) {
|
|
149
|
+
return root;
|
|
150
|
+
}
|
|
151
|
+
root = next;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Returns the least bigint whose square is at least value. */
|
|
155
|
+
function ceilIntegerSquareRoot(value) {
|
|
156
|
+
const root = integerSquareRoot(value);
|
|
157
|
+
return root * root === value ? root : root + 1n;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Computes the nth Fibonacci number exactly using fast doubling.
|
|
161
|
+
*
|
|
162
|
+
* Negative indices use the negafibonacci identity F(-n) = (-1)^(n+1)F(n).
|
|
163
|
+
*
|
|
164
|
+
* @param n - Integer index.
|
|
165
|
+
* @returns The exact Fibonacci number.
|
|
166
|
+
*/
|
|
167
|
+
function fibonacci(n) {
|
|
168
|
+
const isNegative = n < 0n;
|
|
169
|
+
const index = isNegative ? -n : n;
|
|
170
|
+
let a = 0n;
|
|
171
|
+
let b = 1n;
|
|
172
|
+
for (const bit of index.toString(2)) {
|
|
173
|
+
const c = a * (2n * b - a);
|
|
174
|
+
const d = a * a + b * b;
|
|
175
|
+
if (bit === '0') {
|
|
176
|
+
a = c;
|
|
177
|
+
b = d;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
a = d;
|
|
181
|
+
b = c + d;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let retval = a;
|
|
185
|
+
if (isNegative && isEven(index)) {
|
|
186
|
+
retval = -retval;
|
|
187
|
+
}
|
|
188
|
+
return retval;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The big number version
|
|
192
|
+
*/
|
|
193
|
+
exports.factorial = (function () {
|
|
194
|
+
const factorialCache = [1n, 1n];
|
|
195
|
+
let i = 2;
|
|
196
|
+
/**
|
|
197
|
+
* Leverages JavaScript's native bigInt and the solution provide here:
|
|
198
|
+
* https://stackoverflow.com/questions/3959211/what-is-the-fastest-factorial-function-in-javascript
|
|
199
|
+
* to provide a fast factorial function capable of calculating large numbers.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
*
|
|
203
|
+
* This is limited to Number.MAX_SAFE_INTEGER since n is of type number since for loop requires it
|
|
204
|
+
*
|
|
205
|
+
* @param n - The factorial of the number being calculated
|
|
206
|
+
* @returns The computed factorial
|
|
207
|
+
* @throws RangeError If `n` is negative.
|
|
208
|
+
*/
|
|
209
|
+
function bigFactorial(n) {
|
|
210
|
+
if (typeof n === 'bigint') {
|
|
211
|
+
n = Number(n);
|
|
212
|
+
}
|
|
213
|
+
if (n < 0) {
|
|
214
|
+
throw new RangeError((0, errors_1.message)('factorialNegativeUndefined'));
|
|
215
|
+
}
|
|
216
|
+
// If there's a cached version return that instead
|
|
217
|
+
if (typeof factorialCache[n] != 'undefined') {
|
|
218
|
+
return factorialCache[n];
|
|
219
|
+
}
|
|
220
|
+
let result = factorialCache[i - 1];
|
|
221
|
+
for (; i <= n; i++) {
|
|
222
|
+
factorialCache[i] = result = result * BigInt(i);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
bigFactorial(100);
|
|
227
|
+
return bigFactorial;
|
|
228
|
+
})();
|
|
229
|
+
// Cache the first 100
|
|
230
|
+
/**
|
|
231
|
+
* Calculates the modulo of two numbers
|
|
232
|
+
*
|
|
233
|
+
* @param a
|
|
234
|
+
* @param b
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
function mod(a, b) {
|
|
238
|
+
const signA = sign(a);
|
|
239
|
+
const signB = sign(b);
|
|
240
|
+
let retval;
|
|
241
|
+
if (signA === signB) {
|
|
242
|
+
retval = a % b;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers
|
|
246
|
+
retval = ((a % b) + b) % b;
|
|
247
|
+
}
|
|
248
|
+
return retval;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Raises a bigint base to a non-negative bigint exponent modulo a positive modulus.
|
|
252
|
+
*
|
|
253
|
+
* Binary exponentiation keeps every intermediate value in bigint modular arithmetic.
|
|
254
|
+
*/
|
|
255
|
+
function powMod(base, exponent, modulus) {
|
|
256
|
+
if (modulus <= 0n) {
|
|
257
|
+
throw new RangeError((0, errors_1.message)('modularExponentiationPositiveModulus'));
|
|
258
|
+
}
|
|
259
|
+
if (exponent < 0n) {
|
|
260
|
+
throw new RangeError((0, errors_1.message)('modularExponentiationNonnegativeExponent'));
|
|
261
|
+
}
|
|
262
|
+
let result = 1n % modulus;
|
|
263
|
+
let factor = mod(base, modulus);
|
|
264
|
+
let power = exponent;
|
|
265
|
+
while (power > 0n) {
|
|
266
|
+
if (power % 2n === 1n) {
|
|
267
|
+
result = (result * factor) % modulus;
|
|
268
|
+
}
|
|
269
|
+
factor = (factor * factor) % modulus;
|
|
270
|
+
power /= 2n;
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Finds the multiplicative inverse of a modulo m.
|
|
276
|
+
*
|
|
277
|
+
* Returns -1 when the inverse does not exist. The extended Euclidean algorithm keeps
|
|
278
|
+
* the operation exact for bigint inputs without scanning every possible residue.
|
|
279
|
+
*
|
|
280
|
+
* @param a
|
|
281
|
+
* @param m
|
|
282
|
+
* @returns
|
|
283
|
+
*/
|
|
284
|
+
function invMod(a, m) {
|
|
285
|
+
let retval = -1n;
|
|
286
|
+
const modulus = abs(m);
|
|
287
|
+
if (modulus !== 0n) {
|
|
288
|
+
let t = 0n;
|
|
289
|
+
let nextT = 1n;
|
|
290
|
+
let r = modulus;
|
|
291
|
+
let nextR = mod(a, modulus);
|
|
292
|
+
while (nextR !== 0n) {
|
|
293
|
+
const q = r / nextR;
|
|
294
|
+
[t, nextT] = [nextT, t - q * nextT];
|
|
295
|
+
[r, nextR] = [nextR, r - q * nextR];
|
|
296
|
+
}
|
|
297
|
+
if (r === 1n) {
|
|
298
|
+
retval = mod(t, modulus);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return retval;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Gets the product given a number range start and finish
|
|
305
|
+
*
|
|
306
|
+
* @param start The start of the range
|
|
307
|
+
* @param end The end of the range
|
|
308
|
+
* @param step The increment step
|
|
309
|
+
*/
|
|
310
|
+
function productInRange(start, end, step = 1) {
|
|
311
|
+
let retval = BigInt(start);
|
|
312
|
+
let n = BigInt(start);
|
|
313
|
+
const i = BigInt(step);
|
|
314
|
+
while (n < end) {
|
|
315
|
+
n += i;
|
|
316
|
+
retval *= n;
|
|
317
|
+
}
|
|
318
|
+
return retval;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Returns the largest of a set of bigints
|
|
322
|
+
* @param args
|
|
323
|
+
* @returns
|
|
324
|
+
*/
|
|
325
|
+
function max(...args) {
|
|
326
|
+
if (args.length < 1) {
|
|
327
|
+
// Math.max() for Number returns -Infinity for empty lists,
|
|
328
|
+
// but BigInt can't represent Infinity, so throwing an error or
|
|
329
|
+
// handling as per application logic is necessary.
|
|
330
|
+
throw new Error((0, errors_1.message)('maxBigIntRequiresArgument'));
|
|
331
|
+
}
|
|
332
|
+
let max = args[0];
|
|
333
|
+
for (let i = 1; i < args.length; i++) {
|
|
334
|
+
if (args[i] > max) {
|
|
335
|
+
max = args[i];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return max;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Returns the smallest of a set of bigints
|
|
342
|
+
* @param args
|
|
343
|
+
* @returns
|
|
344
|
+
*/
|
|
345
|
+
function min(...args) {
|
|
346
|
+
if (args.length === 0) {
|
|
347
|
+
// Math.min() returns Infinity for no arguments, but BigInt cannot represent Infinity.
|
|
348
|
+
// It's often better to throw an error or handle the empty case explicitly.
|
|
349
|
+
throw new Error((0, errors_1.message)('minBigIntEmpty'));
|
|
350
|
+
}
|
|
351
|
+
let min = args[0];
|
|
352
|
+
for (let i = 1; i < args.length; i++) {
|
|
353
|
+
if (args[i] < min) {
|
|
354
|
+
min = args[i];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return min;
|
|
358
|
+
}
|
|
359
|
+
function recoverCoeffsZ(num, primes) {
|
|
360
|
+
const variables = Object.keys(primes).sort((a, b) => {
|
|
361
|
+
if (/\w+[-+]\w+/.test(a)) {
|
|
362
|
+
return 1;
|
|
363
|
+
}
|
|
364
|
+
return a.localeCompare(b);
|
|
365
|
+
});
|
|
366
|
+
const map = {};
|
|
367
|
+
// Loop though the variables
|
|
368
|
+
for (const v of variables) {
|
|
369
|
+
const prime = primes[v];
|
|
370
|
+
let n = 0;
|
|
371
|
+
let canDivide = true;
|
|
372
|
+
// Divide out the max until you hit a remainder
|
|
373
|
+
do {
|
|
374
|
+
const q = num / prime;
|
|
375
|
+
if (q === 0n) {
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
const r = num % q;
|
|
379
|
+
if (r === 0n) {
|
|
380
|
+
n++;
|
|
381
|
+
num = q;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
canDivide = false;
|
|
385
|
+
}
|
|
386
|
+
} while (canDivide);
|
|
387
|
+
// Mark the power of the variable found
|
|
388
|
+
map[v] = n;
|
|
389
|
+
}
|
|
390
|
+
// Put the rest to the coefficient
|
|
391
|
+
map['coeff'] = num;
|
|
392
|
+
return map;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The binomial function using bigint
|
|
396
|
+
* @param n
|
|
397
|
+
* @param k
|
|
398
|
+
* @returns
|
|
399
|
+
*/
|
|
400
|
+
function binom(n, k) {
|
|
401
|
+
if (n < 0n) {
|
|
402
|
+
throw new RangeError((0, errors_1.message)('binomBigIntNonnegativeN'));
|
|
403
|
+
}
|
|
404
|
+
if (k < 0n || k > n) {
|
|
405
|
+
return 0n;
|
|
406
|
+
}
|
|
407
|
+
if (k === 0n || k === n) {
|
|
408
|
+
return 1n;
|
|
409
|
+
}
|
|
410
|
+
let kk = k;
|
|
411
|
+
const nMinusK = n - k;
|
|
412
|
+
if (nMinusK < kk) {
|
|
413
|
+
kk = nMinusK;
|
|
414
|
+
}
|
|
415
|
+
let result = 1n;
|
|
416
|
+
for (let i = 1n; i <= kk; i++) {
|
|
417
|
+
result = (result * (n - kk + i)) / i;
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Computes the LCM of an array of positive bigints.
|
|
423
|
+
*/
|
|
424
|
+
function bigintLCM(values) {
|
|
425
|
+
if (values.length === 0) {
|
|
426
|
+
return 1n;
|
|
427
|
+
}
|
|
428
|
+
function gcd(a, b) {
|
|
429
|
+
a = a < 0n ? -a : a;
|
|
430
|
+
b = b < 0n ? -b : b;
|
|
431
|
+
while (b !== 0n) {
|
|
432
|
+
[a, b] = [b, a % b];
|
|
433
|
+
}
|
|
434
|
+
return a;
|
|
435
|
+
}
|
|
436
|
+
function lcm(a, b) {
|
|
437
|
+
return (a / gcd(a, b)) * b;
|
|
438
|
+
}
|
|
439
|
+
let result = values[0];
|
|
440
|
+
for (let i = 1; i < values.length; i++) {
|
|
441
|
+
result = lcm(result, values[i]);
|
|
442
|
+
}
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type factorCountType = Record<string, bigint>;
|
|
2
|
+
/**
|
|
3
|
+
* Calculates and array of prime factors
|
|
4
|
+
*
|
|
5
|
+
* @see https://stackoverflow.com/questions/39899072/how-can-i-find-the-prime-factors-of-an-integer-in-javascript by @TheChiporpoise
|
|
6
|
+
* @param num
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPrimeBig(num: bigint): boolean;
|
|
10
|
+
/** Returns the least prime greater than or equal to start. */
|
|
11
|
+
export declare function nextPrimeBig(start: bigint): bigint;
|
|
12
|
+
/**
|
|
13
|
+
* Fast prime factorization using trial division with optimizations
|
|
14
|
+
*/
|
|
15
|
+
export declare function trialDivisionBig(n: bigint): bigint[];
|
|
16
|
+
/**
|
|
17
|
+
* Pollard's rho algorithm for faster factorization of large numbers
|
|
18
|
+
*/
|
|
19
|
+
export declare function pollardRhoBig(n: bigint): bigint;
|
|
20
|
+
/**
|
|
21
|
+
* Advanced factorization using Pollard's rho for large numbers
|
|
22
|
+
*/
|
|
23
|
+
export declare function primeFactorsBig(n: bigint, toNumbers: true): {
|
|
24
|
+
sign: number;
|
|
25
|
+
factors: number[];
|
|
26
|
+
};
|
|
27
|
+
export declare function primeFactorsBig(n: bigint, toNumbers: false | void): {
|
|
28
|
+
sign: number;
|
|
29
|
+
factors: bigint[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Places the prime factors in an object and counts their occurrences
|
|
33
|
+
*
|
|
34
|
+
* @param n
|
|
35
|
+
*/
|
|
36
|
+
export declare function primeFactorCounts(n: bigint): factorCountType;
|
|
37
|
+
/**
|
|
38
|
+
* Merges two factor counts into one object
|
|
39
|
+
*
|
|
40
|
+
* @param a
|
|
41
|
+
* @param b
|
|
42
|
+
*/
|
|
43
|
+
export declare function mergeFactors(a: factorCountType, b: factorCountType): factorCountType;
|
|
44
|
+
/**
|
|
45
|
+
* Gets prime factors that can be used to create a number. The number one is
|
|
46
|
+
* included since 1 * n is a possible combination.
|
|
47
|
+
*
|
|
48
|
+
* @param n The number for which the factors are being retrieved
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export declare function getFactors(n: number | bigint): number[];
|