0% found this document useful (0 votes)
116 views11 pages

Proof: We Will Give A Direct Proof of (I) - Suppose That A - B and A - C. Then, From The

This document discusses divisibility, modular arithmetic, and representations of integers. It begins by defining divisibility and providing examples. It then introduces modular arithmetic, including congruences and operations like addition and multiplication modulo m. Key theorems are presented, such as properties of congruences being preserved under addition and multiplication. The document concludes by discussing representations of integers in different number bases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views11 pages

Proof: We Will Give A Direct Proof of (I) - Suppose That A - B and A - C. Then, From The

This document discusses divisibility, modular arithmetic, and representations of integers. It begins by defining divisibility and providing examples. It then introduces modular arithmetic, including congruences and operations like addition and multiplication modulo m. Key theorems are presented, such as properties of congruences being preserved under addition and multiplication. The document concludes by discussing representations of integers in different number bases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Divisibility and Modular Arithmetic

Division
DEFINITION 1 If a and b are integers with a ≠ 0, we say that a divides b if there
𝑏
is an integer c such that b= ac, or equivalently, if is an integer. When a divides
𝑎
b we say that a is a factor or divisor of b, and that b is a multiple of a. The notation
a | b denotes that a divides b. We write 𝑎 ∤ b when a does not divide b.
EXAMPLE 1 Determine whether 3 | 7 and whether 3 | 12.

Solution: We see that 3∤7, because 7/3 is not an integer. On the other hand, 3 | 12
because 12/3 = 4.
THEOREM 1 Let a, b, and c be integers, where a ≠ 0. Then

(i) if a | b and a | c, then a | (b + c);

(ii) if a | b, then a | bc for all integers c;

(iii) if a | b and b | c, then a | c.


Proof: We will give a direct proof of (i). Suppose that a | b and a | c. Then, from the
definition of divisibility, it follows that there are integers s and t with b = as and c
= at. Hence, b + c = as + at = a(s + t).
COROLLARY 1 If a, b, and c are integers, where a ≠ 0, such that a | b and a | c,
then a | mb + nc whenever m and n are integers.
Proof: We will give a direct proof. By part (ii) of Theorem 1 we see that a | mb and
a | nc whenever m and n are integers. By part (i) of Theorem 1 it follows that
a | mb + nc.
The Division Algorithm
When an integer is divided by a positive integer, there is a quotient and a remainder,
as the division algorithm shows.
THEOREM 2 THE DIVISION ALGORITHM Let a be an integer and d a
positive integer. Then there are unique integers q and r, with 0 ≤ r < d, such that
a = dq + r.
DEFINITION 2 In the equality given in the division algorithm, d 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 = a div d, r = a mod d.
Remark: Note that both a div d and a mod d for a fixed d are functions on the set
of integers. Furthermore, when a is an integer and d is a positive integer, we have
a div d = ⌊a/d⌋ and a mod d =a − d⌊a/d⌋.
Examples 2 and 3 illustrate the division algorithm.
EXAMPLE 2 What are the quotient and remainder when 101 is divided by 11?
Solution: We have 101=11·9+2. Hence, the quotient when 101 is divided by 11 is
9 = 101 div 11, and the remainder is 2 = 101 mod 11.
EXAMPLE 3 What are the quotient and remainder when −11 is divided by 3?
Solution: We have −11 = 3(−4) + 1.
Hence, the quotient when −11 is divided by 3 is −4 = −11 div 3, and the
remainder is 1 = −11 mod 3.
Note that the remainder cannot be negative. Consequently, the remainder is not −2,
even though
−11 = 3(−3) − 2,
because r = −2 does not satisfy 0 ≤ r < 3.
Note that the integer a is divisible by the integer d if and only if the remainder is
zero when a is divided by d.
Modular Arithmetic
DEFINITION 3 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 the notation a ≡ b (mod m) to
indicate that a is congruent to b modulo m. We say that a ≡ b (mod m) is a
congruence and that m is its modulus (plural moduli). If a and b are not congruent
modulo m, we write a≢ b (mod m).
Although both notations a ≡ b (mod m) and a mod m = b include “mod,” they
represent fundamentally different concepts. The first represents a relation on the set
of integers, whereas the second represents a function. However, the relation
a ≡ b (mod m) and the mod m function are closely related, as described in Theorem
3.
THEOREM 3 Let a and b be integers, and let m be a positive integer. Then
a ≡ b (mod m) if and only if a mod m = b mod m.
Theorem 3 also says that a ≡ b (mod m) if and only if a and b have the same
remainder when divided by m.
EXAMPLE 4 Determine whether 17 is congruent to 5 modulo 6 and whether 24
and 14 are congruent modulo 6.
Solution: Because 6 divides 17 − 5 = 12, we see that 17 ≡ 5 (mod 6). However,
because 24 − 14 = 10 is not divisible by 6, we see that 24 ≢ 14 (mod 6).
THEOREM 4 Let m be a positive integer. The integers a and b are congruent
modulo m if and only if there is an integer k such that a = b + km.
Proof: If a ≡ b (mod m), by the definition of congruence (Definition 3), we know
that m | (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. Hence, m divides a − b, so that a ≡ b (mod m).
The set of all integers congruent to an integer a modulo m is called the congruence
class of a modulo m. We will show that there are m pairwise disjoint equivalence
classes modulo m and that the union of these equivalence classes is the set of
integers.
Theorem 5 shows that additions and multiplications preserve congruences.
THEOREM 5 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).
Proof: We use a direct proof. Because a ≡ b (mod m) and c ≡ d (mod m), by
Theorem 4 there are integers s and t with b = a + sm and d = c + tm. Hence,
b + d = (a + sm) + (c + tm) = (a + c) + m(s + t)
and
bd = (a + sm)(c + tm) = ac + m(at + cs + stm).

