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.
Files changed (341) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +293 -312
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +7 -0
  5. package/dist/parser.js +2 -0
  6. package/dist/parser.js.LICENSE.txt +7 -0
  7. package/docs-data/parser-functions.json +1960 -0
  8. package/index.d.ts +10 -426
  9. package/output/algebra/adapters.d.ts +33 -0
  10. package/output/algebra/adapters.js +109 -0
  11. package/output/algebra/algorithms/arith.d.ts +84 -0
  12. package/output/algebra/algorithms/arith.js +323 -0
  13. package/output/algebra/algorithms/factor.d.ts +3 -0
  14. package/output/algebra/algorithms/factor.js +5 -0
  15. package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
  16. package/output/algebra/algorithms/factorMultivariate.js +2393 -0
  17. package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
  18. package/output/algebra/algorithms/factorUnivariate.js +1072 -0
  19. package/output/algebra/algorithms/gcd.d.ts +22 -0
  20. package/output/algebra/algorithms/gcd.js +690 -0
  21. package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
  22. package/output/algebra/algorithms/groebnerBase.js +1166 -0
  23. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
  24. package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
  25. package/output/algebra/algorithms/poly.d.ts +228 -0
  26. package/output/algebra/algorithms/poly.js +1299 -0
  27. package/output/algebra/algorithms/rational.d.ts +17 -0
  28. package/output/algebra/algorithms/rational.js +115 -0
  29. package/output/algebra/factor/factor.d.ts +62 -0
  30. package/output/algebra/factor/factor.js +158 -0
  31. package/output/algebra/gcd/gcd.d.ts +29 -0
  32. package/output/algebra/gcd/gcd.js +141 -0
  33. package/output/algebra/groebner.d.ts +21 -0
  34. package/output/algebra/groebner.js +42 -0
  35. package/output/algebra/partfrac.d.ts +19 -0
  36. package/output/algebra/partfrac.js +398 -0
  37. package/output/algebra/polynomialize.d.ts +20 -0
  38. package/output/algebra/polynomialize.js +24 -0
  39. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  40. package/output/algebra/simplify/complexsimp.js +24 -0
  41. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  42. package/output/algebra/simplify/factorCommon.js +136 -0
  43. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  44. package/output/algebra/simplify/funcsimp.js +633 -0
  45. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  46. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  47. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  48. package/output/algebra/simplify/ratsimp.js +140 -0
  49. package/output/algebra/simplify/simplify.d.ts +25 -0
  50. package/output/algebra/simplify/simplify.js +228 -0
  51. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  52. package/output/algebra/simplify/trigreduce.js +424 -0
  53. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  54. package/output/algebra/simplify/trigrewrite.js +156 -0
  55. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  56. package/output/algebra/simplify/trigsimp.js +369 -0
  57. package/output/algebra/simplify/utils.d.ts +32 -0
  58. package/output/algebra/simplify/utils.js +56 -0
  59. package/output/algebra/utils.d.ts +32 -0
  60. package/output/algebra/utils.js +48 -0
  61. package/output/api/advanced.d.ts +7 -0
  62. package/output/api/advanced.js +18 -0
  63. package/output/api/algebra.d.ts +17 -0
  64. package/output/api/algebra.js +32 -0
  65. package/output/api/assumptions.d.ts +4 -0
  66. package/output/api/assumptions.js +11 -0
  67. package/output/api/calculus.d.ts +9 -0
  68. package/output/api/calculus.js +21 -0
  69. package/output/api/core.d.ts +17 -0
  70. package/output/api/core.js +41 -0
  71. package/output/api/debug.d.ts +16 -0
  72. package/output/api/debug.js +23 -0
  73. package/output/api/parser.d.ts +85 -0
  74. package/output/api/parser.js +16 -0
  75. package/output/api/solve.d.ts +10 -0
  76. package/output/api/solve.js +16 -0
  77. package/output/api/structures.d.ts +10 -0
  78. package/output/api/structures.js +22 -0
  79. package/output/calculus/derivative/diff.d.ts +30 -0
  80. package/output/calculus/derivative/diff.js +238 -0
  81. package/output/calculus/fresnel.d.ts +16 -0
  82. package/output/calculus/fresnel.js +39 -0
  83. package/output/calculus/integrate/byParts.d.ts +18 -0
  84. package/output/calculus/integrate/byParts.js +339 -0
  85. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  86. package/output/calculus/integrate/bySubstitution.js +411 -0
  87. package/output/calculus/integrate/integrate.d.ts +38 -0
  88. package/output/calculus/integrate/integrate.js +652 -0
  89. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  90. package/output/calculus/integrate/integrationTable.js +914 -0
  91. package/output/calculus/integrate/utils.d.ts +28 -0
  92. package/output/calculus/integrate/utils.js +96 -0
  93. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  94. package/output/calculus/laplace/ilaplace.js +192 -0
  95. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  96. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  97. package/output/calculus/laplace/laplace.d.ts +22 -0
  98. package/output/calculus/laplace/laplace.js +109 -0
  99. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  100. package/output/calculus/laplace/laplaceTable.js +187 -0
  101. package/output/calculus/limit/limit.d.ts +35 -0
  102. package/output/calculus/limit/limit.js +1183 -0
  103. package/output/calculus/limit/limitsTable.d.ts +2 -0
  104. package/output/calculus/limit/limitsTable.js +7 -0
  105. package/output/core/Settings.d.ts +32 -0
  106. package/output/core/Settings.js +68 -0
  107. package/output/core/adapters.d.ts +18 -0
  108. package/output/core/adapters.js +40 -0
  109. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  110. package/output/core/classes/assumption/Assumption.js +605 -0
  111. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  112. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  113. package/output/core/classes/assumption/assume.d.ts +90 -0
  114. package/output/core/classes/assumption/assume.js +145 -0
  115. package/output/core/classes/collection/Collection.d.ts +107 -0
  116. package/output/core/classes/collection/Collection.js +231 -0
  117. package/output/core/classes/complex/Complex.d.ts +99 -0
  118. package/output/core/classes/complex/Complex.js +135 -0
  119. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  120. package/output/core/classes/decimalSet/DecimalSet.js +453 -0
  121. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  122. package/output/core/classes/dictionary/Dictionary.js +213 -0
  123. package/output/core/classes/equation/Equation.d.ts +256 -0
  124. package/output/core/classes/equation/Equation.js +350 -0
  125. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  126. package/output/core/classes/expression/CoeffObject.js +198 -0
  127. package/output/core/classes/expression/Expression.d.ts +1674 -0
  128. package/output/core/classes/expression/Expression.js +2332 -0
  129. package/output/core/classes/expression/analysis.d.ts +25 -0
  130. package/output/core/classes/expression/analysis.js +218 -0
  131. package/output/core/classes/expression/collect.d.ts +9 -0
  132. package/output/core/classes/expression/collect.js +49 -0
  133. package/output/core/classes/expression/format.d.ts +45 -0
  134. package/output/core/classes/expression/format.js +217 -0
  135. package/output/core/classes/expression/products.d.ts +23 -0
  136. package/output/core/classes/expression/products.js +115 -0
  137. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  138. package/output/core/classes/expression/shortcuts.js +129 -0
  139. package/output/core/classes/expression/traversal.d.ts +31 -0
  140. package/output/core/classes/expression/traversal.js +216 -0
  141. package/output/core/classes/expression/trig.d.ts +25 -0
  142. package/output/core/classes/expression/trig.js +40 -0
  143. package/output/core/classes/expression/utils.d.ts +52 -0
  144. package/output/core/classes/expression/utils.js +189 -0
  145. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  146. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  147. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  148. package/output/core/classes/matrix/Matrix.js +889 -0
  149. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  150. package/output/core/classes/matrix/Sylvester.js +54 -0
  151. package/output/core/classes/matrix/functions.d.ts +26 -0
  152. package/output/core/classes/matrix/functions.js +52 -0
  153. package/output/core/classes/matrix/utils.d.ts +9 -0
  154. package/output/core/classes/matrix/utils.js +22 -0
  155. package/output/core/classes/parser/Parser.d.ts +480 -0
  156. package/output/core/classes/parser/Parser.js +1812 -0
  157. package/output/core/classes/parser/Token.d.ts +58 -0
  158. package/output/core/classes/parser/Token.js +137 -0
  159. package/output/core/classes/parser/constants.d.ts +160 -0
  160. package/output/core/classes/parser/constants.js +227 -0
  161. package/output/core/classes/parser/helpers.d.ts +21 -0
  162. package/output/core/classes/parser/helpers.js +42 -0
  163. package/output/core/classes/parser/operations/add.d.ts +15 -0
  164. package/output/core/classes/parser/operations/add.js +238 -0
  165. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  166. package/output/core/classes/parser/operations/comma.js +11 -0
  167. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  168. package/output/core/classes/parser/operations/compare.js +461 -0
  169. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  170. package/output/core/classes/parser/operations/divide.js +72 -0
  171. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  172. package/output/core/classes/parser/operations/functions.js +430 -0
  173. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  174. package/output/core/classes/parser/operations/multiply.js +321 -0
  175. package/output/core/classes/parser/operations/power.d.ts +48 -0
  176. package/output/core/classes/parser/operations/power.js +673 -0
  177. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  178. package/output/core/classes/parser/operations/subtract.js +35 -0
  179. package/output/core/classes/parser/preprocess.d.ts +14 -0
  180. package/output/core/classes/parser/preprocess.js +259 -0
  181. package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
  182. package/output/core/classes/parser/scripting/controlFlow.js +355 -0
  183. package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
  184. package/output/core/classes/parser/scripting/evaluate.js +112 -0
  185. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  186. package/output/core/classes/parser/scripting/functions.js +59 -0
  187. package/output/core/classes/parser/scripting/scope.d.ts +35 -0
  188. package/output/core/classes/parser/scripting/scope.js +155 -0
  189. package/output/core/classes/parser/types.d.ts +125 -0
  190. package/output/core/classes/parser/types.js +2 -0
  191. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  192. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  193. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  194. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  195. package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
  196. package/output/core/classes/polynomial/Polynomial.js +1149 -0
  197. package/output/core/classes/polynomial/Term.d.ts +222 -0
  198. package/output/core/classes/polynomial/Term.js +430 -0
  199. package/output/core/classes/polynomial/functions.d.ts +69 -0
  200. package/output/core/classes/polynomial/functions.js +126 -0
  201. package/output/core/classes/polynomial/utils.d.ts +62 -0
  202. package/output/core/classes/polynomial/utils.js +206 -0
  203. package/output/core/classes/rational/Rational.d.ts +504 -0
  204. package/output/core/classes/rational/Rational.js +779 -0
  205. package/output/core/classes/seq/SEQ.d.ts +13 -0
  206. package/output/core/classes/seq/SEQ.js +137 -0
  207. package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
  208. package/output/core/classes/valuesSet/ValuesSet.js +381 -0
  209. package/output/core/classes/vector/Vector.d.ts +222 -0
  210. package/output/core/classes/vector/Vector.js +497 -0
  211. package/output/core/classes/vector/functions.d.ts +28 -0
  212. package/output/core/classes/vector/functions.js +47 -0
  213. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  214. package/output/core/common/classes/MathematicalAggregate.js +140 -0
  215. package/output/core/common/classes/Scope.d.ts +62 -0
  216. package/output/core/common/classes/Scope.js +122 -0
  217. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  218. package/output/core/common/classes/StructuredEntity.js +151 -0
  219. package/output/core/common/common.d.ts +63 -0
  220. package/output/core/common/common.js +279 -0
  221. package/output/core/common/functions/functions.d.ts +14 -0
  222. package/output/core/common/functions/functions.js +33 -0
  223. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  224. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  225. package/output/core/converters/BaseConverter.d.ts +97 -0
  226. package/output/core/converters/BaseConverter.js +405 -0
  227. package/output/core/converters/Converter.d.ts +111 -0
  228. package/output/core/converters/Converter.js +802 -0
  229. package/output/core/converters/Pattern.d.ts +71 -0
  230. package/output/core/converters/Pattern.js +302 -0
  231. package/output/core/dispatch.d.ts +34 -0
  232. package/output/core/dispatch.js +304 -0
  233. package/output/core/errors.d.ts +531 -0
  234. package/output/core/errors.js +621 -0
  235. package/output/core/functions/bigint/bigint.d.ts +121 -0
  236. package/output/core/functions/bigint/bigint.js +392 -0
  237. package/output/core/functions/bigint/primeFactor.d.ts +49 -0
  238. package/output/core/functions/bigint/primeFactor.js +267 -0
  239. package/output/core/functions/bigint/primes.d.ts +1 -0
  240. package/output/core/functions/bigint/primes.js +11 -0
  241. package/output/core/functions/build/definitions.d.ts +12 -0
  242. package/output/core/functions/build/definitions.js +133 -0
  243. package/output/core/functions/build/index.d.ts +32 -0
  244. package/output/core/functions/build/index.js +136 -0
  245. package/output/core/functions/complex.d.ts +90 -0
  246. package/output/core/functions/complex.js +482 -0
  247. package/output/core/functions/decimal.d.ts +24 -0
  248. package/output/core/functions/decimal.js +664 -0
  249. package/output/core/functions/expand/expand.d.ts +42 -0
  250. package/output/core/functions/expand/expand.js +376 -0
  251. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  252. package/output/core/functions/fresnelNumeric.js +123 -0
  253. package/output/core/functions/numeric.d.ts +140 -0
  254. package/output/core/functions/numeric.js +790 -0
  255. package/output/core/functions/rationalNormalization.d.ts +11 -0
  256. package/output/core/functions/rationalNormalization.js +117 -0
  257. package/output/core/functions/setFunction.d.ts +19 -0
  258. package/output/core/functions/setFunction.js +75 -0
  259. package/output/core/functions/string.d.ts +26 -0
  260. package/output/core/functions/string.js +101 -0
  261. package/output/core/functions/subst.d.ts +90 -0
  262. package/output/core/functions/subst.js +498 -0
  263. package/output/core/functions/utils.d.ts +24 -0
  264. package/output/core/functions/utils.js +51 -0
  265. package/output/core/types.d.ts +48 -0
  266. package/output/core/types.js +2 -0
  267. package/output/index.d.ts +339 -0
  268. package/output/index.js +715 -0
  269. package/output/math/defint/defintDecimal.d.ts +37 -0
  270. package/output/math/defint/defintDecimal.js +320 -0
  271. package/output/math/defint/defintNative.d.ts +57 -0
  272. package/output/math/defint/defintNative.js +292 -0
  273. package/output/math/geometry.d.ts +8 -0
  274. package/output/math/geometry.js +32 -0
  275. package/output/math/math.d.ts +655 -0
  276. package/output/math/math.js +1811 -0
  277. package/output/math/trig.d.ts +518 -0
  278. package/output/math/trig.js +1444 -0
  279. package/output/math/trunc.d.ts +19 -0
  280. package/output/math/trunc.js +36 -0
  281. package/output/math/utils.d.ts +60 -0
  282. package/output/math/utils.js +180 -0
  283. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  284. package/output/solve/classes/DecimalMatrix.js +86 -0
  285. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  286. package/output/solve/classes/FunctionSolver.js +433 -0
  287. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  288. package/output/solve/classes/MultivariateSolver.js +240 -0
  289. package/output/solve/classes/PolynomialSolver.d.ts +85 -0
  290. package/output/solve/classes/PolynomialSolver.js +292 -0
  291. package/output/solve/classes/SolutionSet.d.ts +153 -0
  292. package/output/solve/classes/SolutionSet.js +357 -0
  293. package/output/solve/classes/Solver.d.ts +17 -0
  294. package/output/solve/classes/Solver.js +132 -0
  295. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  296. package/output/solve/classes/SymbolicSolver.js +601 -0
  297. package/output/solve/linsolve.d.ts +51 -0
  298. package/output/solve/linsolve.js +225 -0
  299. package/output/solve/solve.d.ts +34 -0
  300. package/output/solve/solve.js +260 -0
  301. package/output/solve/solveSystem.d.ts +31 -0
  302. package/output/solve/solveSystem.js +290 -0
  303. package/output/solve/utils.d.ts +9 -0
  304. package/output/solve/utils.js +62 -0
  305. package/output/utils/array.d.ts +42 -0
  306. package/output/utils/array.js +98 -0
  307. package/output/utils/debug.d.ts +131 -0
  308. package/output/utils/debug.js +295 -0
  309. package/output/utils/decimal.d.ts +3 -0
  310. package/output/utils/decimal.js +16 -0
  311. package/output/utils/numeric.d.ts +14 -0
  312. package/output/utils/numeric.js +51 -0
  313. package/output/utils/object.d.ts +26 -0
  314. package/output/utils/object.js +56 -0
  315. package/package.json +213 -57
  316. package/.travis.yml +0 -3
  317. package/Algebra.js +0 -4568
  318. package/BREAKING_CHANGES.md +0 -5
  319. package/CODE_OF_CONDUCT.md +0 -46
  320. package/CONTRIBUTING.md +0 -14
  321. package/Calculus.js +0 -2675
  322. package/Extra.js +0 -622
  323. package/Solve.js +0 -1783
  324. package/all.js +0 -16
  325. package/all.min.js +0 -1
  326. package/gulpfile.js +0 -16
  327. package/index.html +0 -158
  328. package/license.txt +0 -19
  329. package/nerdamer.core.js +0 -12510
  330. package/spec/LaTeX.spec.js +0 -302
  331. package/spec/TeXConvert.spec.js +0 -8
  332. package/spec/algebra.spec.js +0 -287
  333. package/spec/basic_parser.spec.js +0 -134
  334. package/spec/build.spec.js +0 -131
  335. package/spec/calculus.spec.js +0 -183
  336. package/spec/core.spec.js +0 -2970
  337. package/spec/extra.spec.js +0 -54
  338. package/spec/solve.spec.js +0 -126
  339. package/spec/support/jasmine.json +0 -11
  340. package/spec/support/utils.js +0 -42
  341. 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[];