CS 104: Discrete Mathematics
-
Upload
arthur-harris -
Category
Documents
-
view
39 -
download
3
description
Transcript of CS 104: Discrete Mathematics
Chapter 3 :
Fundamental Structures
CS 104: Discrete Mathematics
T. Mai Al-Ammar
2
Functions (In Book: Chapter 2-sec
2.3)
T. Mai Al-Ammar
3
Introduction
Amal
Rawan
Maha
Sara
Safia
A
B
C
D
FS G
• In many instances we assign to each element of a set a
particular element of a second set.
• E.g. if we have a set of students S={Amal, Rawan, Maha,
Sara, Safia} and a set of grads G = { A, B, C, D, F}
we can assign a grade for each student, this assignment is
an example
of a function.
T. Mai Al-Ammar
Functions4
Definition:
• Let A and B be nonempty sets. A function f from A to B ( A
B ) is an assignment of exactly one element of B to each
element of A.
• We write f(a) = b if b is the unique element of B assigned by
the function f to the element a of A.
• Function are sometimes also called mapping or
transformations.
Functions are specified in different ways :
Explicitly state the assignment ( as example in the previous
slide)
Give a formula, e.g.
Use a computer program to specify a function
Define a function in terms of a relation from A to B
T. Mai Al-Ammar
Functions ( Cont.) 5
a
A
b=f(a)
B
f(a)
f
Definition:
• If the function f : A B, then A is the domain and B is the co-
domain of f.
• If f(a) = b, we say that b is the image of a and a is a pre-
image of b.
• The range or image of f is the set of all images of elements of
A.
• If f is a function from A to B, we say that f maps A to B.
T. Mai Al-Ammar
Functions ( Cont.) 6
• To define a function, we specify its domain, codomain, and
the mapping of elements of the domain to elements in the
codomain.
• Two functions are equal when they have the same domain,
have the same codomain, and map each element in the
domain to the same element in the codomain .
• If we change a domain or codomain or a mapping of a
function, we obtain a different function.
T. Mai Al-Ammar
Functions ( Cont.) 7
Example:
What are the domain, co-domain and range of the function that
assigns grades to students?
Let G be the function that assigns grades to a student in our
class.
The domain is the set {Amal, Rawan, Maha, Sara, Safia}
The co-domain is the set {A, B, C, D, F}
The range of G is the set {A, B, C, F}
Amal
Rawan
Maha
Sara
Safia
A
B
C
D
FS G
T. Mai Al-Ammar
Functions ( Cont.)8
Example :
Let R be the relation with ordered pairs (Amal,22), (Bdoor, 24),
(Sara, 21), (Dalal, 22), (Eman, 24) and (Fadwa, 22). Here each
pair consists of a graduate student and this student’s age. Specify
a function determined by this relation.
If f is a function specified by R, then : f(Amal)=22, f(Bdoor)= 24,
f(Sara)=21, f(Dala)=22, f(Eman)= 24, f(Fadwa)=22
Here f(X) is the age of x, where x is a student.
Domain {Amal, Bdoor, Sara, Dalal, Eman, Fadwa}
Co-domain { a | a>10 and a<90}
Range {21,22,24}
T. Mai Al-Ammar
Functions ( Cont.)9
Example:
Let f be the function that assigns the last two bits of a bit string of
length 2 or greater to that string. For example, f(11010)=10.
The domain of f is the set of all bit strings of length 2 or greater
both the co-domain and the range are the set {00, 01, 10, 11}
Example:
Let f: ZZ assign the square of an integer to this integer.
Domain and Co-domain of f is the set of all integers
Range of f is the set of all integers that are perfect squares {0, 1,
4, 9, …}
T. Mai Al-Ammar
Functions ( Cont.)10
The domain and codomain of functions are often specified in
computer programs
e.g.
the domain of the function is real numbers ( float ) , and the
codomain of
the function is integers.
int MyFunction ( float x )
T. Mai Al-Ammar
Functions ( Cont.)11
Definition:
Let f1 and f2 be two functions from A to R. Then f1+ f2 and f1 f2
are also functions from A to R defined by
(f1+f2) (x) = f1(x) + f2(x)
(f1 f2)(x) = f1 (x) f2(x)
Example :
Let f1 and f2 be two functions from R to R such that f1 (x) = x2
and f2 (x) = x – x2. What are the functions f1+f2 , f1 f2?
(f1+f2)(x) = f1 (x) + f2 (x) = x2 + (x – x2) = x
(f1f2)(x) = f1 (x) f2(x) = x2(x – x2) = x3 – x4
T. Mai Al-Ammar
Functions ( Cont.)12
A function f from the set A to the set B is said to be one-to-one or an
injunction, if and only if f(a) = f(b) implies that a = b for all a and b in the
domain of f. (No element of B is the image of more than one element in A)
a b ( f (a) = f (b) a=b )
Taking the contrapositive of the implication in the definition:
a b (a ≠ b f (a) ≠ f (b))
Every b B has at most one preimage.
T. Mai Al-Ammar
Functions ( Cont.)13
Example :
Determine whether the function f: {a, b, c, d} {1, 2, 3, 4, 5} with f(a)
= 4, f(b) = 5, f(c) = 1, and f(d) = 3 is injective.
The function f is one-to-one since f takes on different values at the four
elements of its domain.
Example :
Determine whether the function f : Z Z , f (x) = x2 is injective.
The function f is not one-to-one since, for instance, f(1) = f(-1) = 1, but 1
≠ -1.
Example :
Determine whether the function f (x) = x+1 from the set of
real numbers to itself is one-to-one.
T. Mai Al-Ammar
Functions ( Cont.)14
A function f from the set A to the set B is said to be onto or
surjection , if and only if for every element b B, there is an
element a A with f (a) = b. (All elements in B are
used.)
Every b B has at least one preimage.
Functions ( Cont.)15
Example :
Determine whether the function f: {a, b, c, d} {1, 2, 3} with f(a) = 3,
f(b) = 2, f(c)= 1, and f(d) = 3 is surjective.
The function f is onto, since three elements of the co-domain are images of
elements in the domain.
Example:
Determine whether the function f: Z Z, f(x) = x2 is surjective.
The function f is not onto since, e.g. there is no integer x with x2 = -1.
Example :
Determine whether the function f (x) = x+1 from the set of
integers to itself is onto.
T. Mai Al-Ammar
T. Mai Al-Ammar
Functions ( Cont.)16
Functions can be both one-to-one and onto. Such functions
are called bijective.
Bijections are functions that are both injective and surjective.
Every b B has exactly one preimage.
T. Mai Al-Ammar
17
Example:
Determine whether the function f: {a, b, c, d} {1, 2, 3, 4} with f(a) =
4, f(b) = 2, f(c) = 1, and f(d) = 3 is bijective.
The function f is one-to-one since no two values in the domain are
assigned the same function value. It is also onto because all four
elements of the co domain are images of elements in the domain.
Hence, f is a bijection.
T. Mai Al-Ammar
Some examples18
T. Mai Al-Ammar
19
Relations
(In Book: Chapter 9- sec 9.1 , sec
9.2)
T. Mai Al-Ammar
20
Relations
The most direct way to express a relationship between
elements of two sets is to use ordered pairs made up of two
related elements.
A set of ordered pairs are called binary relations.
Definition:
Let A and B be sets. A binary relation from A to B is a subset
of A x B.
A binary relation from A to B is a set R of ordered pairs where
the first element of each ordered pair comes from A and the
second element comes from B.
a R b (a,b) R
a R b (a,b) ∉ R
T. Mai Al-Ammar
21
Relations ( Cont.)
Example:
Let A = Set of students; B = Set of courses, let R be the
relation that consists of pairs :
R = {(a,b) | student a is enrolled in course b}
Note that when a student is not enrolled in any course, there
will be no pairs in R that have this student as the first element.
Example :
Let A = Set of cities; B = Set of countries. Define the relation
R by specifying that (a, b) belongs to R if city a is the capital
of b.
For instance, (Riyadh, Saudi Arabia), (Delhi, India),
(Washington, USA) are in R.
T. Mai Al-Ammar
22
Relations ( Cont.)
Example:
Let A={0, 1, 2} and B={a, b}. {(0, a), (0, b), (1, a), (2, b)} is a
relation from A to B. This means, 0Ra, but 1Rb.
Relations can be represented in two ways - as shown in the
figure:
Graphically using arrows to represent ordered pairs.
Using a table 0.
.
a
1.
.b
2.
a b RX X
X X
012
T. Mai Al-Ammar
23
Relations ( Cont.)
A function f from a set A to B assigns exactly one element of B
to each element of A.
Every element of A is the first element of exactly one ordered
pair in the relation.
A relation can be used to express a one to many relationships
between the elements of the sets A and B, i.e. an element of A
may be related to more than one element of B.
A function represents a relation where exactly one element of
B is related to each element of A, i.e. every element has only
one image.
T. Mai Al-Ammar
24
Relations ( Cont.)
Definition:
A relation on the set A is a relation from A to A. That is, a
relation on a set A is a subset of A x A.
Example:
Let A = {1, 2, 3, 4}. Which ordered pairs are in the relation
R={(a, b) | a divides b}?
(a, b) є R if and only if a and b are positive integers not
exceeding 4 such that a divides b, we see that
R={(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}
The pairs in R are displayed graphically and in tabular form:
T. Mai Al-Ammar
25
Relations ( Cont.)
The pairs in R are displayed graphically and in tabular form:
1 .1
2. .2
3. .3
4. .4
1 2 3 4 RX X X X
X X X X
1234
T. Mai Al-Ammar
26
Relations ( Cont.)
Example :
Consider the relations on the set of integers:
R1= {(a, b) | a ≤ b}, R2={(a, b) | a > b},
R3={(a, b) | a = b or a = -b}, R4={(a, b) | a = b},
R5={(a, b) | a = b+1}, R6={(a, b) | a+b ≤ 3},
Which of these relations contain each of the pairs (1, 1), (1, 2),
(2, 1), (1, -1) and (2, 2)?
(1, 1) is in R1, R3, R4 and R6; (1, 2) is in R1and R6;
(2, 1) is in R2, R5 and R6; (1, -1) is in R2, R3 and
R6;
(2, 2) is in R1, R3 and R4.
T. Mai Al-Ammar
27
Relations ( Properties of Relations )
1. Reflexivity: A relation R on a set A is called reflexive if (a, a)
R for all a A.
2. Symmetry: A relation R on a set A is called symmetric if (b, a)
R whenever (a, b) R, for all a, b A.
3. Antisymmetry: A relation R on a set A is called antisymmetric
if for all a, b A, if (a, b) R and (b, a) R, then a = b.
The contrapositive is :
T. Mai Al-Ammar
28
Relations ( Properties of Relations )
4. Transitivity: A relation R on a set A is called transitive if (a, b)
R and (b, c) R imply (a, c) R, for all a, b, c A.
Remark:
The terms symmetric and antisymmetric are not opposites.
A relation can have both of these properties or may lack both of
them.
A relation can not be both symmetric and antisymmetric if it
contains some pair of the form (a,b) where a b
In antisymmetric, the only way to have a related to b and b
related to a is for a and b to be the same element.
T. Mai Al-Ammar
Relations ( Properties of Relations )
29
Example :
Which of the following relations are reflexive and symmetric?
Consider the relations on the set of integers:
R1= {(a, b) | a ≤ b}, R2={(a, b) | a > b},
R3={(a, b) | a = b or a = -b}, R4={(a, b) | a = b},
R5={(a, b) | a = b+1}, R6={(a, b) | a+b ≤
3},
The reflexive relations are R1 (because a ≤ a, for all integer a),
R3 and R4.
For each of the other relations ,it is easy to find a pair of the
form (a, a) that is not in the relation.
T. Mai Al-Ammar
30
Relations ( Properties of Relations )
The symmetric relations are R3, R4 and R6.
R3 is symmetric, for if a=b or a=-b, then b=a or b=-a.
R4 is symmetric, since a=b implies b=a.
R6 is symmetric, since a+b ≤ 3 implies b+a ≤ 3.
None of the other relations is symmetric.
Relations ( Properties of Relations )
31
Example :
Which of the following relations are antisymmetric? Relations of
integers
R1= {(a, b) | a ≤ b}, R2={(a, b) | a > b},
R3={(a, b) | a = b or a = -b}, R4={(a, b) | a = b},
R5={(a, b) | a = b+1}, R6={(a, b) | a+b ≤ 3},
R1 is antisymmetric, since the inequalities a ≤ b and b ≤ a imply
that a = b.
R2 is antisymmetric, since it is impossible for a>b and b>a.
R4 is antisymmetric because two elements are related with
respect to R4 if and only if they are equal.
R5 is also antisymmetric, since it is impossible that a = b+1 and b
= a+1.
T. Mai Al-Ammar
T. Mai Al-Ammar
Relations ( Properties of Relations )
32
Example:
Which of the following relations are transitive? Relations of
integers
R1= {(a, b) | a ≤ b}, R2={(a, b) | a > b},
R3={(a, b) | a = b or a = -b}, R4={(a, b) | a = b},
R5={(a, b) | a = b+1}, R6={(a, b) | a+b ≤ 3},
The transitive relations from Example 5 are R1, R2, R3 and R4.
R1 is transitive, since a ≤ b and b ≤ c imply a ≤ c.
R2 is transitive, since a > b and b > c imply a > c.
R3 is transitive, since a = ±b and b = ±c imply a = ±c.
R4 is transitive, since a = b and b = c imply a = c.
T. Mai Al-Ammar
Relations ( Properties of Relations )33
Example :
Consider following relations on {1, 2, 3}:
R1= {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)},
R2={(1, 1), (1, 2), (2, 2), (3, 2), (3, 3)},
R3={(2, 1), (2, 3), (3, 1)}
R4={(2, 3)},
Which of the relations are reflexive, symmetric,
antisymmetric and transitive?
T. Mai Al-Ammar
Relations ( Properties of Relations )
34
Definition:
A relation on a set A is called an equivalence
relation if it is reflexive, symmetric, and transitive.
1. Reflexive ( aA, aRa)
2. Symmetric (aRb => bRa)
3. Transitive (aRb and bRc => aRc)
T. Mai Al-Ammar
35
Relations ( Properties of Relations )
Example :
Let R be the relation on the set of real numbers such that aRb if
and only if a-b is an integer. Is R an equivalence relation?
As a-a = 0 is an integer for all real numbers a. So, aRa for all real
numbers a. Hence R is reflexive.
Let aRb, then a-b is an integer, so b-a also an integer. Hence bRa,
i.e., R is symmetric.
If aRb and bRc, then a-b and b-c are integers. So, a-c = (a-b) +
(b-c) is also an integer. Hence, aRc. Thus R is transitive.
Consequently, R is an equivalence relation
T. Mai Al-Ammar
36
End of Chapter 3