Hence, a + c ≡ b + d (mod m) and ac ≡ bd (mod m).


EXAMPLE 5 Because 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5), it follows
from Theorem 5 that 18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5)
and that
77=7·11≡2·1=2( mod 5).
We must be careful working with congruences. Some properties we may expect to
be true are not valid. For example, if ac ≡ bc (mod m), the congruence a ≡ b (mod
m) may be false. Similarly, if a ≡ b (mod m) and c ≡ d (mod m), the congruence ac
≡ bd (mod m) may be false.
COROLLARY 2 Let m be a positive integer and let a and b be integers. Then
(a + b) mod m = ((a mod m) + (b mod m)) mod m
and
ab mod m = ((a mod m)(b mod m)) mod m.
Proof: By the definitions of mod m and of congruence modulo m, we know that
a ≡ (a mod m) (mod m) and b ≡ (b mod m) (mod m). Hence, Theorem 5 tells us that
a + b ≡ (a mod m) + (b mod m) (mod m)
and
ab ≡ (a mod m)(b mod m) (mod m).

The equalities in this corollary follow from these last two congruences by Theorem
3.
Arithmetic Modulo m
We can define arithmetic operations on Zm , the set of nonnegative integers less than
m, that is, the set {0, 1, . . . , m − 1}. In particular, we define addition of these
integers, denoted by +m by

a +m b = (a + b) mod m,

where the addition on the right-hand side of this equation is the ordinary addition of
integers, and we define multiplication of these integers, denoted by ·m by

a ·m b = (a · b) mod m,

