Ch1 Ch2 Basic Structure, Sets - Functions
Ch1 Ch2 Basic Structure, Sets - Functions
DEFINITION 1 . A set is an unordered collection of objects, called elements or members of the set. A
set is said to contain its elements. We write a ∈ A to denote that a is an element of the set A. The
notation a ∉ A denotes that a is not an element of the set A.
EXAMPLE 1. The set V of all vowels in the English alphabet can be written as V = {a, e, i, o, u}.
EXAMPLE 2. The set O of odd positive integers less than 10 can be expressed by O = {1, 3, 5, 7,
9}.These sets, each denoted using a boldface letter, play an important role in discrete mathematics:
N = {0, 1, 2, 3, . . .}, the set of natural numbers.
Z = {. . . ,−2,−1, 0, 1, 2, . . .}, the set of integers.
Z+ = {1, 2, 3, . . .}, the set of positive integers.
Q = {p/q | p ∈ Z, q ∈ Z, and q ≠ 0}, the set of rational numbers.
R, the set of real numbers.
R+, the set of positive real numbers.
C, the set of complex numbers.
Two sets are equal if and only if they have the same elements. Therefore, if A and B are sets,then A and
B are equal if and only if ∀x(x ∈ A ↔ x ∈ B).We write A = B if A and B are equal sets.Venn
Diagrams.
Subsets
It is common to encounter situations where the elements of one set are also the elements of a second set.
We now introduce some terminology and notation to express such relationships between sets.
DEFINITION 3. The set A is a subset of B if and only if every element of A is also an element of B.We
use the notation A ⊆ B to indicate that A is a subset of the set B.
We see that A ⊆ B if and only if the quantification∀x(x ∈ A → x ∈ B) is true.
Note that to show that A is not a subset of B we need only find one element x ∈ A with
x ∉ B. Such an x is a counterexample to the claim that x ∈ A implies x ∈ B.
We have these useful rules for determining whether one set is a subset of another:
Showing that A is a Subset of B To show that A ⊆ B, show that if x belongs to A then x
also belongs to B.
Showing that A is Not a Subset of B . To show that A ⊄ B, find a single x ∈ A such thatx ∉ B.
2
EXAMPLE. What are the truth sets of the predicates P(x), Q(x), and R(x), where the domain is the
set of integers and P(x) is “|x| = 1,” Q(x) is “x2 = 2,” and R(x) is “|x| = x.”
Solution: The truth set of P, {x ∈ Z | |x| = 1}, is the set of integers for which |x| = 1. Because |x| = 1
when x = 1 or x = −1, and for no other integers x, we see that the truth set of P is the set {−1, 1}.
The truth set of Q, {x ∈ Z | x2 = 2}, is the set of integers for which x2 = 2. This is the empty set
because there are no integers x for which x2 = 2.
The truth set of R, {x ∈ Z | |x| = x}, is the set of integers for which |x| = x. Because |x| = x if and only if
x ≥ 0, it follows that the truth set of R is N, the set of nonnegative integers.
Note that ∀x P(x) is true over the domain U if and only if the truth set of P is the set U.
Likewise, ∃x P(x) is true over the domain U if and only if the truth set of P is nonempty
Identity Name
A∩U=A Identity laws
A∪∅=A
A∪U=U Domination laws
A∩∅ = ∅
A∪A=A Idempotent laws
A∩A=A
Á = A Complementation law
A∪B=B∪A Commutative laws
A∩B=B∩A
A ∪ (B ∪ C) = (A ∪ B) ∪ C Associative laws
A ∩ (B ∩ C) = (A ∩ B) ∩ C
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) Distributive laws
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∪ A = A ∩B De Morgan’s laws
A∩ A = A ∪B
A ∪ (A ∩ B) = A Absorption laws
A ∩ (A ∪ B) = A
A ∪ A= U Complement laws
A∩ A=∅
A ∩ B = {x | x ∉ A ∩ B} by definition of complement
= {x | ¬(x ∈ A)∨¬(x ∈ B)} by the first De Morgan law for logical equivalences
= {x | x ∈ A ∨ x ∈ B} by definition of complement
= {x | x ∈ A ∪ B} by definition of union
= A ∪B by meaning of set builder notation.▄
EXAMPLE 2. Let A, B, and C be sets. Use logical equivalences to prove that A ∪( B ∩C) = ( C ∪ B)∩ A
Solution. We have
A ⊕ B = { x ∈ U | (x ∈ A ∧ x ∉ B )∨(x ∈ B ∧x ∉ A) } by definition
= { x ∈ U | (x ∈ A ∧x ∈ B )∨(x ∈ B ∧ x ∈ B ) }. by definition of complement
= (A − B) ⋃ (B − A). by definition symmetric difference. ▄
membership tables
Set identities can also be proved using membership tables
6
To indicate that an element is in a set, a 1 is used; toindicate that an element is not in a set, a 0 is used. (The reader
should note the similarity betweenmembership tables and truth tables.)
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Solution:
2) the subset of all even integers in U, and 3) the subset of integers not exceeding 5 in U?
Solution:
The bit string that represents the set of odd integers in U, namely, {1, 3, 5, 7, 9}, is 10 1010 1010.
The bit string that represents the set {2, 4, 6, 8, 10}, is 01 0101 0101.
The set of all integers in U that do not exceed 5, namely, {1, 2, 3, 4, 5}, is represented by the
String 11 1110 0000. ▄
To find the bit string for the complement of a set from the bitstring for that set, we simply change each 1 to a 0 and
each 0 to 1, because x ∈ A if and only if x ∉ A . Note that this operation corresponds to taking the negation of
each bit when we associate a bit with a truth value—with 1 representing true and 0 representing false.
EXAMPLE 2. We have seen that the bit string for the set {1, 3, 5, 7, 9} (with universal set {1, 2, 3, 4,
5, 6, 7, 8, 9, 10}) is 10 1010 1010.What is the bit string for the complement of this set?
7
Solution: The bit string for the complement of this set is obtained by replacing 0s with 1s and vice versa. This yields
the string 01 0101 0101,which corresponds to the set {2 , 4, 6, 8, 10}.▄
To obtain the bit string for the union and intersection of two sets we perform bitwise Boolean operations on the bit
strings representing the two sets.
EXAMPLE 3. The bit strings for the sets {1, 2, 3, 4, 5} and {1, 3, 5, 7, 9} are 11 1110 0000 and 10 1010 1010,
respectively. Use bit strings to find the union and intersection of these sets.
11 1110 0000 ∨ 10 1010 1010 = 11 1110 1010,which corresponds to the set {1, 2, 3, 4, 5, 7, 9}.
11 1110 0000 ∧ 10 1010 1010 = 10 1010 0000,which corresponds to the set {1, 3, 5}.▄
EXERCISES
1. The symmetric difference of A and B, denoted by A ⊕ B, is the set containing those elements in
either A or B, but not in both A and B.
(1) Find the symmetric difference of {1, 3, 5} and {1, 2, 3}.
(2) Show that A ⊕ B = (A ∪ B) − (A ∩ B).
(3) . Show that A ⊕ B = (A − B) ∪ (B − A).
2. Suppose that the universal set is U ={1, 2, 3, 4,5, 6, 7, 8, 9, 10}. Express each of these sets with bit
strings where the ith bit in the string is 1 if i is in the set and 0 otherwise.
2.3 Functions
Introduction. Definitions and examples of : a function f from a set A to a set B , domain and range
(codomain ) of functions. One-to-One and Onto Functions…….
Some Important Functions (The floor and ceiling functions).
Let x be a real number
8
Example1. These are some values of the floor and ceiling functions:
⌊ 0.5 ⌋ =0, ⌈ 0.5 ⌉=1, ⌊−0.5 ⌋ =−1 , ⌈ −0.5 ⌉=0 , ⌊ 3.1 ⌋ =3 , ⌈ 3.1⌉ =4 , ⌊ 9 ⌋=9 , ⌈ 9 ⌉ =1 ▄
Example. These are some values of the floor and ceiling functions:
⌊ 0.5 ⌋ =0, ⌈ 0.5 ⌉=1, ⌊−0.5 ⌋ =−1 , ⌈ −0.5 ⌉=0 , ⌊ 3.1 ⌋ =3 , ⌈ 3.1⌉ =4 , ⌊ 9 ⌋=9 , ⌈ 9 ⌉ =1 ▄
Directly from the definitions of floor and ceiling we have the following properties.
Properties of the floor and ceiling functions:
(1) ⌊ x ⌋=n if and only if n ≤ x < n+1 or ⌊ x ⌋ ≤ x < ⌊ x ⌋ +1
(2) ⌊ x ⌋=n if and only if x−¿ 1 < n ≤ x or x−¿1 < ⌊ x ⌋ ≤ x
(3) ⌈ x ⌉=n if and only if n−¿ 1 < x ≤ n or ⌈ x ⌉−¿1 < x ≤ ⌈ x ⌉
(4) ⌈ x ⌉=n if and only if x ≤ n < x+1 or x ≤ ⌈ x ⌉ < x+1
(d) ⌊ x+ n ⌋ =⌊ x ⌋+ n
(e) ⌈ x+ n⌉ =⌈ x ⌉ +n
Proof.
(a) Follows from properties (2) ,(4). We will prove (b) –(e).
(b) Assume ⌊−x ⌋=n , then ⌊−x ⌋=n ⟺ −x−¿ 1 < n ≤ −x , by (2). This follows x ≤ −n < x +1. By
we have −n = ⌈ x ⌉ , that is −⌊−x ⌋=⌈ x ⌉ ∧so ⌊−x ⌋=−⌈ x ⌉ .
(c) Similarly to (b).
(d) Suppose that ⌊ x ⌋=m,. By property (1), it follows that m ≤ x <m+ 1.
Adding n to all three quantities m + n ≤ x +n < m+ n + 1.
Using property (1) again, we see that ⌊ x+ n ⌋ = m + n = ⌊ x ⌋ +n .
(e) Similarly to (d). ▄
EXAMPLE .3 Prove that if x is a real number , then
1
⌊ 2 x ⌋=⌊ x ⌋ + ⌊ x+ ⌋
2
Solution. Assume that ⌊ x ⌋=n , then by property (1) we have n ≤ x < n+1 . There is
0≤ε<1, such that x=n+ ε . We consider 3 cases:
1 1 1 1 1
1) 0 ≤ ε < , x + =n+ε + , then ⌊ x+ ⌋ =n because ε < . And
2 2 2 2 2
1
2 x=2 n+2 ε and ⌊ 2 x ⌋=2 n because 2 ε <1. So ⌊ 2 x ⌋=2 n=n+n=⌊ x ⌋ + ⌊ x + ⌋ .
2
1 1 1
2) ε = , then ⌊ x+ ⌋ = ⌊ n+ε + ⌋ =⌊ n+ 1 ⌋ =n+1 , and
2 2 2
1
⌊ 2 x ⌋=⌊ 2n+ 2 ε ⌋ = ⌊ 2n+ 1 ⌋ =2n+ 1. So ⌊ 2 x ⌋=2 n+1=n+n+1=⌊ x ⌋ + ⌊ x + ⌋
2
1 1 1
3) < ε <1 , then ⌊ x+ ⌋ = ⌊ n+ε + ⌋ =⌊ n+ 1 ⌋ =n+1 and
2 2 2
1
⌊ 2 x ⌋=⌊ 2n+ 2 ε ⌋ =2 n+1, So ⌊ 2 x ⌋=2 n+1=n+n+1=⌊ x ⌋ + ⌊ x + ⌋ ▄
2
Exercises
1
1. Give counterexample to prove that the proposition ⌈ 2 x ⌉=⌈ x ⌉ + ⌈ x+ ⌉ is false.
2
10
Answer: x=1.
1
2. Give counterexample to prove that the proposition ⌊ 2 x ⌋=⌊ x ⌋ + ⌊ x− ⌋ is false.
2
Answer: x=1.
1
3. Use Example 3 and (b) in Example 2, to prove ⌈ 2 x ⌉=⌈ x ⌉ + ⌈ x− ⌉ .
2
1
Answer: We have from Example 3, ⌊ 2 x ⌋=⌊ x ⌋ + ⌊ x+ ⌋ for all real numbers. Replacing x by −x
2
1 1
we get ⌊−2 x ⌋ =⌊−x ⌋+ ⌊−x + ⌋ =⌊−x ⌋+ ⌊−( x− ) ⌋ . By the property ⌊−x ⌋=−⌈ x ⌉ ( see (b) in
2 2
1 1
Example 2), we have −⌈ 2 x ⌉=−⌈ x ⌉ −⌈ x− ⌉ and so ⌈ 2 x ⌉=⌈ x ⌉ + ⌈ x+ ⌉ ▄
2 2
4. Prove, without using the property ⌊−x ⌋=−⌈ x ⌉ , that if x is a real m then :
1
⌈ 2 x ⌉=⌈ x ⌉ + ⌈ x− ⌉
2
Answer: Assume that ⌈ x ⌉=n , then by property (3) we have n−¿ 1 < x ≤ n . There is
0≤ε<1, such that x=n−ε . We consider 3 cases:
1 1 1 1 1 1
1) 0 ≤ ε < , x− =n−ε− , then ⌈ x− ⌉=⌈ n−ε− ⌉ =n because ε < .
2 2 2 2 2 2
1
2 x=2 n−2 ε and ⌈ 2 x ⌉=2 n because 2 ε <1. So ⌈ 2 x ⌉=⌈ x ⌉ + ⌈ x− ⌉ .
2
1 1 1
2) ε = , then ⌈ x− ⌉= ⌈ n−ε− ⌉ =⌊ n−1 ⌋ =n−1 ,
2 2 2
1
⌈ 2 x ⌉=⌈ 2 n−2 ε ⌉ = ⌈ 2n−1 ⌉=2 n−1 . So ⌈ 2 x ⌉=2 n−1=n+n−1=⌈ x ⌉ + ⌈ x− ⌉
2
1 1 1
3) < ε <1 , then ⌈ x− ⌉= ⌈ n−ε− ⌉ =⌈ n−1 ⌉ and
2 2 2
1
⌊ 2 x ⌋=⌊ 2n−2 ε ⌋=2 n−1, So ⌊ 2 x ⌋=2 n−1=n+n−1=⌈ x ⌉ + ⌈ x− ⌉ ▄
2
5. If x is a real number, prove that ⌊ x+1 ⌋=⌊ x ⌋ +1
⌊ x+1 ⌋=n=n−1+1=⌊ x ⌋ +1
11
Examples.
1) bn = (−1)n = 1,−1, 1,−1, 1, . ;, is a geometric progression with initial term and ratio equal to 1 and −1;
2) cn = 2 ・ 5n is a geometric progression with initial term and ratio equal to 2 and 5;
3) dn = 6 ・ (1/3)n is a geometric progression with initial term and ratio equal to 6 and 1/3;
An arithmetic progression is a sequence of the form a, a + d, a + 2d, . . . , a + nd, . . .where the initial
term a and the common difference d are real numbers.
Examples.
1) sn = −1 + 4n is an arithmetic progressions with initial term and difference equal to −1 and 4.
2) tn = 7 − 3n is an arithmetic progressions with initial term and difference equal to 7 and −3.
A String is a finite sequences a1a2 . . . an. The length of a string is the number of terms in this string. The
empty string, denoted by λ, is the string that has no terms. The empty string has length zero.
The string abcd is a string of length four
Recurrence Relations
A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of
the previous terms of the sequence, namely, a0, a1, . . . , a n−1, for all integers n with n ≥ n0, where n0 is a
nonnegative integer. A sequence is called a solution of a recurrence relation if its terms satisfy the
recurrence relation. (A recurrence relation is said to recursively define a sequence. We will explain this
alternative terminology in Chapter 5.)
EXAMPLE 1. Let {an} satisfies the recurrence relation an = a n−1 + 3 for n = 1, 2, 3, . . . ,
and suppose that a0 = 2. What are a1, a2, and a3?
Solution: We see from the recurrence relation that a1 = a0 + 3 = 2 + 3 = 5. It then follows
13
The Fibonacci sequence, f0, f1, f2, . . . , is defined by the initial conditions f0 = 0, f1 = 1,
and the recurrence relation f n = f n−1 + f n−2 for n = 2, 3, 4, . . . .
EXAMPLE 1 Find the Fibonacci numbers f2, f3, f4, f5, and f6.
Solution: 2,3,5,8. . ▄
EXAMPLE 2 Suppose that {an} defined by an = n!, where n = 1, 2, 3, . . .. Because
n! = n((n − 1)(n − 2) . . . 2 ・ 1) =n(n − 1)! = n a n−1, we see that the sequence of factorials satisfies the
recurrence relation an = n a n−1, together with the initial condition a1 = 1. ▄
We say that we have solved the recurrence relation together with the initial conditions when
we find an explicit formula, called a closed formula, for the terms of the sequence.
EXAMPLE 3. Determine whether the sequence {an}, , is a solution of the recurrence relation
an = 2a n−1 – a n−2 for n = 2, 3, 4, . . . .
1) an = 3n , 2) an = 2n , 3) an = 5.
Solution: 1) Suppose that an = 3n for every nonnegative integer n. Then, for n ≥ 2, we see that
2a n−1 – a n−2 = 2(3(n − 1)) − 3(n − 2) = 3n = an. Therefore, {an}, where an = 3n, is a solution
of the recurrence relation.
2) Suppose that an = 2n. Note that a0 = 1, a1 = 2, and a2 = 4.
Because 2a1 − a0 = 2・2 − 1 = 3 ≠ a2, we see that {an}, where an = 2n, is not a solution of
the recurrence relation.
3) Suppose that an = 5 for every nonnegative integer n. Then for n ≥ 2, we see that an =
2a n−1 – a n−2 = 2 ・5 − 5 = 5 = an. Therefore, {an}, where an = 5, is a solution of the recurrence relation.
▄
EXAMPLE 3. Let {an} be a sequence that satisfies the recurrence relation an = a n−1 + 3 for n = 1, 2, 3, .
. . , and suppose that a0 = 2. Find explicit formula of an
14
Solution: starting with the initial condition a1 = 2, and working upward until we reach an to deduce a
explicit formula for the sequence. We see that
a2 = 2 + 3
a3 = (2 + 3) + 3 = 2 + 3 ・ 2
a4 = (2 + 2 ・ 3) + 3 = 2 + 3 ・ 3
...
an = a n−1 + 3 = (2 + 3 ・ (n − 2)) + 3 = 2 + 3(n − 1). ▄
Some Useful Summation Formulae
n
ar n+1 −a
1. ∑ ar = k
1−r
, r≠0
k=0
n
n(n+1)
2. ∑ k = 2
k =1
n
n ( n+1 ) (2 n+1)
3. ∑ k 2 = 6
k =1
n
n2 ( n+1 )2
4. ∑ k = 3
4
k =1
∞
1
5. ∑ x k = 1−x , |x| <1
k=0
∞
1
6. ∑ k x k −1 = ¿¿
, |x| <1
k =1
Definitions of m × n matrix. A , matrix arithmetic , the product of A and B, the identity matrix of
order n , The transpose of a matrix. A
5) Zero–One Matrices
A matrix all of whose entries are either 0 or 1 is called a zero–one matrix. Zero–one matrices are
often used to represent discrete structures, as we will see in Chapters 9 and 10. Algorithms using these
structures are based on Boolean arithmetic with zero–one matrices. This arithmetic is based on the Boolean
operations ∧ and ∨, which operate on pairs of bits, defined by
{
b 1 ∧b 2= 1 if b 1=b 2=1
0 otherwise
, {
b 1 ∨b 2= 1 if b 1=1 ∨b 2=1
0 otherwise
Let A = [aij ] and B = [bij ] be m × n zero–one matrices. Then the join of A and B is the zero–one
matrix with (i, j )th entry aij ∨ bij . The join of A and B is denoted by A ∨ B. Themeet of A and B is
the zero–one matrix with (i, j )th entry aij ∧ bij . The meet of A and B is denoted by A ∧ B.
A= [ 10 0 1
1 0 ]
, B=
0 1 0
1 1 0[ ]
Solution: We find that the join of A and B is
A∨B= [ 1∨ 0
0 ∨1
0 ∨1 1 ∨0
1 ∨1 0 ∨0
= ][
1 1 1
1 1 0 ]
The meet of A and B is
A∧B= [ 1∧ 0
0 ∧1
0 ∧1 1 ∧0
1 ∧1 0 ∧0
= ][
0 0 0
0 1 0
▄ ]
7) The Boolean product of two matrices
Let A = [aij ] be an m × k zero–one matrix and B = [bij ] be a k × n zero–one matrix. Then the
Boolean product of A and B, denoted by A⨀B, is the m × n matrix with (i, j )th entry cij where
[ ]
1 0
A= 0 1
1 0
B= [ 10 1 0
1 1 ]
Solution
[ ][ ]
(1 ∧1)∨(0 ∧0) (1 ∧1) ∨(0 ∧1) (1 ∧0) ∨( 0∧ 1) 1∨ 0 1∨ 0 0 ∨ 0
A⨀B = (0 ∧1)∨(1 ∧0) (0 ∧1)∨(1 ∧1) (0 ∧ 0)∨(1∧ 1) = 0 ∨0 0 ∨1 0∨ 1 =
(1 ∧1)∨(0 ∧0) (1 ∧1) ∨(0 ∧1) (1 ∧0) ∨( 0∧ 1) 1∨ 0 1∨ 0 0 ∨ 0
[ ]
1 1 0
= 0 1 1▄
1 1 0
8) The Boolean power . Let A be a square zero–one matrix and let r be a positive integer. The rth
Boolean power of A is the Boolean product of r factors of A. The rth Boolean product of A is
denoted by A[r].Hence A[r] = A⨀A⨀A⨀ ・ ・ ・⨀A
(This is well defined because the Boolean product of matrices is associative.)We also define
A[0] to be In.
[ ]
0 0 1
EXAMPLE 9 Let A = 1 0 0 . Find A[n] for all positive integers n.
1 1 0
Solution
[ ] [ ][ ]
1 1 0 0 0 1 1 0 1
A = A ⨀A = 0 0 1 ⨀ 1 0 0 = 1 1 0
[3] [2]
1 0 1 1 1 0 1 1 1
[ ] [ ][ ]
1 0 1 0 0 1 1 1 1
[4]
¿
A = A ⨀A 1 1 0
[3]
⨀ 1 0 0=1 0 1
1 1 1 1 1 0 1 1 1
17
[ ]
1 1 1
A == 1 1 1 .So A[n] = A[5] for all positive integers n with n ≥ 5.
[5]
1 1 1
Exercises
[ ] [ ]
1 0 1 0 1 1
1. Let A= 1 1 0 and B = 1 0 1 . Find
0 0 1 1 0 1
a) A ∨ B. b) A ∧ B. c) A⨀B.
2. Find the Boolean product of A and B, where
[ ] []
10
1001
01
A= 0 1 0 1 , B= .
11
1111
10
[ ]
1 0 0
3. Let A= 1 0 1 . Find
0 1 0