Inmathematics, therational sieve is a generalalgorithm forfactoring integers into prime factors. It is a special case of thegeneral number field sieve. While it is lessefficient than the general algorithm, it is conceptually simpler. It serves as a helpful first step in understanding how the general number field sieve works.
Suppose we are trying to factor thecomposite numbern. We choose a boundB, and identify thefactor base (which we will callP), the set of all primes less than or equal toB. Next, we search for positive integersz such that bothz andz +n areB-smooth — i.e. all of their prime factors are inP. We can therefore write, for suitable exponentsai andbi,
Butz and are congruent modulon, and so each such integerz that we find yields a multiplicative relation(modn) among the elements ofP, i.e.
(where theai andbi are nonnegative integers.)
When we have generated enough of these relations (it is generally sufficient that the number of relations be a few more than the size ofP), we can use the methods oflinear algebra to multiply together these various relations in such a way that the exponents of the primes are all even. This will give us acongruence of squares of the forma2 ≡b2 (modn), which can be turned into a factorization ofn = gcd(a +b,n) × gcd(a −b,n). This factorization might turn out to be trivial (i.e.n =n × 1), in which case we have to try again with a different combination of relations, but with luck we will get a nontrivial pair of factors ofn, and the algorithm will terminate.
We will factor the integern = 187 using the rational sieve. We will arbitrarily try the valueB = 7, giving the factor baseP = {2,3,5,7}. The first step is to testn for divisibility by each of the members ofP; clearly ifn is divisible by one of these primes, then we are finished already. However, 187 is not divisible by 2, 3, 5, or 7. Next, we search for suitable values ofz; the first few are 2, 5, 9, and 56. These four suitable values ofz give four multiplicative relations (mod 187):
| 1 |
| 2 |
| 3 |
| 4 |
There are now several essentially different ways to combine these and end up with even exponents. For example,
Alternatively, equation (3) is in the proper form already:
Like the general number field sieve, the rational sieve cannot factor numbers of the formpm, wherep is a prime andm is an integer. This is not a huge problem, though—such numbers are statistically rare, and moreover there is a simple and fast process to check whether a given number is of this form. Probably the most elegant method is to check whether⌊n1/b⌋b =n holds for any1 < b ≤ log2(n) using an integer version ofNewton's method for the root extraction.[2]
The biggest problem is finding a sufficient number ofz such that bothz andz +n areB-smooth. For any givenB, the proportion of numbers that areB-smooth decreases rapidly with the size of the number. So ifn is large (say, a hundred digits), it will be difficult or impossible to find enoughz for the algorithm to work. The advantage of the general number field sieve is that one only needs to search for smooth numbers of orderexp(C (log(n))2/3 (log(log(n)))1/3) for someC > 0, rather than of ordern as required here.[3]