You are on page 1of 22

Algebraic

Foundations of
Computer Science
(AFCS)

Prof.Dr. F.L.
Tiplea

Linear
Algebraic Foundations of Computer Science.
congruential
equations Computational Introduction to Number Theory (II)
The Chinese
remainder
theorem

Quadratic
residues
Ferucio Laurenţiu Ţiplea
The Legendre
symbol
Department of Computer Science
The Jacobi symbol “AL.I.Cuza” University of Iaşi
Course readings Iaşi, Romania
E-mail: fltiplea@mail.dntis.ro

Spring 2017

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 1 / 22
Outline
Algebraic
Foundations of
Computer Science
(AFCS)

Prof.Dr. F.L.
1 Linear congruential equations
Tiplea

Linear
congruential 2 The Chinese remainder theorem
equations

The Chinese
remainder
theorem 3 Quadratic residues
Quadratic
residues

The Legendre
symbol 4 The Legendre symbol
The Jacobi symbol

Course readings
5 The Jacobi symbol

6 Course readings

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 2 / 22
Linear congruential equations
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 1
Prof.Dr. F.L. Let a, b, m ∈ Z with m ≥ 1. Then, the equation
Tiplea

Linear
congruential
ax ≡ b mod m
equations

The Chinese is solvable in Z iff (a, m)|b. Moreover, if it is solvable, then it has
remainder
theorem exactly (a, m) solution in Zm which are of the form
Quadratic
residues
 
m
The Legendre x0 + i mod m,
symbol (a, m)
The Jacobi symbol

Course readings where x0 is an arbitrary integer solution and 0 ≤ i < (a, m).

Example 2
The equation
5x ≡ 25 mod 10
has (5, 10) = 5 solutions in Z10 : 1, 3, 5, 7, 9.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 3 / 22
Linear congruential equations
Algebraic
Foundations of
Computer Science Algorithm 1: Solving linear congruential equations
(AFCS)

Prof.Dr. F.L.
Tiplea
input : m ≥ 1 and a, b ∈ Z;
output: all solutions modulo m of ax ≡ b mod m;
Linear
congruential
equations begin
The Chinese compute gcd(a, m) := αa + βm;
remainder
theorem if gcd(a, m)|b then
Quadratic b0 := b/gcd(a, m);
residues

The Legendre
x0 := αb0 ;
symbol for i := 0 to gcd(a, m) − 1 do
The Jacobi symbol print ((x0 + im/gcd(a, m)) mod m)
Course readings
else
“no integer solutions”

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 4 / 22
The Chinese remainder theorem
Algebraic
Foundations of
Computer Science
According to D.Wells, the following problem was posed by Sun
(AFCS)
Tsu Suan-Ching (4th century AD):
Prof.Dr. F.L.
Tiplea There are certain things whose number is unknown.
Linear Repeatedly divided by 3, the remainder is 2; by 5, the
congruential
equations remainder is 3; and by 7, the remainder is 2. What will be
The Chinese the number?
remainder
theorem

Quadratic The mathematical form of this problem is:


residues

The Legendre

symbol  x ≡ 2 mod 3
The Jacobi symbol x ≡ 3 mod 5
x ≡ 2 mod 7
Course readings

This system of equations has a least integer solution which is


x = 23.

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 5 / 22
The Chinese remainder theorem
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 3 (Chinese Remainder Theorem)
Prof.Dr. F.L.
Tiplea
Let k ≥ 1 and m1 , . . . , mk be pairwise co-prime integers. Then, for
any b1 , . . . , bk ∈ Z, the following system (S) of equations has a
Linear
congruential unique solution modulo m1 · · · mk
equations

The Chinese
remainder  x ≡ b1 mod m1
theorem
(S) ···
Quadratic
x ≡ bk mod mk

residues

The Legendre
symbol

The Jacobi symbol


The solution can be obtained as follows:
Course readings Qk
compute ci = j=1, j6=i mj ;
compute an integer solution xi of the equation
ci x ≡ bi mod mi , for any i;
x = (c1 x1 + · · · + ck xk ) mod (m1 · · · mk ) is the unique solution
modulo m1 · · · mk of the system.

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 6 / 22
The Chinese remainder theorem: example
Algebraic
Foundations of
Computer Science
(AFCS)
Example 4
Prof.Dr. F.L.
Tiplea
Let (S) be the system

