Primality Testing and Integer Factorization: The Computational Edge
How do we determine if a very large number is prime, or find its prime factors? These are central questions in computational number theory.
Primality Testing
Primality testing is the problem of determining whether a given integer is prime or composite.
- Trial Division: The simplest method. To test , try dividing it by all primes up to . If none divide , then is prime. This is efficient for small but becomes impractically slow for large numbers (e.g., hundreds of digits).
- Fermat's Little Theorem: If is a prime number, then for any integer not divisible by , we have:
(This means is divisible by ). This can be used for a probabilistic test: pick a random . If , then is definitely composite. If , then is probably prime. However, some composite numbers (Carmichael numbers) pass this test for all coprime to .
- Miller-Rabin Test: A more sophisticated probabilistic test based on Fermat's Little Theorem. It has a very low probability of declaring a composite number as prime. By repeating the test with multiple random choices of , the probability of error can be made arbitrarily small. This is widely used in practice.
- AKS Primality Test (Agrawal-Kayal-Saxena): Discovered in 2002, this was a major breakthrough. It is the first algorithm that is:
- General: Works for all numbers.
- Polynomial-time: Its runtime is bounded by a polynomial in the number of digits of .
- Deterministic: Always gives the correct answer (not probabilistic).
Unconditional: Its correctness does not rely on any unproven hypotheses (like RH).
While theoretically important, AKS is slower in practice for most numbers than Miller-Rabin.
Integer Factorization
Integer factorization is the problem of finding the prime factors of a given composite integer . This is believed to be a much harder computational problem than primality testing.
- For small numbers, trial division works.
- For larger numbers, more advanced algorithms are needed, such as:
- Pollard's rho algorithm
- Quadratic Sieve (QS)
- General Number Field Sieve (GNFS): This is the fastest known algorithm for factoring very large integers (typically over 100 digits).
The presumed difficulty of factoring large numbers is the cornerstone of many modern public-key cryptography systems, most notably the RSA algorithm. If someone discovered a fast, general-purpose factorization algorithm, it would break much of today's internet security.