HOME

TheInfoList



OR:

Wheel factorization is an improvement of the
trial division Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer ''n'', the integer to be factored, can be divided by each number in turn t ...
method for
integer factorization In number theory, integer factorization is the decomposition of a composite number into a product of smaller integers. If these factors are further restricted to prime numbers, the process is called prime factorization. When the numbers are suf ...
. The trial division method consists of dividing the number to be factorized successively by the first integers (2, 3, 4, 5, ...) until finding a divisor. For wheel factorization, one starts from a small list of numbers, called the ''basis'' — generally the first few
prime number A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
s; then one generates the list, called the ''wheel'', of the integers that are
coprime In mathematics, two integers and are coprime, relatively prime or mutually prime if the only positive integer that is a divisor of both of them is 1. Consequently, any prime number that divides does not divide , and vice versa. This is equival ...
with all numbers of the basis. Then to find the smallest divisor of the number to be factorized, one divides it successively by the numbers in the basis, and in the wheel. With the basis , this method reduces the number of divisions to of the number necessary for trial division. Larger bases reduce this proportion even further; for example, with basis to ; and with basis to .


A typical example

With a given basis of the first few prime numbers , the "first turn" of the wheel consists of: :. The second turn is obtained by adding 30, the
product Product may refer to: Business * Product (business), an item that serves as a solution to a specific consumer problem. * Product (project management), a deliverable or set of deliverables that contribute to a business solution Mathematics * Produ ...
of the basis, to the numbers in the first turn. The third turn is obtained by adding 30 to the second turn, and so on. For implementing the method, one may remark that the increments between two consecutive elements of the wheel, that is : remain the same after each turn. The suggested implementation that follows uses an auxiliary function div(''n'', ''k''), which tests whether ''n'' is evenly divisible by ''k'', and returns ''true'' in this case, ''false'' otherwise. In this implementation, the number to be factorized is ''n'', and the program returns the smallest divisor of ''n'' returning ''n'' itself if it is prime. if div(''n'', 2) = true then return 2 if div(''n'', 3) = true then return 3 if div(''n'', 5) = true then return 5 ''k'' := 7; ''i'' := 0 while ''k'' * ''k'' ≤ ''n'' do if div(''n'', ''k'') = true, then return ''k'' ''k'' := ''k'' + inc 'i'' if ''i'' < 7 then ''i'' := ''i'' + 1 else ''i'' := 0 return ''n'' For getting the complete factorization of an integer, the computation may be continued without restarting the wheel at the beginning. This leads to the following program for a complete factorization, where the function "add" adds its first argument at the end of the second argument, which must be a list. factors := while div(''n'', 2) = true do factors := add(2, factors) ''n'' := ''n'' / 2 while div(''n'', 3) = true do factors := add(3, factors) ''n'' := ''n'' / 3 while div(''n'', 5) = true do factors := add(5, factors) ''n'' := ''n'' / 5 ''k'' := 7; ''i'' := 0 while ''k'' * ''k'' ≤ ''n'' do if div(''n'', ''k'') = true then add(''k'', factors) ''n'' := ''n'' / ''k'' else ''k'' := ''k'' + inc 'i'' if ''i'' < 7 then ''i'' := ''i'' + 1 else ''i'' := 0 if ''n'' > 1 then add(''n'', factors) return factors


Another presentation

Wheel factorization is used for generating lists of mostly
prime number A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
s from a simple mathematical formula and a much smaller list of the first prime numbers. These lists may then be used in
trial division Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer ''n'', the integer to be factored, can be divided by each number in turn t ...
or
sieves A sieve, fine mesh strainer, or sift, is a device for separating wanted elements from unwanted material or for controlling the particle size distribution of a sample, using a screen such as a woven mesh or net or perforated sheet material. ...
. Because not all the numbers in these lists are prime, doing so introduces inefficient redundant operations. However, the generators themselves require very little memory compared to keeping a pure list of prime numbers. The small list of initial prime numbers constitute complete parameters for the
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
to generate the remainder of the list. These generators are referred to as wheels. While each wheel may generate an infinite list of numbers, past a certain point the numbers cease to be mostly prime. The method may further be applied recursively as a prime number wheel sieve to generate more accurate wheels. Much definitive work on wheel factorization, sieves using wheel factorization, and wheel sieve, was done by Paul PritchardPritchard, Paul, "Linear prime-number sieves: a family tree," ''Sci. Comput. Programming'' 9:1 (1987), pp. 17–35.Paul Pritchard, A sublinear additive sieve for finding prime numbers, Communications of the ACM 24 (1981), 18–23. Paul Pritchard, Explaining the wheel sieve, Acta Informatica 17 (1982), 477–485. Paul Pritchard, Fast compact prime number sieves (among others), Journal of Algorithms 4 (1983), 332–344. in formulating a series of different algorithms. To visualize the use of a factorization wheel, one may start by writing the natural numbers around circles as shown in the adjacent diagram. The number of spokes is chosen such that prime numbers will have a tendency to accumulate in a minority of the spokes.


