Escolar Documentos
Profissional Documentos
Cultura Documentos
1 Basic Concepts
Sets, index sets, Cartesian product, Relations and Functions
The Integers and Division
Introduction
Integer Division
Modular Arithmetic
Applications of Congruences
Hushing Functions
Pseudo-random Numbers
Cryptology
Functions
Introduction
Introduction
The part of mathematics involving the integers and their properties
belongs to the branch of mathematics called Number theory.
In this section, will develop the basic concepts of number theory used
throughout the computer science.
We will review some basic concepts of number theory including
Divisibility and Modular Arithmetic.
We will cover a bit on primes and introduce the algorithm of nding
the Greatest common divisor.
Integer Division
Integer Division
When one integer is divided by a second, nonzero integer, the
quotient may or may not be an integer.
Foe example 12=4 = 3 is an integer, while 11=4 = 2:75 is not integer.
These examples lead to the following denition.
Denition (Divisibility)
If a and b are integers with a 6= 0, we say that a divides b if there is an
integer c such that b = ac . When a divides b, we say that a is a factor of
b and that b is a multiple of a. The notation ajb denotes a divides b . We
Integer Division
Integer Division
We can express ajb using quantiers, 9c [ac = b], where the universe
of discourse is the set of all integers.
a) j j
if a b and a c , then a j( b + c );
b) j j
if a b, then a bc for all integers c ;
c) j j j
if a b and b c , then a c .
Integer Division
Proof
First, we give a direct proof of (a). We suppose that ajb and ajc .
Then from the denition of divisibility, it follows that, 9s ; t 2 Z such
that b = as and c = at .
Hence, b + c = as + at = a(s + t ). Therefore, a divides b + c and
thus this establishes part (a) of the theorem.
The proof of the rest of the theorem are left as exercise.
Corollary
j
If a; b and c are integers such that a b and a c , then a mb j j + nc , whenever
m and n are integers.
Proof
This is a perfect example of the existence-and-uniqueness type of
proof.
We must rst prove that the numbers q and r actually exist.
Then we must show that if q 0 and r 0 are two other such numbers,
then q = q 0 and r = r 0 .
The existence of q and r . Let
S = fa bk kj 2 Z; a bk 0g
Proof
If 0 2 S , then b divides a, and we can let q = a=b and r = 0.
If 0 6= S and b 1, we can use the Well-Ordering Principle and we
must rst show that S is nonempty.
If a > 0, then a b:0 2 S . If a < 0, then a b(2a) = a(1 2b) 2 S .
In either case, S 6= ;. By the Well-Ordering Principle, S must have a
smallest member, say r = a bq .
Therefore, a = bq + r ; r 0.
Proof
We now show that r < b . Suppose that r > b . Then
a ( + 1) = a
b q bq b =r b > 0
In this case we would have a b(q + 1) in the set S .
But then a b(q + 1) < a bq , which would contradict the fact that
r = a bq is the smallest member of S .
Proof
Uniqueness of and q r . Suppose there exists integers q; r ; q 0 and r 0
such that
a = bq + r ; 0 r < b jj and a = bq 0 + r 0 ; 0 r 0 < jbj
Then bq + r = bq 0 + r 0 . Assume that r 0 r . From the last equation
we have b(q q 0 ) = r 0 r .
Therefore, b must divide r 0 r and 0 r 0 r r 0 < b.
This is only possible if r 0 r = 0. Hence, r 0 = r and q = q 0 .
Denition
In the equality given in the division algorithm, b is called the divisor, a is
called the dividend, q is called the quotient and r is called the
remainder. This notation is used to express the quotient and remainder.
q = adivb; r mod b
Modular Arithmetic
Modular Arithmetic
In some situations we care only about the remainder of an integer
when it is divided by some specied positive integer.
For instance, when we ask what time it will be (on a 24-hour clock)
50 hours from now, we care only about the remainder when 50 plus
the current hour is divided by 24.
Because we are often interested only in remainder, we have special
notation for them.
We have notation to indicate that two integers have the same
remainder when they are divided by the positive integer m
Modular Arithmetic
Denition
If a and b are integers and m is a positive integer, then a is congruent to
b modulo m if m divides a b. We use notation a b (mod m) to
indicate that a is congruent to b modulo m. If a and b are not
congruent modulo m, then we write a 6 b (mod m).
Modular Arithmetic
The connection between the notations used when working with
remainders is made clear in theorem (7) below.
Theorem
Let a and b be integers, and let m be a positive integer.
Modular Arithmetic
Proof
First we assume that a (mod m) is true. Then by using the
b
Modular Arithmetic
Proof
Conversely, we assume that a mod m = b mod m is true. Then let
Modular Arithmetic
Modular Arithmetic
The notion of congruences has played an important role in the
development of number theory.
The theorem below provides useful way to work with congruences.
Theorem
Let m be a positive integer. The integers a and b are congruent modulo m
Modular Arithmetic
Proof
If a b (mod m), then mj(a b). This means that there is an
integer k such that a b = km, so that a = b + km.
Conversely, if there is an integer k such that a = b + km, then
km = a b.
Modular Arithmetic
Modular Arithmetic
The set of all integers congruent to an integer a modulo m is called
the congruence class of a modulo m.
The theorem below shows how congruences work with respect to
addition and multiplication.
Theorem
Let m be a positive integer. If a b (mod m) and c d (mod m), then
a +c b + d (mod m); and; ac bd (mod m)
Modular Arithmetic
Proof
Because a b (mod m) and c d (mod m).
Then 9s ; t 2 Z such that a = b + sm and c = d + tm.
Hence
a + c = (b + d ) + (s + t )m =) a + c b + d (mod m)
ac = (b + sm )(d + tm ) = bd + (bt + ds )m + stm
2
Modular Arithmetic
Corollary
Let m be a positive integer, and let a and b be integers. Then
Applications of Congruences
Applications of Congruences
Number theory has applications to a wide range of areas.
In this section we will get introduced to three applications of
congruences such as:
1 The use of congruence to assign memory locations to computer les.
2 The generation of pseudo-random numbers and
3 Cryptosystems based on modular arithmetic.
Applications of Congruences
Hashing Functions
The central computer at an insurance company maintains records for
each of its customers.
How can memory locations be assigned so that customers records can
be retrieved quickly?
The solution to this problem is to use a suitably chosen Hashing
function.
Applications of Congruences
Hashing Functions
For instance, customer records are often identied using the social
security number of the customer as the key.
A hashing function h assigns memory locations h(k ) to the record
that has k as its key.
The widely applied hashing function is dened hereunder:
( ) = k mod m
h k
Applications of Congruences
Hashing Functions
Hashing function should be easily evaluated so that les can be
quickly located.
The hashing function h(k ) = k mod m meets this requirement.
To nd h(k ), we need only compute the remainder when k is divided
by m.
Furthermore, the hashing function should be onto, so that all
memory locations are possible.
The function h(k ) = k mod m also satises this property.
Applications of Congruences
Hashing Functions
For example, when m = 111, the record of the customer with social
security number 064212848 is assigned to memory location 14,
because
h (064212848) = 064212848 mod 111 = 14
Applications of Congruences
Hashing Functions
One way to resolve a collision is to assign the rst free location
following the occupied memory location assigned by hashing function.
For instance, consider a customer with social security number
107405723. We would like assign this to a memory location using
hashing function.
That is, h(107405723) = 107405723 mod 111 = 14.
But this location is already occupied(by the le of customer with SSN
064212848).
However, memory location 15, the rst location following memory
location 14 is free, so we assign it there.
Applications of Congruences
Pseudo-random Numbers
Randomly chosen numbers are often needed for computer simulations.
Dierent methods have been devised for generating numbers that
have properties of randomly chosen numbers.
Numbers generated by systematic methods are not truly random, they
are called Pseudo-random numbers.
The most commonly used procedure for generating pseudo-random
numbers is the Linear Congruential method.
Applications of Congruences
Pseudo-random Numbers
We choose four integers: The modulus m, multiplier a, increment c
and seed x0 , with 2 a < m; 0 c < m and 0 x0 < m.
We generate a sequence of pseudorandom numbers fxn g, with
0 xn < m for all n, by successively using the congruence.
xn+1 = (axn + c ) mod m
Applications of Congruences
Pseudo-random Numbers
Many computer experiments require the generation of pseudo-random
numbers between 0 and 1.
To generate such numbers, we divide numbers generated with a linear
congruential generator by the modulus; that is, we use the numbers
xn =m .
Applications of Congruences
Pseudo-random Numbers
Applications of Congruences
Pseudo-random Numbers
Continuation from above
x7 = 7x6 + 4 mod 9 = 7 0 + 4 mod 9 = 4 mod 9 = 4
x8 = 7x7 + 4 mod 9 = 7 4 + 4 mod 9 = 32 mod 9 = 5
x9 = 7x8 + 4 mod 9 = 7 5 + 4 mod 9 = 39 mod 9 = 3
Because x9 = x0 and because each term depends only on the previous
term, this sequence is generated.
That is the Pseudo-random numbers generated are:
3; 7; 8; 6; 1; 2; 0; 4; 5; 3; 7; 8; 6; 1; 2; 0; 4; 5; 3; : : : .
Applications of Congruences
Pseudo-random Numbers
This sequence contains nine(9) dierent numbers before repeating.
Often, a Linear congruential generator with increment c = 0 is used.
Such a generator is called a Pure multiplicative generator.
For example, the pure multiplicative generator with modulus 2311 1
and multiplier 75 = 16; 807 is widely used.
With these values, it can be shown that 231 2 numbers are
generated before repetition.
Applications of Congruences
Cryptology
Congruence have numerous applications to discrete mathematics and
computer science.
One of the most important application of congruences involves
Cryptology, which is the study of secret messages.
One of the earliest known uses of cryptology was by Julius Caesar.
He made messages secret by shifting each letter three letters forward
in the alphabet(sending the last three letters of the alphabet to the
rst three letters).
Applications of Congruences
Cryptology
For instance, using this scheme, the letter B is send to E and the
letter X is send to A.
This is an example of Encryption, that is, the process of making a
message secret.
To express Caesar's encryption process mathematically, rst replace
each letter by an integer from 0 to 25 based on its position in the
alphabet.
For example replace A by 0, K by 10 and Z by 25.
Applications of Congruences
Cryptology
Caesar's encryption method can be represented by the function f that
assigns to the nonnegative integer p; p 25, the integer
f (p ) 2 f0; : : : ; 25g with
f (p ) = (p + 3) mod 26
In the encrypted version of the message, the letter represented by p is
then replaced with the letter represented by (p + 3) mod 26
Applications of Congruences
Cryptology: Example
Example: What is the secret message produced from message
\MEET YOU IN THE PARK"using the Caesar cipher?
Solution: First replace the letters in the message with numbers. This
produces 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f (p ) = (p + 3) mod 26.
This gives 15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13.
Translating this back to letters produces the encrypted message
PHHW BRX LQ WKH SDUN.
Applications of Congruences
Encryption
To recover the original message from a secret message encrypted by
Caesar cipher, the function f 1 , the inverse of f is used.
Note that the function f 1 sends an integer p from f0; : : : ; 25g to
f
1
(p ) = (p 3) mod 26.
In other words, to nd the original message, each letter is shifted
back three letters in the alphabet, with the rst three letters send to
the last three letters of the alphabet.
The process of determining the original message from the encrypted
message is called Decryption.
Applications of Congruences
Encryption
There are various ways to generalize the Caesar cipher.
For example, instead of shifting each letter by 3, we can shift each
letter by an integer k , so that
f (p ) = (p + k ) mod 26
Such a cipher is called Shift cipher.
Note that decryption can be carried out using the function
f
1
(p ) = (p k ) mod 26
Applications of Congruences
Encryption
Obviously Caesar's method and shift cipher do not provide a high
level of security.
There are various ways to enhance security in this method.
One approach that slightly enhances the security is to use a function
of the form
f (p ) = (ap + b ) mod 26
where a and b are integers, chosen such that f is bijection.
Applications of Congruences
Encryption
Such a mapping is called ane transformation.
This provides a number of possible encryption systems.
Example: Encrypt the message in the example above using the
function f (p ) = (7p + 3) mod 26.
Primes
Primes
Every positive integer greater than 1 is divisible by at least two
integers.
Positive integers that have exactly two dierent positive integer
factors are called Primes.
Denition
A positive integer p greater than 1 is called prime if the only positive
factors of p are 1 and p . A positive integer that is greater than 1 and is
not prime is called Composite.
Remark: The integer n is composite if and only if there exists an
integer a such that ajn and 1 < a < n.
Primes
Primes
The primes are the building blocks of positive integers, as the
Fundamental Theorem of Arithmetic below shows
Theorem (The Fundamental Theorem of Arithmetic)
Every positive integer greater than 1 can be written uniquely as a prime or
as the product of two or more primes where the prime factors are written
Primes
Question: Find the prime factorizations of 100, 641, 999 and 1024.
The following theorem below gives the procedures on how to show
that a given integer is a prime or not.
Primes
Theorem
p
If n is a composite integer, then n has a prime divisor less than or equal to
n.
Proof
Let n be a composite integer. Then by denition of composite integer
there is a positive integer factor a with 1 < a < n such that n = ab
and b is a positive integer greater than 1.
Required to show
p p
that a np_ bp n. Suppose that
p n ^b >
p n , then ab > n = n , which is contradiction.
p p
a > n:
Consequently, a n _ b n
Primes
Proof
Because both
p a and b are divisors of n, then n has positive divisor not
exceeding n.
This divisor is either a prime or by the Fundamental Theorem of
Arithmetic, has a prime divisor less than itself.
p
In either case, n has a prime divisor less than or equal to n.
Question: Show that 101 is a prime integer.
Primes
Primes
Let us now discuss the procedures for nding the prime factorization
of every integers under the question.
Consider the problem of nding the prime factorization of an integer
n.
Primes
Primes
Otherwise, if a prime p is found continue by factoring n=p .
Note that n=p has no prime factors less than p.
Again, if n=p has no prime factor greater than or equal to p and not
exceeding its square root, then it is a prime.
Otherwise, if it has a prime factor q , continue by factoring n=(pq ).
This procedure is continued until the factorization has been reduced
to a prime.
Primes
Primes
Question: Find the prime factorization of 7007.
Solution: First perform the division of 7007 by successive primes,
starting with the least prime 2.
However, none of the primes 2,3, and 5 divides 7007. But 7 does
divide 7007 with 7007=7 = 1001.
Next, divide 1001 by successive primes beginning with 7, and it is
immediately noted that 7 does divide 1007 and it is 1001=7 = 143.
Primes
Primes
The process continue by dividing 143 by successive primes starting
with 7.
But 7 - 143, however 11 does divide 143 and thus 143=11 = 13.
Since 13 is a prime then the process is complete and it follows that
the prime factorization of 7007 is 72 11 13.
The gcd
The largest integer that divides both of two integers is called the
greatest common divisor of these integers.
Denition
Let a and b be integers not zero. The largest integer d such that d ja and
d jb is called the gcd of a and b . The greatest common divisor of a and b
The gcd
Example 2: What is the gcd(17 22)? ;
Denition
The integers a1 ; a2 ; : : : ; an are pairwise relatively prime if gcd(ai ; aj ) = 1
whenever 1 i < j n.
Prime factorization
Suppose that the prime factorization of the integers a and b, neither
equal to zero, are
a = p1a 1
;p
a2 an
2 ; : : : ; pn and b = p1b 1
;p
b2 bn
2 ; : : : ; pn
(
gcd a; b ) = p1min(a b
1; 1)
:p
2
min(a b
2; 2)
: : : : :pn
min(an bn )
;
Example
Example 4: Find the gcd(120 500). ;
500 = 2 :5 .2 3
Thus the
gcd(120; 500) = 2min(3 2) :3min(1 0) :5min(1 3) = 22 :30 :51 = 20
; ; ;
The lcm
Denition
The least common multiple of the positive integers a and b is the smallest
positive integer that is divisible by both a and b. The least common
multiple of a and b is denoted by lcm(a; b).
lcm(a; b) = p1max(a b
1; 1)
:p
2
max(a b
2; 2) max(an bn )
: : : : :pn
;
Theorem
Let a and b be nonzero integers. Then there exist integers r and s such
that
(
gcd a; b ) = ar + bs
Furthermore, the greatest common divisor of a and b is unique.
Proof
Let
S = fam + bnjm; n 2 Z; am + bn > 0g
Clearly, the set S is nonempty; hence, by the Well-Ordering
Principle, S must have a smallest member, say d = ar + bs .
Proof
Write a = dq + r 0 where 0 r 0 < d . If r 0 > 0 then
r
0=a dq
= a (ar + bs )q
= a arq bsq
= a(1 rq ) + b( sq )
which is in S .
But this would contradict the fact that d is the smallest member of S .
Hence r 0 = 0 and d divides a.
A similar argument shows that d divides b. Therefore, d is a common
divisor of a and b.
Proof
Suppose that d 0 is another common divisor of a and b and we want
to show that d 0 jd .
If we let a = d 0 h and b = d 0 k then
d = ar + bs = d 0 hr + d 0 ks = d 0 (hr + ks )
So d 0 must divide d and hence d must be the unique greatest
common divisor of a and b.
Theorem
Let a and b be nonzero integers. Then a and b are relatively prime if and
Proof
Let a and b be relatively prime. Then the gcd(a; b) = 1.
By the theorem above there exists r ; s 2 Z such that ar + bs = 1.
Conversely, suppose that ar + bs = 1 for some pair of integers r and
s , and let d = gcd(a; b ).
Theorem
Let a; b; c 2 Z with a 6= 0 j
. If a bc and a and b are relatively prime, then
j
a c.
Proof
Since a and b are relatively prime, then 9r ; s 2 Z such that
ar + bs = 1.
Thus, c = acr + bcs . Since aja and by the hypothesis ajbc , then it is
obviously that aj(acr + bcs ) and hence ajc .
Euclidean Algorithm
Euclidean Algorithm
The method described earlier for computing the gcd of two integers,
using prime factorizations of these integers, is inecient.
The reason is that, it is time consuming to nd prime factorizations.
We are interested in a more ecient method of nding the gcd, called
the Euclidean Algorithm.
Before describing the Euclidean Algorithm, we would like rst to show
how it is used to nd gcd(91; 287).
Euclidean Algorithm
Euclidean Algorithm
First, divide 287, the larger of the two integers, by 91, the smaller, to
obtain
287 = 91 3 + 14
Any divisor of 91 and 287 must also be a divisor of 287 91 3 = 14.
Also, any divisor of 91 and 14 must be a divisor of 287 = 91 3 + 14.
Hence, the gcd of 91 and 287 is the same as the gcd of 91 and 14.
Euclidean Algorithm
Euclidean Algorithm
This means that the problem of nding the gcd(91; 287) has been
reduced to the problem of nding the gcd(91; 14).
Next, divide 91 by 14 to obtain 91 = 14 6 + 7.
With the same reasons, gcd(91; 14) = gcd(14; 7).
Continue by dividing 14 by 7, to obtain 14 = 7 2 + 0.
Because 7 divides 14, it follows that gcd(14; 7) = 7
Euclidean Algorithm
Euclidean Algorithm
Furthermore, because gcd(287; 91) = gcd(91; 14) = gcd(14; 7) = 7,
the original problem has been solved.
We now describe how the Euclidean algorithm works in generality.
We will use successive division to reduce the problem of nding the
greatest common divisor of two positive integers to the same problem
with smaller integers, until one of the integer is zero.
The Euclidean Algorithm is based on the following result about
greatest common divisors and the division algorithm.
Euclidean Algorithm
Algorithm
Lemma
Let a = bq + r , where a; b; q and r are integers. Then
gcd(a; b ) = gcd(b; r ).
Proof: It is enough to show that the common divisors for a and b are
the same as the common divisors for b and r .
Now suppose that d ja and d jb. Then it follows that d j(a bq ),
which implies that d jr .
Hence, any common divisor of a and b is also a common divisor of b
and r .
Euclidean Algorithm
Algorithm
Likewise, suppose that d jb and d jr . Then d j(bq + r ), which implies
that d ja.
Hence, any common divisor of b and r is also a common divisor of a
and b.
Consequently gcd(a; b) = gcd(b; r ).
Euclidean Algorithm
rn 1 = rn qn
Euclidean Algorithm
Euclidean Algorithm
Euclidean Algorithm
Euclidean Algorithm
Euclidean Algorithm
Euclidean Algorithm
If we work backward through the above sequence of equations, we
can also obtain numbers r and s such that 945r + 2415s = 105.
Observe that
105 = 525 + ( 1) 420 = 525 + ( 1) [945 + ( 1) 525] = 2 525
So r = 5 and s = 2. Notice that r and s are not unique, since
r = 41 and s = 16 would also work.
Euclidean Algorithm
Euclidean Algorithm
To compute gcd(a; b) = d , we are using repeated divisions to obtain
a decreasing sequence of positive integers
r1 > r2 > : : : > rn =d
That is
= aq1 + r1 ;
b 0 r1 < a
a = r1 q2 + r2 ; 0 r2 < r1
.
r1 = r2 q3 + r3 0 r3 < r2 ..
rn 2 = rn 1 qn 1 + rn ; 0 rn < rn 1
rn 1 = rn qn
Euclidean Algorithm
Euclidean Algorithm
To nd r and s such that ar + bs = d , we begin with this last
equation and substitute results obtained from the previous equations:
d = rn
= rn 2 rn 1 qn
rn 2 [ 3 qn 1 rn 2 ]
qn rn
qn rn 3 + [1 + qn qn 1 ]rn 2
..
.
= ar + bs
The algorithm that we have just used to nd the greatest common
divisor d of two integers a and b and then write d as the linear
combination of a and b is known as the Euclidean Algorithm.
MBIGILI Lusungu Julius () MSS211: Abstract Algebra November 15, 2016 79 / 79