Download Lecture 3: January 14 3.1 Primality Testing (continued)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

List of important publications in mathematics wikipedia , lookup

Theorem wikipedia , lookup

Mathematical proof wikipedia , lookup

Central limit theorem wikipedia , lookup

Collatz conjecture wikipedia , lookup

Fundamental theorem of algebra wikipedia , lookup

Law of large numbers wikipedia , lookup

List of prime numbers wikipedia , lookup

Wiles's proof of Fermat's Last Theorem wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Quadratic reciprocity wikipedia , lookup

Transcript
CSE 525 Randomized Algorithms & Probabilistic Analysis
Winter 2008
Lecture 3: January 14
Lecturer: James R. Lee
Scribe: Alan Ritter, Bao-Nguyen Nguyen
Disclaimer: These notes have not been subjected to the usual scrutiny reserved for formal publications.
They may be distributed outside this class only with the permission of the Instructor.
3.1
Primality Testing (continued)
Z∗n = {a : gcd(a, n) = 1} refers to the multiplicative group modulo n.
3.1.1
Fermat Test
Recall from last time, the Fermat test, which makes use of Fermat’s Little Theorem to test if n is prime or
composite:
choose a ∈ {2 . . . n − 1} uniformly at random
if gcd(a, n) 6= 1 then
return(composite)
else if an−1 6≡ 1 (mod n) then
return(composite)
else
return(maybe prime)
Note that the Fermat test has one-sided error. It can mistakenly output “prime” when it’s input was in
fact composite. Also there is a set of numbers, referred to as Carmichael Numbers, for which this test fails
regardless of choice of a.
Claim 3.1 If n is not a Carmichael Number(CN), then Pr[error] ≤ 12 .
Proof: Define Sn = {a ∈ Z∗n : an−1 ≡ 1 (mod n)}. Sn contains the set of inputs which cause Fermat’s
test to fail. Furthermore Sn is a subgroup of Z∗n , since it contains 1, it is closed under multiplication
((ab)n−1 ≡ an−1 bn−1 ≡ 1 (mod n)), and each element a has an inverse an−2 . Sn is also a proper subgroup,
because n is not a CN, so there must exist some a ∈ Z∗n such that a ∈
/ Sn , so |Sn | < |Z∗n |. By Lagrange’s
1
∗
∗
theorem, |Sn | | |Zn |, therefore, |Sn | ≤ 2 |Zn |
Claim 3.1 suggests that CNs are the only bad inputs to the Fermat test, and because
lim Pr[random b bit number is CN] = 0
b→∞
the Fermat test is useful for some applications.
3-1
3-2
Lecture 3: January 14
3.1.2
Miller-Rabin Primality test
Miller-Rabin is a randomized primality testing algorithm which does not always fail when it’s input is a
CN.
Definition 3.2 a ∈ Z∗n is a quadratic residue (mod n) if a ≡ x2 (mod n) for some x ∈ Z∗n . We call x a
“square root” of a.
Claim 3.3 If n is prime, then ±1 are the only square roots of 1 (mod n).
Proof: Assume that x2 ≡ 1 (mod n). Then we have:
x2
≡ 1(mod n)
x −1
≡ 0(mod n)
(x − 1)(x + 1)
≡ 0(mod n)
2
Therefore, either n|x − 1 or n|x + 1, and thus x ≡ ±1 (mod n).
Claim 3.3 suggests another test for primality, namely checking for square roots of 1 (mod n) which are not
±1. The Miller-Rabin algorithm makes use of this in addition to the Fermat test:
choose a ∈ {2 . . . n − 1} uniformly at random
if gcd(a, n) 6= 1 then
return(composite)
choose r, R such that 2r R = n − 1 (with R odd)
i
compute bi = a2 R for 0 ≤ i ≤ r
if an−1 6≡ 1 (mod n) then
return(composite)
else if b0 ≡ 1 (mod n) then
return(maybe prime)
else
select the smallest i s.t. bi = 1
if bi−1 6≡ −1 (mod n) then
return(composite)
else
return(maybe prime)
Claim 3.4 If n is odd, composite and not a prime power, then Pr[error] ≤ 21 .
It is easy to check if n is a prime power (the proof is an exercise).
Definition 3.5 s is a bad power if ∃x(xs ≡ −1(mod n)). Given a bad power s, define Sn as the set of all
x s.t. xs ≡ ±1(mod n).
Lemma 3.6 If n is composite, odd, and not a prime power, then Sn is a proper subgroup of Z∗n .
We first present a proof of claim 3.4 using lemma 3.6:
∗
Proof: Let s∗ = 2i R be the largest bad power. There exists at least one of these, since R is odd, and thus
R
(−1) ≡ −1 (mod n). Now suppose that a ∈ {2, 3, . . . , n − 1} is not a witness; there are two possible cases:
Lecture 3: January 14
3-3
1. aR ≡ a2R ≡ a4R ≡ . . . ≡ an−1 ≡ 1 (mod n).
i
2. For some i ∈ {0, . . . , r − 1}, a2
R
≡ −1 (mod n) and a2
i+1
R
≡ . . . ≡ an−1 ≡ 1 (mod n).
∗
In case 1 above, as ≡ 1 (mod n), so a ∈ Sn . In case 2, 2i R is a bad power, and because s∗ is the largest bad
∗
i∗
power, i∗ ≥ i. Hence, from the above sequence of equivalences, as ≡ a2 R ≡ ±1 (mod n). So in either case
a ∈ Sn , and because Sn is a proper subgroup of Z∗n (due to Lemma 3.6) we can apply Lagrange’s Theorem:
Pr[error] = Pr[a is not a witness]
≤ Pr[a ∈ Sn ]
|Sn |
≤
|Z∗n |
1
≤
2
Now we prove lemma 3.6:
Proof: Sn is clearly a subgroup of Z∗n , because it contains 1, it is closed under multiplication (xs · y s ≡
(x · y)s ≡ (±1)s ≡ ±1(mod n)), and each element x has an inverse x2s−1 . We now show that Sn is a proper
subgroup of Z∗n . Because n is odd, composite, and not a prime power, there exists n1 , n2 which are co-prime
and odd, such that n = n1 n2 . Since s is a bad power, there exists an x s.t. xs ≡ −1 (mod n). Now using
the Chinese Remainder Theorem, we can find y ∈ Z∗n such that:
y
≡ x(mod n1 )
y
≡ 1(mod n2 )
So we have that:
y s ≡ xs
y
s
≡
−1(mod n1 )
≡ 1(mod n2 )
(3.1)
(3.2)
If y is in Sn , then y s ≡ ±1(mod n). If y s ≡ 1(mod n), then y s ≡ 1(mod n1 ) which contradicts 3.1. If
y s ≡ −1(mod n), then y s ≡ −1(mod n2 ) which contradicts 3.2. Therefore y ∈
/ Sn by contradiction, so Sn is
a proper subgroup of Z∗n .
3.2
The Probabilistic Method
The probabilistic method is a nonconstructive, powerful mathematical tool pioneered by Paul Erdos, for
proving the existence of a prescribed kind of object. It works by showing that given some probability
distributions over random objects, the probability that the object we choose satisfies the desired properties
is more than 0.
3.2.1
MAX-3SAT
3.2.1.1
Existence of a good solution - probabilistic method
MAX-3SAT is an NP-hard optimization problem. This example will show how a simple probabilistic method
can yields a good lower bound for this problem.
3-4
Lecture 3: January 14
Input: A 3-CNF boolean formula ϕ = C1 ∧ C2 ∧ · · · ∧ Cm in which each Ci is a disjunction of 3 literals on
the set of variables {x1 , x2 , · · · xn }. For the purpose of this this section, we assume that the literals of each
Ci come from different variables.
Output: Find a truth assignment to boolean variables {x1 , x2 , · · · , xn } to maximize the number of clauses
Ci that are satisfied.
Claim 3.7 For every ϕ, there exists an assignment that satisfies at least
7m
8
clauses.
Proof: Choose a truth assignment to {x1 , x2 , · · · , xn }uniformly independently at random. Define
1 if Ci is satisfied
Yi =
0 otherwise
Let Y be the number of satisfied clauses: Y =
Pm
i=1
Yi .
Since among the 8 truth assignments to the variables of Ci , exactly one of them doesn’t satisfy Ci (recall
the assumption that the three literals of Ci come from different variables), we have:
E[Yi ] = Pr[Ci is satisfied] =
7
8
By linear of expectation,
E[Y ] =
m
X
E[Yi ] =
i=1
7
m.
8
In the sample space, there exist a point at which Y takes value at least E[Y ]. Thus, there exists an assignment
satisfying at least 87 m clauses.
3.2.1.2
Constructing good solutions - Markov’s inequality
The previous section proved that there exists an assignment satisfying at least 78 m clauses without telling
how to construct such a solution. In fact, the probability of hitting one may be vanishingly small. In this
section, we show that the randomized algorithm which assigns random values to variables produces good
solutions - those satisfy at least 3m
4 clauses - with high probability. To bound the chance of getting good
solutions, we need a new tool: Markov’s Inequality.
Theorem 3.8 (Markov’s Inequality) If X is a non-negative random variable then for all α > 0,
Pr[X ≥ αE[X]] ≤
1
α
Proof: The proof is simple and is left as an exercise.
Let Z = m − Y , the number of unsatisfied clauses. Then Z is non-negative and
m
E[Z] = m − E[Y ] =
8
By Markov’s Inequality,
Pr[Z ≥ αE[Z]] = Pr[Z ≥
αm
1
]≤
8
α
Lecture 3: January 14
3-5
Choose α = 2, we have
Pr[Z ≥
m
1
]≤
4
2
Pr[Y >
3m
1
]>
4
2
or in other words,
Therefore, a random assignment satisfies at least
3
4
of the clauses with the probability at least 12 .