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,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the absolute value of a bigint
|
|
3
|
+
*
|
|
4
|
+
* @param x
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function abs(x: bigint): bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Returns an array with unique values, sorted, and in reverse order.
|
|
10
|
+
*
|
|
11
|
+
* @param array
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function uniqueSortedArray(array: bigint[]): bigint[];
|
|
15
|
+
/**
|
|
16
|
+
* Calculates the gcd of a set of bigints
|
|
17
|
+
*
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function GCD(...args: bigint[]): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Calculates the LCM of a set of bigints
|
|
23
|
+
*
|
|
24
|
+
* @param args
|
|
25
|
+
*/
|
|
26
|
+
export declare function LCM(...args: bigint[]): bigint;
|
|
27
|
+
/**
|
|
28
|
+
* Simplifies a ratio of two bigints
|
|
29
|
+
*
|
|
30
|
+
* @param numerator
|
|
31
|
+
* @param denominator
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function simplifyRatio(numerator: bigint, denominator: bigint): [bigint, bigint];
|
|
35
|
+
/**
|
|
36
|
+
* Converts a decimal number to a rational
|
|
37
|
+
*
|
|
38
|
+
* @param numStr
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare function convert(numStr: string): [bigint, bigint];
|
|
42
|
+
/**
|
|
43
|
+
* Returns the sign of a bigint
|
|
44
|
+
*
|
|
45
|
+
* @param n
|
|
46
|
+
* @returns -1 if negative and 1 for positive and 0 for zero
|
|
47
|
+
*/
|
|
48
|
+
export declare function sign(n: bigint): 0 | 1 | -1;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a bigint is an even number
|
|
51
|
+
*
|
|
52
|
+
* @param n
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare function isEven(n: bigint): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Computes the nth Fibonacci number exactly using fast doubling.
|
|
58
|
+
*
|
|
59
|
+
* Negative indices use the negafibonacci identity F(-n) = (-1)^(n+1)F(n).
|
|
60
|
+
*
|
|
61
|
+
* @param n - Integer index.
|
|
62
|
+
* @returns The exact Fibonacci number.
|
|
63
|
+
*/
|
|
64
|
+
export declare function fibonacci(n: bigint): bigint;
|
|
65
|
+
/**
|
|
66
|
+
* The big number version
|
|
67
|
+
*/
|
|
68
|
+
export declare const factorial: (n: number | bigint) => bigint;
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the modulo of two numbers
|
|
71
|
+
*
|
|
72
|
+
* @param a
|
|
73
|
+
* @param b
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare function mod(a: bigint, b: bigint): bigint;
|
|
77
|
+
/**
|
|
78
|
+
* Finds the multiplicative inverse of a modulo m.
|
|
79
|
+
*
|
|
80
|
+
* Returns -1 when the inverse does not exist. The extended Euclidean algorithm keeps
|
|
81
|
+
* the operation exact for bigint inputs without scanning every possible residue.
|
|
82
|
+
*
|
|
83
|
+
* @param a
|
|
84
|
+
* @param m
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export declare function invMod(a: bigint, m: bigint): bigint;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the product given a number range start and finish
|
|
90
|
+
*
|
|
91
|
+
* @param start The start of the range
|
|
92
|
+
* @param end The end of the range
|
|
93
|
+
* @param step The increment step
|
|
94
|
+
*/
|
|
95
|
+
export declare function productInRange(start: number, end: number, step?: number): bigint;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the largest of a set of bigints
|
|
98
|
+
* @param args
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare function max(...args: bigint[]): bigint;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the smallest of a set of bigints
|
|
104
|
+
* @param args
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
export declare function min(...args: bigint[]): bigint;
|
|
108
|
+
export declare function recoverCoeffsZ(num: bigint, primes: {
|
|
109
|
+
[variable: string]: bigint;
|
|
110
|
+
}): Record<string, number | bigint>;
|
|
111
|
+
/**
|
|
112
|
+
* The binomial function using bigint
|
|
113
|
+
* @param n
|
|
114
|
+
* @param k
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
export declare function binom(n: bigint, k: bigint): bigint;
|
|
118
|
+
/**
|
|
119
|
+
* Computes the LCM of an array of positive bigints.
|
|
120
|
+
*/
|
|
121
|
+
export declare function bigintLCM(values: bigint[]): bigint;
|
|
@@ -0,0 +1,392 @@
|
|
|
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.fibonacci = fibonacci;
|
|
13
|
+
exports.mod = mod;
|
|
14
|
+
exports.invMod = invMod;
|
|
15
|
+
exports.productInRange = productInRange;
|
|
16
|
+
exports.max = max;
|
|
17
|
+
exports.min = min;
|
|
18
|
+
exports.recoverCoeffsZ = recoverCoeffsZ;
|
|
19
|
+
exports.binom = binom;
|
|
20
|
+
exports.bigintLCM = bigintLCM;
|
|
21
|
+
const string_1 = require("../string");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
23
|
+
/**
|
|
24
|
+
* Returns the absolute value of a bigint
|
|
25
|
+
*
|
|
26
|
+
* @param x
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
function abs(x) {
|
|
30
|
+
return x < 0n ? -x : x;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns an array with unique values, sorted, and in reverse order.
|
|
34
|
+
*
|
|
35
|
+
* @param array
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
function uniqueSortedArray(array) {
|
|
39
|
+
return (0, utils_1.arrayUnique)([].slice.call(array).map(function (x) {
|
|
40
|
+
return abs(x);
|
|
41
|
+
})).sort();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Calculates the gcd of a set of bigints
|
|
45
|
+
*
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function GCD(...args) {
|
|
49
|
+
// Get a unique set and convert to absolute values
|
|
50
|
+
args = uniqueSortedArray(args);
|
|
51
|
+
// Point to the first element
|
|
52
|
+
let a = args[0];
|
|
53
|
+
for (let i = 1; i < args.length; i++) {
|
|
54
|
+
let b = args[i];
|
|
55
|
+
while (true) {
|
|
56
|
+
a %= b;
|
|
57
|
+
if (a === 0n) {
|
|
58
|
+
a = b;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
b %= a;
|
|
62
|
+
if (b === 0n) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return a;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the LCM of a set of bigints
|
|
71
|
+
*
|
|
72
|
+
* @param args
|
|
73
|
+
*/
|
|
74
|
+
function LCM(...args) {
|
|
75
|
+
// Get a unique set and convert to absolute values
|
|
76
|
+
args = uniqueSortedArray(args);
|
|
77
|
+
let a = args[0];
|
|
78
|
+
for (let i = 1; i < args.length; i++) {
|
|
79
|
+
const b = args[i];
|
|
80
|
+
// Get the LCM of that of the last calculated LCM and the new number
|
|
81
|
+
a = (a * b) / GCD(a, b);
|
|
82
|
+
}
|
|
83
|
+
return a;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Simplifies a ratio of two bigints
|
|
87
|
+
*
|
|
88
|
+
* @param numerator
|
|
89
|
+
* @param denominator
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
function simplifyRatio(numerator, denominator) {
|
|
93
|
+
if (denominator !== 1n) {
|
|
94
|
+
const gcd = GCD(denominator, numerator);
|
|
95
|
+
return [numerator / gcd, denominator / gcd];
|
|
96
|
+
}
|
|
97
|
+
return [numerator, denominator];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts a decimal number to a rational
|
|
101
|
+
*
|
|
102
|
+
* @param numStr
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
function convert(numStr) {
|
|
106
|
+
//Split the whole and decimal
|
|
107
|
+
const [w, d] = (0, string_1.decimalSplit)(numStr);
|
|
108
|
+
//Create the denominator based on the number of decimal places
|
|
109
|
+
const denominator = 10n ** BigInt(d.length);
|
|
110
|
+
const numerator = BigInt(w + d);
|
|
111
|
+
return simplifyRatio(numerator, denominator);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the sign of a bigint
|
|
115
|
+
*
|
|
116
|
+
* @param n
|
|
117
|
+
* @returns -1 if negative and 1 for positive and 0 for zero
|
|
118
|
+
*/
|
|
119
|
+
function sign(n) {
|
|
120
|
+
return n === 0n ? 0 : n < 0n ? -1 : 1;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Checks if a bigint is an even number
|
|
124
|
+
*
|
|
125
|
+
* @param n
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
function isEven(n) {
|
|
129
|
+
return n % 2n === 0n;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Computes the nth Fibonacci number exactly using fast doubling.
|
|
133
|
+
*
|
|
134
|
+
* Negative indices use the negafibonacci identity F(-n) = (-1)^(n+1)F(n).
|
|
135
|
+
*
|
|
136
|
+
* @param n - Integer index.
|
|
137
|
+
* @returns The exact Fibonacci number.
|
|
138
|
+
*/
|
|
139
|
+
function fibonacci(n) {
|
|
140
|
+
const isNegative = n < 0n;
|
|
141
|
+
const index = isNegative ? -n : n;
|
|
142
|
+
let a = 0n;
|
|
143
|
+
let b = 1n;
|
|
144
|
+
for (const bit of index.toString(2)) {
|
|
145
|
+
const c = a * (2n * b - a);
|
|
146
|
+
const d = a * a + b * b;
|
|
147
|
+
if (bit === '0') {
|
|
148
|
+
a = c;
|
|
149
|
+
b = d;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
a = d;
|
|
153
|
+
b = c + d;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let retval = a;
|
|
157
|
+
if (isNegative && isEven(index)) {
|
|
158
|
+
retval = -retval;
|
|
159
|
+
}
|
|
160
|
+
return retval;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The big number version
|
|
164
|
+
*/
|
|
165
|
+
exports.factorial = (function () {
|
|
166
|
+
const factorialCache = [1n, 1n];
|
|
167
|
+
let i = 2;
|
|
168
|
+
/**
|
|
169
|
+
* Leverages JavaScript's native bigInt and the solution provide here:
|
|
170
|
+
* https://stackoverflow.com/questions/3959211/what-is-the-fastest-factorial-function-in-javascript
|
|
171
|
+
* to provide a fast factorial function capable of calculating large numbers.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
*
|
|
175
|
+
* This is limited to Number.MAX_SAFE_INTEGER since n is of type number since for loop requires it
|
|
176
|
+
*
|
|
177
|
+
* @param n - The factorial of the number being calculated
|
|
178
|
+
* @returns The computed factorial
|
|
179
|
+
* @throws RangeError If `n` is negative.
|
|
180
|
+
*/
|
|
181
|
+
function bigFactorial(n) {
|
|
182
|
+
if (typeof n === 'bigint') {
|
|
183
|
+
n = Number(n);
|
|
184
|
+
}
|
|
185
|
+
if (n < 0) {
|
|
186
|
+
throw new RangeError('Factorial is undefined for negative integers.');
|
|
187
|
+
}
|
|
188
|
+
// If there's a cached version return that instead
|
|
189
|
+
if (typeof factorialCache[n] != 'undefined') {
|
|
190
|
+
return factorialCache[n];
|
|
191
|
+
}
|
|
192
|
+
let result = factorialCache[i - 1];
|
|
193
|
+
for (; i <= n; i++) {
|
|
194
|
+
factorialCache[i] = result = result * BigInt(i);
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
bigFactorial(100);
|
|
199
|
+
return bigFactorial;
|
|
200
|
+
})();
|
|
201
|
+
// Cache the first 100
|
|
202
|
+
/**
|
|
203
|
+
* Calculates the modulo of two numbers
|
|
204
|
+
*
|
|
205
|
+
* @param a
|
|
206
|
+
* @param b
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
209
|
+
function mod(a, b) {
|
|
210
|
+
const signA = sign(a);
|
|
211
|
+
const signB = sign(b);
|
|
212
|
+
let retval;
|
|
213
|
+
if (signA === signB) {
|
|
214
|
+
retval = a % b;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers
|
|
218
|
+
retval = ((a % b) + b) % b;
|
|
219
|
+
}
|
|
220
|
+
return retval;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Finds the multiplicative inverse of a modulo m.
|
|
224
|
+
*
|
|
225
|
+
* Returns -1 when the inverse does not exist. The extended Euclidean algorithm keeps
|
|
226
|
+
* the operation exact for bigint inputs without scanning every possible residue.
|
|
227
|
+
*
|
|
228
|
+
* @param a
|
|
229
|
+
* @param m
|
|
230
|
+
* @returns
|
|
231
|
+
*/
|
|
232
|
+
function invMod(a, m) {
|
|
233
|
+
let retval = -1n;
|
|
234
|
+
const modulus = abs(m);
|
|
235
|
+
if (modulus !== 0n) {
|
|
236
|
+
let t = 0n;
|
|
237
|
+
let nextT = 1n;
|
|
238
|
+
let r = modulus;
|
|
239
|
+
let nextR = mod(a, modulus);
|
|
240
|
+
while (nextR !== 0n) {
|
|
241
|
+
const q = r / nextR;
|
|
242
|
+
[t, nextT] = [nextT, t - q * nextT];
|
|
243
|
+
[r, nextR] = [nextR, r - q * nextR];
|
|
244
|
+
}
|
|
245
|
+
if (r === 1n) {
|
|
246
|
+
retval = mod(t, modulus);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return retval;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Gets the product given a number range start and finish
|
|
253
|
+
*
|
|
254
|
+
* @param start The start of the range
|
|
255
|
+
* @param end The end of the range
|
|
256
|
+
* @param step The increment step
|
|
257
|
+
*/
|
|
258
|
+
function productInRange(start, end, step = 1) {
|
|
259
|
+
let retval = BigInt(start);
|
|
260
|
+
let n = BigInt(start);
|
|
261
|
+
const i = BigInt(step);
|
|
262
|
+
while (n < end) {
|
|
263
|
+
n += i;
|
|
264
|
+
retval *= n;
|
|
265
|
+
}
|
|
266
|
+
return retval;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns the largest of a set of bigints
|
|
270
|
+
* @param args
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
function max(...args) {
|
|
274
|
+
if (args.length < 1) {
|
|
275
|
+
// Math.max() for Number returns -Infinity for empty lists,
|
|
276
|
+
// but BigInt can't represent Infinity, so throwing an error or
|
|
277
|
+
// handling as per application logic is necessary.
|
|
278
|
+
throw new Error('maxBigInt() requires at least one argument');
|
|
279
|
+
}
|
|
280
|
+
let max = args[0];
|
|
281
|
+
for (let i = 1; i < args.length; i++) {
|
|
282
|
+
if (args[i] > max) {
|
|
283
|
+
max = args[i];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return max;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Returns the smallest of a set of bigints
|
|
290
|
+
* @param args
|
|
291
|
+
* @returns
|
|
292
|
+
*/
|
|
293
|
+
function min(...args) {
|
|
294
|
+
if (args.length === 0) {
|
|
295
|
+
// Math.min() returns Infinity for no arguments, but BigInt cannot represent Infinity.
|
|
296
|
+
// It's often better to throw an error or handle the empty case explicitly.
|
|
297
|
+
throw new Error('Min of empty list is not defined for BigInt.');
|
|
298
|
+
}
|
|
299
|
+
let min = args[0];
|
|
300
|
+
for (let i = 1; i < args.length; i++) {
|
|
301
|
+
if (args[i] < min) {
|
|
302
|
+
min = args[i];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return min;
|
|
306
|
+
}
|
|
307
|
+
function recoverCoeffsZ(num, primes) {
|
|
308
|
+
const variables = Object.keys(primes).sort((a, b) => {
|
|
309
|
+
if (/\w+[-+]\w+/.test(a)) {
|
|
310
|
+
return 1;
|
|
311
|
+
}
|
|
312
|
+
return a.localeCompare(b);
|
|
313
|
+
});
|
|
314
|
+
const map = {};
|
|
315
|
+
// Loop though the variables
|
|
316
|
+
for (const v of variables) {
|
|
317
|
+
const prime = primes[v];
|
|
318
|
+
let n = 0;
|
|
319
|
+
let canDivide = true;
|
|
320
|
+
// Divide out the max until you hit a remainder
|
|
321
|
+
do {
|
|
322
|
+
const q = num / prime;
|
|
323
|
+
if (q === 0n) {
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
const r = num % q;
|
|
327
|
+
if (r === 0n) {
|
|
328
|
+
n++;
|
|
329
|
+
num = q;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
canDivide = false;
|
|
333
|
+
}
|
|
334
|
+
} while (canDivide);
|
|
335
|
+
// Mark the power of the variable found
|
|
336
|
+
map[v] = n;
|
|
337
|
+
}
|
|
338
|
+
// Put the rest to the coefficient
|
|
339
|
+
map['coeff'] = num;
|
|
340
|
+
return map;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The binomial function using bigint
|
|
344
|
+
* @param n
|
|
345
|
+
* @param k
|
|
346
|
+
* @returns
|
|
347
|
+
*/
|
|
348
|
+
function binom(n, k) {
|
|
349
|
+
if (n < 0n) {
|
|
350
|
+
throw new RangeError('binomBigInt: n must be non-negative');
|
|
351
|
+
}
|
|
352
|
+
if (k < 0n || k > n) {
|
|
353
|
+
return 0n;
|
|
354
|
+
}
|
|
355
|
+
if (k === 0n || k === n) {
|
|
356
|
+
return 1n;
|
|
357
|
+
}
|
|
358
|
+
let kk = k;
|
|
359
|
+
const nMinusK = n - k;
|
|
360
|
+
if (nMinusK < kk) {
|
|
361
|
+
kk = nMinusK;
|
|
362
|
+
}
|
|
363
|
+
let result = 1n;
|
|
364
|
+
for (let i = 1n; i <= kk; i++) {
|
|
365
|
+
result = (result * (n - kk + i)) / i;
|
|
366
|
+
}
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Computes the LCM of an array of positive bigints.
|
|
371
|
+
*/
|
|
372
|
+
function bigintLCM(values) {
|
|
373
|
+
if (values.length === 0) {
|
|
374
|
+
return 1n;
|
|
375
|
+
}
|
|
376
|
+
function gcd(a, b) {
|
|
377
|
+
a = a < 0n ? -a : a;
|
|
378
|
+
b = b < 0n ? -b : b;
|
|
379
|
+
while (b !== 0n) {
|
|
380
|
+
[a, b] = [b, a % b];
|
|
381
|
+
}
|
|
382
|
+
return a;
|
|
383
|
+
}
|
|
384
|
+
function lcm(a, b) {
|
|
385
|
+
return (a / gcd(a, b)) * b;
|
|
386
|
+
}
|
|
387
|
+
let result = values[0];
|
|
388
|
+
for (let i = 1; i < values.length; i++) {
|
|
389
|
+
result = lcm(result, values[i]);
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Fast prime factorization using trial division with optimizations
|
|
12
|
+
*/
|
|
13
|
+
export declare function trialDivisionBig(n: bigint): bigint[];
|
|
14
|
+
/**
|
|
15
|
+
* Pollard's rho algorithm for faster factorization of large numbers
|
|
16
|
+
*/
|
|
17
|
+
export declare function pollardRhoBig(n: bigint): bigint;
|
|
18
|
+
/**
|
|
19
|
+
* Advanced factorization using Pollard's rho for large numbers
|
|
20
|
+
*/
|
|
21
|
+
export declare function primeFactorsBig(n: bigint, toNumbers: true): {
|
|
22
|
+
sign: number;
|
|
23
|
+
factors: number[];
|
|
24
|
+
};
|
|
25
|
+
export declare function primeFactorsBig(n: bigint, toNumbers: false | void): {
|
|
26
|
+
sign: number;
|
|
27
|
+
factors: bigint[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Places the prime factors in an object and counts their occurrences
|
|
31
|
+
*
|
|
32
|
+
* @param n
|
|
33
|
+
*/
|
|
34
|
+
export declare function primeFactorCounts(n: bigint): factorCountType;
|
|
35
|
+
/**
|
|
36
|
+
* Merges two factor counts into one object
|
|
37
|
+
*
|
|
38
|
+
* @param a
|
|
39
|
+
* @param b
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeFactors(a: factorCountType, b: factorCountType): factorCountType;
|
|
42
|
+
/**
|
|
43
|
+
* Gets prime factors that can be used to create a number. The number one is
|
|
44
|
+
* included since 1 * n is a possible combination.
|
|
45
|
+
*
|
|
46
|
+
* @param n The number for which the factors are being retrieved
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export declare function getFactors(n: number | bigint): number[];
|