COMPUTER PROBLEMS: DAY 7 1. Computing Legendre Symbols

advertisement
COMPUTER PROBLEMS:
DAY 7
1. Computing Legendre Symbols
Recall the definition of the Legendre Symbol:
Definition 1. For integers a


0
a
= +1

p
−1
and positive odd primes p,
if a ≡ 0 mod p
if a ≡
6 0 mod p and a is a square mod p
if a is not a square mod p.
As a computational tool, we introduce the generalized Legendre symbol (also known
as the Jacobi symbol):
Definition 2. Let a be an integer and n an odd positive integer. Let n = p1 p2 · · · pk
be the prime factorization of n. Then,
a
a
a
a
···
.
=
n
p1
p2
pk
The generalized Legendre symbol has the following properties:
ab
a
b
(1)
=
n
n n
(2) If m and n are odd and positive, then
 n


if m ≡ 1 mod 4 or n ≡ 1 mod 4


m

m
=

n

n


−
otherwise.
m
(3)
(
2
1
if n ≡ 1, 7 mod 8
=
n
−1 if n ≡ 3, 5 mod 8.
1
= 1.
(4)
a
a
b
(5) If a ≡ b mod n then
=
.
n
n
a
(6) If a is a square mod n then
= 1.
n
1
COMPUTER PROBLEMS:
DAY 7
2
a
= 1 does not
Note that the converse of this last property is not true. That is,
n
2
necessarily imply that a is a square mod n unless n is prime. For example,
= 1,
9
but 2 is not a square mod 9.
Example 3.
15881
345
971
971
=
=
=
(1)
15881
971
971
345
6
345
64
2
281
=
=
=
= 16 = 1.
=
345
281
281
281
Example 4.
541
13907
382
2
191
191
(2)
=
=
=
=−
13907
541
541
541 541
541
5
159
191
32
2
541
=−
=
=
=
= 1.
=−
191
191
159
159
159
Exercise 5. Compute the following:
300
(1)
13841
323
(2)
10559
4577
(3)
9497
Exercise 6. Determine if 527 is a square mod 12917.
We can use the following algorithm to compute the generalized Legendre symbol:
(1) Reduce the top number modulo the bottom number. If the top number is now
0, the symbol equals 0.
(2) If the top number is even pull out 2 and compute. Repeat until the top number
is odd.
a
(3) If the top number is 1, finish the computation. Otherwise, convert
to
b
b
and return to step 1.
±
a
Exercise 7. Write a Python program that computes the generalized Legendre symbol.
Use this program to compute the Legendre symbols from the previous exercise and
compare these answers with those you computed earlier.
2. Relative Efficiency of Primality Tests
Exercise 8. Find an odd composite n and a base a such that an−1 ≡ 1 mod n.
COMPUTER PROBLEMS:
DAY 7
3
Exercise 9. Find an odd composite n and a base a such that a is not a Miller-Rabin
witness for n. (In other words, using a in the Miller-Rabin primality test does not
show that n is composite. You can use the function MillerRabinWitness in the
Miller-Rabin code to do this test. If it returns false then a is not a Miller-Rabin
witness for n.
Exercise 10. Run the Fermat primality test one hundred times with random bases
on
(3) 970144211072083375324432436728236532412880462773480357
858212700976290933264798910842217879225575878584165340764
1566872977940913068169745200838573927400347.
How many of your randomly chosen bases are witnesses to the compositeness of the
above number? Can you factor the number?
Exercise 11. Repeat the previous exercise, but now use the Miller-Rabin primality
test.
Exercise 12. Repeat the previous two exercises with the number 999629786233.
Download