<<

Congruence

Euclidean Algorithm and Congruence

G. Carl Evans

University of Illinois

Fall 2018

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Recall Euclidean Algorithm

Remainder(a, b) is the remainder when a is divided by b.

RecursiveGCD (a, b) r ← Remainder(a, b) if r = 0 return b return RecursiveGCD (b, r)

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence But why does Euclidean algorithm work?

RecursiveGCD (a, b) r ← Remainder(a, b) if r = 0 return b return RecursiveGCD (b, r)

The Euclidean algorithm works iff gcd(a, b) = gcd(b, r), where r = the remainder of the remainder when a is divided by b.

Euclidean Algorithm and Congruence Let a, b, q, r ∈ Z with b > 0 and a = bq + r. Let n = gcd(a, b) and m = gcd(b, r) So n is the largest that divides both a and b and m is the largest integer that divides both b and r. Since n | a and n | b it holds that a = nk, b = np for some k, p ∈ Z. From a = bq + r we get r = bq − a expanding to r = nk − npq = n(k − pq) and since k − pq ∈ Z then n | r.

Euclidean Algorithm Congruence Proof of Euclidean algorithm

Claim: For any a, b, q, r, with b > 0, if a = bq + r then gcd(a, b) = gcd(b, r).

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Proof of Euclidean algorithm

Claim: For any integers a, b, q, r, with b > 0, if a = bq + r then gcd(a, b) = gcd(b, r).

Let a, b, q, r ∈ Z with b > 0 and a = bq + r. Let n = gcd(a, b) and m = gcd(b, r) So n is the largest integer that divides both a and b and m is the largest integer that divides both b and r. Since n | a and n | b it holds that a = nk, b = np for some k, p ∈ Z. From a = bq + r we get r = bq − a expanding to r = nk − npq = n(k − pq) and since k − pq ∈ Z then n | r.

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Proof of Euclidean algorithm pt2

Claim: For any integers a, b, q, r, with b > 0, if a = bq + r then gcd(a, b) = gcd(b, r).

Similarly:

m | b ∧ m | r → b = km, r = pm, k, p ∈ Z

a = bq + r = km + mp = m(kq + p) kq + p ∈ Z So m | a. Since n and m divide a, b and r there are three cases either n < m, m < n or, n = m. Since n is the largest value that divides a and b, n is not less then m. Similarly since m is the largest value that divides b and r, m is not less then n. Thus m = n. QED

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Applications of congruence

bitwise operations error checking encryption telling time etc.

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Congruence mod k

Two integers are congruent mod k if the differ by an integer multiple of k Definition: If k is any positive integer, two integers a and b are congruent mod k if k divides (a − b).

a ≡ b( mod k) ↔ k | (a − b)

Euclidean Algorithm and Congruence Let a, b, c, d, k ∈ Z with k > 0 s.t. a ≡ b (mod k) and c = d (mod k).

From the definition of mod we get k | a − b and k | c − d.

From linearity of divides we get k | (a − b) + (c − d) and then k | (a + b) − (b + d) so (a + c) ≡ (b + d) (mod k). QED

Euclidean Algorithm Congruence Modulus proof

Claim: For any integers a, b, c, d, k with k > 0, if a ≡ b (mod k) and c ≡ d (mod k) then (a + c) ≡ (b + d) (mod k). Definition: a ≡ b (mod k) ↔ k | (a − b)

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Modulus addition proof

Claim: For any integers a, b, c, d, k with k > 0, if a ≡ b (mod k) and c ≡ d (mod k) then (a + c) ≡ (b + d) (mod k). Definition: a ≡ b (mod k) ↔ k | (a − b)

Let a, b, c, d, k ∈ Z with k > 0 s.t. a ≡ b (mod k) and c = d (mod k).

From the definition of mod we get k | a − b and k | c − d.

From linearity of divides we get k | (a − b) + (c − d) and then k | (a + b) − (b + d) so (a + c) ≡ (b + d) (mod k). QED

Euclidean Algorithm and Congruence Let a, b, c, d, k ∈ Z with k > 0 s.t. a ≡ b (mod k) and c = d (mod k). From the definition of mod we get k | a − b and k | c − d. So (a − b) = nk and (c − d) = pk by def divides. This leads to a = nk + b and c = pk + d and

ac = (nk+b)(pk+d) = pnk2+dnk+bpk+bd = bd+(pnk+dn+b)k

Since pnk + dn + b is an integer ac = bd + qk where q is an integer. Thus ac − bd = qk and k | (ac − bd) and ac ≡ bd (mod k). QED

Euclidean Algorithm Congruence Modulus proof

Claim: For any integers a, b, c, d, k with k > 0, if a ≡ b (mod k) and c ≡ d (mod k) then ac ≡ bd( mod k). Definition: a ≡ b( mod k) ↔ k | (a − b)

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Modulus multiplication proof

Claim: For any integers a, b, c, d, k with k > 0, if a ≡ b (mod k) and c ≡ d (mod k) then ac ≡ bd( mod k). Definition: a ≡ b( mod k) ↔ k | (a − b)

Let a, b, c, d, k ∈ Z with k > 0 s.t. a ≡ b (mod k) and c = d (mod k). From the definition of mod we get k | a − b and k | c − d. So (a − b) = nk and (c − d) = pk by def divides. This leads to a = nk + b and c = pk + d and

ac = (nk+b)(pk+d) = pnk2+dnk+bpk+bd = bd+(pnk+dn+b)k

Since pnk + dn + b is an integer ac = bd + qk where q is an integer. Thus ac − bd = qk and k | (ac − bd) and ac ≡ bd (mod k). QED

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Equivalence classes with modulus

The equivalence class of integer x (written [x]) is the set of all integers congruent to x( mod k).

In ( mod 7), [3] = {..., −11, −4, 3, 10, 17,... }

In ( mod 5), [3] = {..., −7, −2, 3, 8, 13,... }

In Z5, [3] = [8] = [−2]

Euclidean Algorithm and Congruence Euclidean Algorithm Congruence Modulus

[x] + [y] = [x + y] [x] ∗ [y] = [x ∗ y]

Euclidean Algorithm and Congruence