Sample graphical procedure

# Find the first few prime numbers to form the basis of the factorization wheel. They are known or perhaps determined from previous applications of smaller factorization wheels or by quickly finding them using the
Sieve of Eratosthenes In mathematics, the sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prim ...
. # Multiply the base prime numbers together to give the result ''n'' which is the circumference of the factorization wheel. # Write the numbers 1 to ''n'' in a circle. This will be the inner-most circle representing one rotation of the wheel. # From the numbers 1 to ''n'' in the innermost circle, strike off all multiples of the base primes from step one as applied in step 2. This composite number elimination can be accomplished either by use of a sieve such as the Sieve of Eratosthenes or as the result of applications of smaller factorization wheels. # Taking ''x'' to be the number of circles written so far, continue to write ''xn'' + 1 to ''xn'' + ''n'' in concentric circles around the inner-most circle, such that ''xn'' + 1 is in the same position as (''x'' − 1)''n'' + 1. # Repeat step 5 until the largest rotation circle spans the largest number to be tested for primality. # Strike off the number 1. # Strike off the spokes of the prime numbers as found in step 1 and applied in step 2 in all outer circles without striking off the prime numbers in the inner-most circle (in circle 1). # Strike off the spokes of all multiples of prime numbers struck from the inner circle 1 in step 4 in the same way as striking off the spokes of the base primes in step 8. # The remaining numbers in the wheel are mostly prime numbers (they are collectively called "relatively" prime). Use other methods such as the Sieve of Eratosthenes or further application of larger factorization wheels to remove the remaining non-primes.


Example

1. Find the first 2 prime numbers: 2 and 3. 2. ''n'' = 2 × 3 = 6 3. 1 2 3 4 5 6 4. strike off factors of 2 and 3 which are 4 and 6 as factors of 2; 6 as the only factor of 3 is already stricken: 1 2 3 4 5 6 5. ''x'' = 1.
''xn'' + 1 = 1 · 6 + 1 = 7.
(''x'' + 1)''n'' = (1 + 1) · 6 = 12.
Write 7 to 12 with 7 aligned with 1. 1 2 3 4 5 6 7 8 9 10 11 12 6. ''x'' = 2.
''xn'' + 1 = 2 · 6 + 1 = 13.
(''x'' + 1)''n'' = (2 + 1) · 6 = 18.
Write 13 to 18.
Repeat for the next few lines. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 7 and 8. Sieving 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 9. Sieving 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 10. The resulting list contains a non-prime number of 25 which is 52. Use other methods such as a sieve to eliminate it to arrive at 2 3 5 7 11 13 17 19 23 29 Note that by using exactly the next prime number of 5 wheel cycles and eliminating the multiple(s) of that prime (and only that prime) from the resulting list, we have obtained the base wheel as per step 4 for a factorization wheel with base primes of 2, 3, and 5; this is one wheel in advance of the previous 2/3 factorization wheel. One could then follow the steps to step 10 using the next succeeding prime of 7 cycles and only eliminating the multiples of 7 from the resulting list in step 10 (leaving some "relative" primes in this case and all successive cases - i.e. some not true fully qualified primes), to get the next further advanced wheel, recursively repeating the steps as necessary to get successively larger wheels.


Analysis and computer implementation

