12. Primality Tests
Prime number theorem:
GCD
- We can calculate the gcd in time using Euclid’s algorithm
- If is prime, then
- Pick a random and test
Not polynomial time b/c need exponentially many trials
Fermat
- If is a prime number, then all nums
- Chose randomly. has some . By Lagrange:
- If : return prime. Using iterative squaring, we can calculate that
Correctness:
- If prime: always correct
- If not prime: Wrong answer with prob unless is Carmichael num
Pseudo-prime bases: ( implies by condition)
is subgroup of (so Lagrange applies!)
Def. Carmichael nums: not prime and
Correctness:
- If prime: Output always correct
- If not prime: Output correct with Prob (since must divide ) unless Carmichael
Miller-Rabin Certificate
Assume that is uneven (trivial to check)
Lemma
with and uneven. If prime and :
Procedure:
- Chose uniformly randomly
- Check if condition in
- Return prime if met, else not prime
Ex. Carmichael Num 561
- 2 is Miller-Rabin Certificate for 561 not prime
Correctness:
- If prime: always correct
- If not prime: wrong answer with probability (even )