|
31 | 31 | // argument value. The only difference between the two functions is the |
32 | 32 | // structure used for the factors: the first function uses an array, and the |
33 | 33 | // second uses a vector. See the comments above each function for more details. |
| 34 | +// |
| 35 | +// Information on the algorithms they use, and on performance, is provided at |
| 36 | +// the bottom of this file. |
34 | 37 |
|
35 | 38 |
|
36 | 39 | namespace hurchalla { |
37 | 40 |
|
38 | 41 |
|
39 | | - |
40 | | -// ------------------------------------ |
41 | | -// The Algorithms: |
42 | | -// ------------------------------------ |
43 | | -// Prior to heavier-weight factorization, factorize() first uses a small trial |
44 | | -// disivion stage. It then uses either ECM or Pollard-Rho to find all remaining |
45 | | -// factors, depending on the size of the number. Prior to trying to extract |
46 | | -// any factor with ECM or Pollard-Rho, it tests for primality by using the |
47 | | -// deterministic Miller-Rabin algorithm - we usually speed up this algorithm by |
48 | | -// using one of the very small hash tables (~100 bytes for example) in |
49 | | -// factoring/include/hurchalla/factoring/detail/miller_rabin_bases/ |
50 | | -// |
51 | | -// For numbers below ~40 bits, factorize() uses the Pollard-Rho factorization |
52 | | -// algorithm, with Brent's improvements (see https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm) |
53 | | -// along with other further improvements I made to the algorithm. |
54 | | -// |
55 | | -// For numbers above ~40 bits, factorize() uses ECM tailored for numbers between |
56 | | -// 32 to 128 bits in size. This ECM code was initially based on Ben Buhrow's |
57 | | -// "micro-ecm", which was then improved, optimized, and extended to 128 bits. |
58 | | - |
59 | | -// ------------------------------------ |
60 | | -// Performance: |
61 | | -// ------------------------------------ |
62 | | -// For 64 bit numbers, the resulting factorization functions below are likely |
63 | | -// the fastest you will currently be able to find, both for factoring arbitrary |
64 | | -// values and for factoring semiprimes with two large factors. |
65 | | -// |
66 | | -// For 128 bit numbers, this code needs to be performance tested against other |
67 | | -// factoring libraries. An initial expectation is that this code will be |
68 | | -// be competitive or possibly do better than other libraries available for 128 |
69 | | -// bit numbers, but this is not yet known. |
70 | | -// |
71 | | -// For 32 bit numbers, a very well-optimized implementation of Hart's One Line |
72 | | -// Factoring algorithm and/or Lehman's method might potentially be faster than |
73 | | -// the functions here. The functions here should nonetheless be fairly close to |
74 | | -// the fastest currently available at 32 bits. |
75 | | -// |
76 | | -// For 256 bit or larger numbers - which this library does not support - you may |
77 | | -// wish to seek out ECM for smaller bit depths, and then Quadratic Sieve and |
78 | | -// GNFS for larger bit depths. For example, see the GMP project/library. |
79 | | - |
80 | | - |
81 | 42 | // ------------------------------------ |
82 | 43 | // The functions: |
83 | 44 | // ------------------------------------ |
84 | 45 |
|
85 | | -// Returns a std::array that contains all factors of x, and writes the total |
86 | | -// number of factors to num_factors. The array entries with index < num_factor |
87 | | -// are the factors. |
| 46 | +// There are two versions of the factorize function. |
| 47 | + |
| 48 | +// This first version returns a std::array that contains all factors of x, and |
| 49 | +// writes the total number of factors to num_factors. The array entries with |
| 50 | +// index < num_factor are the factors. |
88 | 51 | // The argument 'expect_arbitrary_size_factors' does not affect the results, but |
89 | 52 | // it will optimize the factoring to be faster when you know or expect all the |
90 | 53 | // factors will be large (assuming you set it to false), or it will optimize the |
@@ -163,6 +126,47 @@ void factorize(T x, std::vector<T>& factors, |
163 | 126 | } |
164 | 127 |
|
165 | 128 |
|
| 129 | +// ------------------------------------ |
| 130 | +// The Algorithms: |
| 131 | +// ------------------------------------ |
| 132 | +// Prior to heavier-weight factorization, factorize() first uses a small trial |
| 133 | +// disivion stage. It then uses either ECM or Pollard-Rho to find all remaining |
| 134 | +// factors, depending on the size of the number. Prior to trying to extract |
| 135 | +// any factor with ECM or Pollard-Rho, it tests for primality by using the |
| 136 | +// deterministic Miller-Rabin algorithm - we usually speed up this algorithm by |
| 137 | +// using one of the very small hash tables (~100 bytes for example) in |
| 138 | +// factoring/include/hurchalla/factoring/detail/miller_rabin_bases/ |
| 139 | +// |
| 140 | +// For numbers below ~40 bits, factorize() uses the Pollard-Rho factorization |
| 141 | +// algorithm, with Brent's improvements (see https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm) |
| 142 | +// along with other further improvements I made to the algorithm. |
| 143 | +// |
| 144 | +// For numbers above ~40 bits, factorize() uses ECM tailored for numbers between |
| 145 | +// 32 to 128 bits in size. This ECM code was initially based on Ben Buhrow's |
| 146 | +// "micro-ecm", which was improved and optimized and extended to 128 bits. |
| 147 | + |
| 148 | +// ------------------------------------ |
| 149 | +// Performance: |
| 150 | +// ------------------------------------ |
| 151 | +// For 64 bit numbers, the resulting factorization functions above are likely |
| 152 | +// the fastest you will currently be able to find, both for factoring arbitrary |
| 153 | +// values and for factoring semiprimes with two large factors. |
| 154 | +// |
| 155 | +// For 128 bit numbers, this code needs to be performance tested against other |
| 156 | +// factoring libraries. An initial expectation is that this code will be |
| 157 | +// be competitive or possibly do better than other libraries available for 128 |
| 158 | +// bit numbers, but this is not yet known. |
| 159 | +// |
| 160 | +// For 32 bit numbers, a very well-optimized implementation of Hart's One Line |
| 161 | +// Factoring algorithm and/or Lehman's method might potentially be faster than |
| 162 | +// the functions here. The functions here should nonetheless be fairly close to |
| 163 | +// the fastest currently available at 32 bits. |
| 164 | +// |
| 165 | +// For 256 bit or larger numbers - which this library does not support - you may |
| 166 | +// wish to seek out ECM for smaller bit depths, and then Quadratic Sieve and |
| 167 | +// GNFS for larger bit depths. For example, see the GMP project/library. |
| 168 | + |
| 169 | + |
166 | 170 | } // end namespace |
167 | 171 |
|
168 | 172 | #endif |
0 commit comments