Formally, the method makes use of the following insights: First, that the set of base primes unioned with its (infinite) set of coprimes is a superset of the primes. Second, that the infinite set of coprimes can be enumerated easily from the coprimes to the base set between 2 and the base set product. (Note that 1 requires special handling.) As seen in the example above, the result of repeated applications of the above recursive procedure from steps 4 to 10 can be a wheel list which spans any desired sieving range (to which it can be truncated) and the resulting list then includes only the multiples of primes higher than one past the last used base primes. Note that once a wheel spans the desired upper limit of the sieving range, one can stop generating further wheels and use the information in that wheel to cull the remaining composite numbers from that last wheel list using a Sieve of Eratosthenes type technique but using the gap pattern inherent to the wheel to avoid redundant culls; some optimizations may be able to be made based on the fact that (will be proven in the next section) that there will be no repeat culling of any composite number: each remaining composite will be culled exactly once. Alternatively, one can continue to generate truncated wheel lists using primes up to the square root of the desired sieve range, in which case all remaining number representations in the wheel will be prime; however, although this method is as efficient as to never culling composite numbers more than once, it loses much time external to the normally considered culling operations in processing the successive wheel sweeps so as to take much longer. The elimination of composite numbers by a factorization wheel is based on the following: Given a number k > n, we know that k is not prime if k mod n and n are not relatively prime. From that, the fraction of numbers that the wheel sieve eliminates can be determined (although not all need be physically struck off; many can be culled automatically in the operations of copying of lesser wheels to greater wheels) as 1 -
phi Phi (; uppercase Φ, lowercase φ or ϕ; grc, ϕεῖ ''pheî'' ; Modern Greek: ''fi'' ) is the 21st letter of the Greek alphabet. In Archaic and Classical Greek (c. 9th century BC to 4th century BC), it represented an aspirated voicele ...
(n) / n, which is also the efficiency of the sieve. It is known that : \lim\inf\frac\log\log n = e^\sim 0.56145948, where is
Euler's constant Euler's constant (sometimes also called the Euler–Mascheroni constant) is a mathematical constant usually denoted by the lowercase Greek letter gamma (). It is defined as the limiting difference between the harmonic series and the natural l ...
. Thus phi(n) / n goes to zero slowly as n increases to infinity and it can be seen that this efficiency rises very slowly to 100% for infinitely large n. From the properties of phi, it can easily be seen that the most efficient sieve smaller than x is the one where n = p_1 p_2 ... p_i < x and n p_ \geq x (i.e. wheel generation can stop when the last wheel passes or has a sufficient circumference to include the highest number in the sieving range). To be of maximum use on a computer, we want the numbers that are smaller than n and relatively prime to it as a set. Using a few observations, the set can easily be generated : # Start with S_1 = \ , which is the set for n=1 with 2 as the first prime. This initial set means that all numbers starting at two up are included as "relative" primes as the circumference of the wheel is 1. # Following sets are S_2 = \ which means that it starts at 3 for all odd numbers with the factors of 2 eliminated (circumference of 2), S_6 = \ has the factors of 2 and 3 eliminated (circumference of 6) as for the initial base wheel in the example above and so on. # Let S_n + k be the set where k has been added to each element of S_n . # Then S_ = F_ _n \cup S_n + n \cup S_n + 2n \cup ... \cup S_n + n (p_ - 1)/math> where F_x represents the operation of removing all multiples of x. # 1 and p_ will be the two smallest of S_n when n > 2 removing the need to compute prime numbers separately although the algorithm does need to keep a record of all eliminated base primes which are no longer included in the succeeding sets. # All sets where the circumference n > 2 are symmetrical around n / 2 , reducing storage requirements. The following algorithm does not use this fact, but it is based on the fact that the gaps between successive numbers in each set are symmetrical around the halfway point.


See also

*
Sieve of Sundaram In mathematics, the sieve of Sundaram is a variant of the sieve of Eratosthenes, a simple deterministic algorithm for finding all the prime numbers up to a specified integer. It was discovered by Indian student S. P. Sundaram in 1934. Algorithm S ...
*
Sieve of Atkin In mathematics, the sieve of Atkin is a modern algorithm for finding all prime numbers up to a specified integer. Compared with the ancient sieve of Eratosthenes, which marks off multiples of primes, the sieve of Atkin does some preliminary work ...
*
Sieve theory Sieve theory is a set of general techniques in number theory, designed to count, or more realistically to estimate the size of, sifted sets of integers. The prototypical example of a sifted set is the set of prime numbers up to some prescribed lim ...


References


External links


Wheel Factorization

Improved incremental prime number sieves
by Paul Pritchard {{DEFAULTSORT:Wheel Factorization Primality tests