Linear
congruential  x ≡ 2 mod 3
equations
(S) x ≡ 3 mod 5
The Chinese
x ≡ 2 mod 7

remainder
theorem

Quadratic
residues
Then:
The Legendre
symbol
c1 = 35, c2 = 21, and c3 = 15;
The Jacobi symbol x1 = 1 is a solution of 35x ≡ 2 mod 3;
Course readings
x2 = 3 is a solution of 21x ≡ 3 mod 5;
x3 = 2 is a solution of 15x ≡ 2 mod 7;
x = (35 · 1 + 21 · 3 + 15 · 2) mod 105 = 128 mod 105 = 23 is
the unique solution modulo 105 of the system (S).

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 7 / 22
The Chinese remainder theorem: application
Algebraic
Foundations of
Computer Science
There is an important application of CRT to the problem of solving
(AFCS)
equations of the form f (x) ≡ 0 mod m, where f (x) is a polynomial
Prof.Dr. F.L.
Tiplea with integer coefficients and variables x.
Linear
congruential
equations
Theorem 5
The Chinese
remainder
theorem
Let f (x) be a polynomial with integer coefficients, and m1 , . . . , mk
Quadratic
be pairwise co-prime integers. Then, a ∈ Z is a solution to the
residues
equation
The Legendre
symbol f (x) ≡ 0 mod m1 · · · mk (1)
The Jacobi symbol
if and only if a is a solution to each of the equations
Course readings

f (x) ≡ 0 mod mi , 1 ≤ i ≤ k. (2)

Moreover, the number of solutions in Zm1 ···mk of the equation (1) is


the product of the numbers of solutions in Zmi of the equations (2).

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 8 / 22
The Chinese remainder theorem: application
Algebraic
Foundations of
Computer Science
(AFCS)
Example 6
Prof.Dr. F.L.
Tiplea 1 The equation
Linear x 2 ≡ 1 mod p,
congruential
equations

The Chinese
where p > 2 is a prime number, has exactly 2 solutions in Zp ,
remainder
theorem
namely x = 1 and x = p − 1.
Quadratic 2 The equation
residues
x 2 ≡ 1 mod p1 · · · pk ,
The Legendre
symbol

The Jacobi symbol


where p1 , . . . , pk are distinct odd primes (k ≥ 2), has exactly
Course readings
2k solutions in Zp1 ···pk .

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 9 / 22
Quadratic residues - motivation
Algebraic
Foundations of
Computer Science
(AFCS)
Proposition 1 (Solving quadratic congruences)
Prof.Dr. F.L.
Tiplea
Let p > 2 be a prime and a, b, c ∈ Z such that (a, p) = 1. Then,
the quadratic congruence
Linear
congruential
equations
ax 2 + bx + c ≡ 0 mod p
The Chinese
remainder
theorem has
Quadratic
residues 1 two roots in Zp , if ∆ ≡ y 2 mod p for some y ∈ Z with p 6 |y ;
The Legendre
symbol
2 one root in Zp , if ∆ ≡ 0 mod p;
The Jacobi symbol 3 no roots, otherwise,
Course readings
where ∆ = b2 − 4ac.

How hard is to decide if a given a ∈ Z∗p satisfies a ≡ y 2 mod p for


some y ∈ Z ?

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 10 / 22
Quadratic residues and non-residues
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 7
Prof.Dr. F.L.
Tiplea
Let p > 2 be a prime and a ∈ Z non-divisible by p. a is called a
quadratic residue modulo p if a ≡ x 2 mod n for some integer x.
Linear
congruential
equations

The Chinese If a is neither divisible by p nor a quadratic residue modulo p then


remainder
theorem a is called a quadratic non-residue modulo p.
Quadratic
residues

The Legendre
Remark 1
symbol
An integer a non-divisible by a prime p > 2 is a quadratic
The Jacobi symbol

Course readings
(non-)residue modulo p if and only if a mod p is a quadratic
(non-)residue modulo p.