where the multiplication on the right-hand side of this equation is the ordinary
multiplication of integers. The operations +m and ·m are called addition and
multiplication modulo m and when we use these operations, we are said to be doing
arithmetic modulo m.
EXAMPLE 6 Use the definition of addition and multiplication in Zm
to find 7 +11 9 and 7 ·11 9.
Solution: Using the definition of addition modulo 11, we find that
7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5,
and
7 ·11 9 = (7 · 9) mod 11 = 63 mod 11 = 8.
Hence 7 +11 9 =5 and 7 ·119 = 8.
The operations +m and ·m satisfy many of the same properties of ordinary
addition and multiplication of integers. In particular, they satisfy these properties:
Closure If a and b belong to Zm, then a +m b and a ·m b belong to Zm.
Associativity If a, b, and c belong to Zm, then (a +m b) +m c = a +m (b +m c) and
(a ·m b) ·m c = a ·m (b ·m c).
Commutativity If a and b belong to Zm, then a +m b = b +m a and a ·m b = b ·m a.
Identity elements The elements 0 and 1 are identity elements for addition and
multiplication modulo m, respectively. That is, if a belongs to Zm, then a +m 0 = 0
+m a = a and a ·m 1 = 1 ·m a = a.
Additive inverses If a≠0 belongs to Zm, then m − a is an additive inverse of a
modulo m and 0 is its own additive inverse. That is a +m (m − a) = 0 and 0 +m 0 =
0.
Distributivity If a, b, and c belong to Zm, then a ·m (b +m c) = (a ·m b) +m (a ·m c)
and (a +m b) ·m c = (a ·m c) +m (b ·m c).

These properties follow from the properties we have developed for congruences
and remainders modulo m, together with the properties of integers. Note that we
have listed the property that every element of Zm has an additive inverse, but no
analogous property for multiplicative inverses has been included. This is because
multiplicative inverses do not always exists modulo m. For instance, there is no
multiplicative inverse of 2 modulo 6.
Remark: Because Zm with the operations of addition and multiplication modulo
m satisfies the properties listed, Zm with modular addition is said to be a
commutative group and Zm with both of these operations is said to be a
commutative ring. Note that the set of integers with ordinary addition and
multiplication also forms a commutative ring. Groups and rings are studied in
courses that cover abstract algebra.
Representations of Integers
THEOREM 1 Let b be an integer greater than 1. Then if n is a positive
integer, it can be expressed uniquely in the form

n = ak bk + ak−1bk−1 + · · · + a1b + a0,

where k is a nonnegative integer, a0, a1, . . . , ak are nonnegative integers less than b,
and ak ≠ 0.
The representation of n given in Theorem 1 is called the base b expansion of n.
The base b expansion of n is denoted by (ak ak−1 . . . a1a0)b. For instance, (245)8
represents 2 · 82 + 4 · 8 + 5 = 165. Typically, the subscript 10 is omitted for base 10
expansions of integers because base 10, or decimal expansions, are commonly used
to represent integers.
BINARY EXPANSIONS Choosing 2 as the base gives binary expansions of
integers. In binary notation each digit is either a 0 or a 1. In other words, the binary
expansion of an integer is just a bit string. Binary expansions (and related expansions
that are variants of binary expansions) are used by computers to represent and do
arithmetic with integers.
EXAMPLE 1 What is the decimal expansion of the integer that has (1 0101 1111)2
as its binary expansion?
Solution: We
have


(101011111)2 =1·28 + 0·27+1·26+ 0·25+1·24
+ 1·23+1·22+1·21+1·20 =351.

OCTAL AND HEXADECIMAL EXPANSIONS Among the most important bases


in computer science are base 2, base 8, and base 16. Base 8 expansions are called
octal expansions and base 16 expansions are hexadecimal expansions.
EXAMPLE 2 What is the decimal expansion of the number with octal
expansion (7016)8?
Solution: Using the definition of a base b expansion with b = 8 tells us that