Denote
QRp = {a ∈ Z∗p |a is a quadratic residue modulo p}
QNRp = {a ∈ Z∗p |a is a quadratic non-residue modulo p}

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 11 / 22
Quadratic residues. Basic properties
Algebraic
Foundations of
Computer Science
(AFCS)
Proposition 2
Prof.Dr. F.L. p−1
Tiplea Let p > 2 be a prime. Then, |QRp | = |QNRp | = 2 .
Linear
congruential
equations
Proposition 3
The Chinese
remainder
theorem Let p > 2 be a prime. Then:
Quadratic
residues
1 a, b ∈ QRp ⇒ (ab mod p) ∈ QRp ;
The Legendre 2 a ∈ QRp ∧ b ∈ QNRp ⇒ (ab mod p) ∈ QNRp ;
symbol

The Jacobi symbol


3 a, b ∈ QNRp ⇒ (ab mod p) ∈ QRp .
Course readings

Theorem 8 (Euler’s Criterion)


Let p > 2 be a prime and a ∈ Z∗p . Then,
p−1
1 a ∈ QRp if and only if a 2 ≡ 1 mod p;
p−1
2 a ∈ QNRp if and only if a 2 ≡ −1 mod p.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 12 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
Introduced by Adrien-Marie Legendre in 1798 when trying to prove
(AFCS)
the law of quadratic reciprocity.
Prof.Dr. F.L.
Tiplea

Linear
Definition 9
congruential
equations Letp > 2 be a prime. The Legendre symbol of a ∈ Z, denoted

The Chinese a
remainder p , is defined by
theorem

Quadratic 
0, if p|a
residues
  
The Legendre a
symbol = 1, if p 6 |a and a is a quadratic residue modulo p
The Jacobi symbol
p 
−1, if p 6 |a and a is a quadratic non-residue modulo p

Course readings

Remark that the Legendre symbol is only defined for primes


p > 2. For p = 2, all even integers are divisible by p and all odd
integers are quadratic residues modulo p.

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 13 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
(AFCS)
Proposition 4
Letp >2 be  a, b ∈Z. If a ≡
 a prime and  b mod p then
Prof.Dr. F.L.
Tiplea 
a b a a mod p
Linear p = p . Therefore, p = p .
congruential
equations

The Chinese
remainder
theorem
Proposition 5
Quadratic
residues
  p−1
a
The Legendre
Let p > 2 be a prime. Then, for any a ∈ Z, p ≡a 2 mod p.
symbol

The Jacobi symbol

Course readings

Proposition 6
    
ab a b
Let p > 2 be a prime. Then, for any a, b ∈ Z, p = p p .

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 14 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
According to the above properties, computing theLegendre
 
and qp , for
(AFCS)

Prof.Dr. F.L.
symbol modulo p comes down to computing −1 p
Tiplea
any prime q with 2 ≤ q < p.
Linear
congruential
equations

The Chinese Proposition 7