(7016)8 =7·83+0·82+1·8+6=3598.
Sixteen different digits are required for hexadecimal expansions. Usually, the
hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, where
the letters A through F represent the digits corresponding to the numbers 10 through
15 (in decimal notation).
EXAMPLE 3 What is the decimal expansion of the number with hexadecimal
expansion (2AE0B)16?
Solution: Using the definition of a base b expansion with b = 16 tells us that
(2AE0B)16 = 2 · 164 + 10 · 163 + 14 · 162 + 0 · 16 + 11 = 175627.
Each hexadecimal digit can be represented using four bits. For instance, we see
that (1110 0101)2 = (E5)16 because (1110)2 = (E)16 and (0101)2 = (5)16. Bytes, which
are bit strings of length eight, can be represented by two hexadecimal digits.
BASE CONVERSION We will now describe an algorithm for constructing the
base b expansion of an integer n. First, divide n by b to obtain a quotient and
remainder, that is,
n = bq0 + a0, 0 ≤ a0 < b.
The remainder, a0, is the rightmost digit in the base b expansion of n. Next, divide
q0 by b to obtain

q0 = bq1 + a1, 0 ≤ a1 < b.

We see that a1 is the second digit from the right in the base b expansion of n.
Continue this process, successively dividing the quotients by b, obtaining additional
base b digits as the remainders. This process terminates when we obtain a quotient
equal to zero. It produces the base b digits of n from the right to the left.
EXAMPLE 4 Find the octal expansion of (12345)10.
Solution: First, divide 12345 by 8 to obtain
12345 = 8 · 1543 + 1.
Successively dividing quotients by 8 gives
1543=8·192+7,
192 =8·24+0,

24 =8·3+0,

3 =8·0+3.

The successive remainders that we have found, 1, 7, 0, 0, and 3, are the digits
from the right to the left of 12345 in base 8. Hence,
(12345)10 = (30071)8.
CONVERSION BETWEEN BINARY, OCTAL, AND
HEXADECIMAL EXPANSIONS

Conversion between binary and octal and between binary and hexadecimal
expansions is extremely easy because each octal digit corresponds to a block of three
binary digits and each hexadecimal digit corresponds to a block of four binary digits,
with these correspondences shown in Table 1 without initial 0s shown. (We leave it
as Exercises 13–16 to show that this is the case.) This conversion is illustrated in
Example 5.
EXAMPLE 5 Find the octal and hexadecimal expansions of (11 1110 1011
1100)2 and the binary expansions of (765)8 and (A8D)16.
Solution: To convert (11 1110 1011 1100)2 into octal notation we group the
binary digits into blocks of three, adding initial zeros at the start of the leftmost block
if necessary. These blocks, from left to right, are 011, 111, 010, 111, and 100,
corresponding to 3, 7, 2, 7, and 4, respectively. Consequently, (11 1110 1011 1100) 2
= (37274)8. To convert (11 1110 1011 1100)2 into hexadecimal notation we group
the binary digits into blocks of four, adding initial zeros at the start of the leftmost
block if necessary. These blocks, from left to right, are 0011, 1110, 1011, and 1100,
corresponding to the hexadecimal digits 3, E, B, and C, respectively. Consequently,
(11 1110 1011 1100)2 = (3EBC)16.
To convert (765)8 into binary notation, we replace each octal digit by a block of
three binary digits. These blocks are 111, 110, and 101. Hence, (765)8 = (1 1111
0101)2. To convert (A8D)16 into binary notation, we replace each hexadecimal digit
by a block of four binary digits. These blocks are 1010, 1000, and 1101. Hence,
(A8D) 16 = (1010 1000 1101) 2.
Algorithms for Integer Operations
The algorithms for performing operations with integers using their binary
expansions are extremely important in computer arithmetic. We will describe
algorithms for the addition and the multiplication of two integers expressed in binary
notation. We will also analyze the computational complexity of these algorithms, in
terms of the actual number of bit operations used. Throughout this discussion,
suppose that the binary expansions of a and b are

a = (an−1an−2 . . . a1a0)2, b = (bn−1bn−2 . . . b1b0)2,

so that a and b each have n bits (putting bits equal to 0 at the beginning of one of
these expansions if necessary).
We will measure the complexity of algorithms for integer arithmetic in terms of
the number of bits in these numbers.
ADDITION ALGORITHM Consider the problem of adding two integers in binary
notation. A procedure to perform addition can be based on the usual method for
adding numbers with pencil and paper. This method proceeds by adding pairs of
binary digits together with carries, when they occur, to compute the sum of two
integers. This procedure will now be specified in detail.
To add a and b, first add their rightmost bits. This gives

a0 + b0 = c0 · 2 + s0,

where s0 is the rightmost bit in the binary expansion of a + b and c0 is the carry,
which is either 0 or 1. Then add the next pair of bits and the carry,

a1 + b1 + c0 = c1 · 2 + s1,

where s1 is the next bit (from the right) in the binary expansion of a + b, and c1 is the
carry. Continue this process, adding the corresponding bits in the two binary
expansions and the carry, to determine the next bit from the right in the binary
expansion of a + b. At the last stage, add an−1, bn−1, and cn−2 to obtain cn−1 · 2 + sn−1.
The leading bit of the sum is sn = cn−1. This procedure produces the binary expansion
of the sum, namely, a + b = (snsn−1sn−2 . . . s1s0)2.
EXAMPLE 6 Add a = (1110)2 and b = (1011)2.

Solution: Following the procedure specified in the algorithm, first note that

a0 + b0 = 0 + 1 = 0 · 2 + 1,

so that c0 = 0 and s0 = 1. Then, because

a1 + b1 + c0 = 1 + 1 + 0 = 1 · 2 + 0,

it follows that c1 = 1 and s1 = 0. Continuing,


a2 + b2 + c1 = 1 + 0 + 1 = 1 · 2 + 0,
so that c2 = 1 and s2 = 0. Finally, because
a3 + b3 + c2 = 1 + 1 + 1 = 1 · 2 + 1,

follows that c3 = 1 and s3 = 1. This means that s4 = c3 = 1. Therefore, s = a + b = (1


1001)2.
MULTIPLICATION ALGORITHM Next, consider the multiplication of two n-
bit integers a and b. The conventional algorithm (used when multiplying with pencil
and paper) works as follows. Using the distributive law, we see that

ab = a(b020 + b121 + · · · + bn−12n−1)

= a(b020) + a(b121) + · · · + a(bn−12n−1).

We can compute ab using this equation. We first note that abj = a if bj = 1 and abj
= 0 if bj = 0. Each time we multiply a term by 2, we shift its binary expansion one
place to the left and add a zero at the tail end of the expansion. Consequently, we
can obtain (abj )2j by shifting the binary expansion of abj j places to the left, adding
j zero bits at the tail end of this binary expansion. Finally, we obtain ab by adding
the n integers abj 2j , j = 0, 1, 2, . . . , n − 1.

EXAMPLE 7 Find the product of a = (110)2 and b = (101)2.

Solution: First note that

ab0 · 20 = (110)2 · 1 · 20 = (110)2,

ab1 · 21 = (110)2 · 0 · 21 = (0000)2,

and

ab2 · 22 = (110)2 · 1 · 22 = (11000)2.


To find the product, add (110)2, (0000)2, and (11000)2. Carrying out these additions
shows that ab = (1 1110)2.
ALGORITHM FOR div AND mod Given integers a and d, d > 0, we can find q
= a div d and r = a mod d . In this brute-force algorithm, when a is positive we
subtract d from a as many times as necessary until what is left is less than d . The
number of times we perform this subtraction is the quotient and what is left over
after all these subtractions is the remainder. Algorithm also covers the case where
a is negative. This algorithm finds the quotient q and remainder r when |a| is
divided by d. Then, when a < 0 and r > 0, it uses these to find the quotient −(q + 1)
and remainder d − r when a is divided by d.
ALGORITHM Computing div and mod.
procedure division algorithm(a: integer, d: positive integer)
q := 0
r := |a|
while
r≥d
r := r
−dq
:= q +
1

if a < 0 and r
> 0 then r
:= d − r
q := −(q + 1)

return (q, r) {q = a div d is the quotient, r = a mod d is the


remainder}

You might also like