remainder
theorem Let p > 2 be a prime. Then,
Quadratic
residues   (
The Legendre
−1 p−1 1, if p ≡ 1 mod 4
symbol = (−1) 2 =
p −1, if p ≡ 3 mod 4
The Jacobi symbol

Course readings

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 15 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 10 (Gauss’ Criterion)
Prof.Dr. F.L.
Tiplea
Letp > 2 be a prime and a ∈ Z non-divisible by p. Then,

a r
Linear p = (−1) , where
congruential
equations

The Chinese
r = |{i ∈ {1, . . . , (p − 1)/2}|ia mod p > p/2}|.
remainder
theorem

Quadratic
residues

The Legendre
symbol

The Jacobi symbol Proposition 8


Course readings
Let p > 2 be a prime. Then,
  (
2 p2 −1 1, if p ≡ ±1 mod 8
= (−1) 8 =
p −1, if p ≡ ±3 mod 8

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 16 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 11 (Quadratic reciprocity law)
Prof.Dr. F.L.
Tiplea
Let p, q > 2 be distinct primes. Then,
  
Linear q p p−1 q−1
congruential = (−1) 2 · 2 .
equations
p q
The Chinese
remainder
theorem Equivalently,
Quadratic
residues
  
− qp , if p, q ≡ 3 mod 4
  
The Legendre q
symbol = p
p otherwise
q ,
The Jacobi symbol

Course readings

Example 12
         
7 59 3 7 1
=− =− = = =1
59 7 7 3 3

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 17 / 22
The Legendre symbol
Algebraic
Foundations of
Computer Science
Basic rules for computing the Legendre symbol (review):
(AFCS)    
Prof.Dr. F.L.
1 if a ≡ b mod p then pa = bp
Tiplea
    
ab
Linear
2
p = pa b
p
congruential
equations  
1
p =1
3
The Chinese
remainder
theorem
(
 
−1 1, if p ≡ 1 mod 4
Quadratic
residues
4
p =
−1, if p ≡ 3 mod 4
The Legendre
symbol
(
 
2 1, if p ≡ ±1 mod 8
p =
The Jacobi symbol 5
Course readings −1, if p ≡ ±3 mod 8
  
  − p , if p ≡ q ≡ 3 mod 4
q  q
p = p
6

q , if p ≡ 1 mod 4 or q ≡ 1 mod 4
for any distinct primes p, q > 2 and a, b ∈ Z.

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 18 / 22
The Jacobi symbol
Algebraic
Foundations of
Computer Science
Introduced by Carl Gustav Jacob Jacobi in 1837 as a
(AFCS)
generalization of the Legendre symbol.
Prof.Dr. F.L.
Tiplea
Definition 13
Linear
congruential
equations
Let n > 0 be an odd integer. The Jacobi symbol of a ∈ Z, denoted
a
The Chinese n , is defined by
remainder
theorem 
Quadratic
 a  1, if n=1
residues =  a e 1  ek
a
The Legendre n  p ··· p , otherwise
symbol 1 k

The Jacobi symbol

Course readings where n = p1e1 · · · pkek is the prime factorization of n.

Remark 2
1 The Jacobi symbol is defined only for odd integers n > 0.
(a, n) = 1 if and only if na 6= 0, for all a ∈ Z and n > 0 odd.

2

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 19 / 22
The Jacobi symbol
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 14
Prof.Dr. F.L.
Tiplea
The following properties hold:
if a ≡ b mod n then na = bn
 
1
Linear
congruential ab
= na bn
  
equations 2
n
The Chinese 1

n =1
remainder 3
theorem (
Quadratic
−1
 1, if n ≡ 1 mod 4
residues 4
n =
The Legendre −1, if n ≡ 3 mod 4
symbol (
The Jacobi symbol
2
 1, if n ≡ ±1 mod 8
n =
5
Course readings
−1, if n ≡ ±3 mod 8
(
− mn , if n ≡ m ≡ 3 mod 4

m

n =
6
n

m , if n ≡ 1 mod 4 or m ≡ 1 mod 4
for any distinct odd integers n, m > 0 and a, b ∈ Z.

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 20 / 22
The Jacobi symbol
Algebraic
Foundations of
Computer Science Algorithm 2: Computing the Jacobi symbol
(AFCS)

Prof.Dr. F.L.
Tiplea
input : integer a and odd integer n > 0;
output: na

Linear
congruential
equations begin
The Chinese b := a mod n; c := n; s := 1;
remainder
theorem while b ≥ 2 do
Quadratic while 4|b do b := b/4;
residues

The Legendre
if 2|b then
symbol if c mod 8 ∈ {3, 5} then s := −s;
The Jacobi symbol
b := b/2;
Course readings
if b = 1 then quit;
if b mod 4 = 3 = c mod 4 then
s := −s;
(b, c) := (c mod b, b);
return s · b;

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 21 / 22
Course readings
Algebraic
Foundations of
Computer Science
(AFCS)
1 F.L. Ţiplea: Fundamentele Algebrice ale Informaticii, Ed.
Prof.Dr. F.L. Polirom, Iaşi, 2006, pag. 164–172.
Tiplea

Linear
2 M. B. Nathanson: Elementary Methods in Number Theory,
congruential
equations Graduate Texts in Mathematics, Springer-Verlag, 2000, pag.
The Chinese 100–120.
remainder
theorem

Quadratic
residues

The Legendre
symbol

The Jacobi symbol

Course readings

Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2017 22 / 22

You might also like