Part1 0SetsandRelations

Download as pdf or txt
Download as pdf or txt
You are on page 1of 160

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI

VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG

Discrete Mathematics

Nguyễn Khánh Phương

Department of Computer Science


School of Information and Communication Technology
E-mail: [email protected]
Discrete Mathematics
Discrete Mathematics deals with
• “Separated” or discrete sets of objects
(rather than continuous sets)
• Processes with a sequence of
individual steps
(rather than continuously changing processes)

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Kind of problems solved by discrete mathematics

• How many ways are there to choose a computer password?

• What is the probability of winning a lottery?

• Is there a link between two users in a social network?

• What is the shortest path between two cities using a


transportation system?

• How can a list of integers sorted in increasing order? How


many steps are required to do such a sorting?
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Importance of Discrete Mathematics
• Information is stored and manipulated by computers in a discrete
fashion
• Applications in many different areas
• Discrete mathematics is a gateway to more advanced courses
• Develops mathematical reasoning skills
• Emphasizes the new role of mathematics

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
The new role of Mathematics
• Make the computer to solve the problem for you
• Modeling (vs. calculations)
• Using logic
– to choose the right model
– to write a correct computer program
– to justify answers
• Efficiency
– make the computer to solve the problem fast
– choose the more efficient model

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Goals of this course

• Study of standard facts of discrete mathematics

• Development of mathematical reasoning skills


(emphasis on modeling, logic, efficiency)

• Discussion of applications

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Text book

Rosen K.H. Discrete Mathematics and its


Applications (8th Editions). McGraw - Hill
Book Company, 2019.

Use lecture notes as study guide.


Text book

Nguyễn Đức Nghĩa,


Nguyễn Tô Thành
TOÁN RỜI RẠC
(in lần thứ ba)
Nhà xuất bản Đại học
Quốc gia Hà nội, 2003,
290 trang
References
1. Johnsonbaugh R. Discrete Mathematics. Prentice Hall Inc., N. J., 1997.
2. Grimaldi R.P. Discrete and Combinatorial Mathematics (an Applied
Introduction), Addison-Wesley, 5th edition, 2004.
3. R. Graham, O. Patashnik, and D.E. Knuth. Concrete Mathematics,
Second Edition. Addison-Wesley, 1994.
References
4. Nguyễn Hữu Anh. Toán rời rạc, NXB Giáo dục,1999.
5. Nguyễn Xuân Quỳnh. Cơ sở Toán rời rạc và ứng dụng. NXB KHKT,
Hà nội, 1996.
6. Đỗ Đức Giáo. Toán rời rạc. NXB KHKT, Hà nội, 2001.
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)

PART 2
GRAPH THEORY
(Lý thuyết đồ thị) 11
Contents of Part 1: Combinatorial Theory
Chapter 1. Counting problem
• This is the problem aiming to answer the question: “How many ways are there that satisfy
given conditions?” The counting method is usually based on some basic principles and some
results to count simple configurations .
• Counting problems are effectively applied to evaluation tasks such as calculating the
probability of an event, calculating the complexity of an algorithm (how long the algorithm
will take to run), ....
Given N paintings in a row over a
distance of M centimeters.
Each painting i (1 ≤ i ≤ N) will be drawn
on a length of ti cm, so t1+t2+..+tn = M.
The K city's most famous artists have
been selected to do this work, each artist
will be assigned to draw at least one
painting. To facilitate the artist's work, if
someone is assigned to draw more than
one painting, the paintings must be
Street art adjacent to each other on the street art

12
Contents of Part 1: Combinatorial Theory
Chapter 1. Counting problem
• This is the problem aiming to answer the question: “How many ways are there that satisfy
given conditions?” The counting method is usually based on some basic principles and some
results to count simple configurations .
• Counting problems are effectively applied to evaluation tasks such as calculating the
probability of an event, calculating the complexity of an algorithm
Chapter 2. Existence problem
In the counting problem, configuration existence is obvious; in the existence problem, we need to
answer the question: "Is there a combinatorial configuration that satisfies given properties ?”
Chapter 3. Enumeration problem
This problem is interested in giving all the configurations that satisfy given conditions.
Chapter 4. Combinatorial optimization problem
• Unlike the enumeration problem, this problem only concerns the "best" configuration in a
certain sense.
• In the optimization problems, each configuration is assigned a numerical value (which is the
use value or the cost to construction the configuration), and the problem is that among the
configurations that satisfy the given conditions, find the configuration with the maximum or
minimum value assigned to it
Contents of Part 2: Graph Theory

• Graphs
• Degree sequence, Eulerian graphs, isomorphism
• Trees
• Matching
• Coloring

Computer networks, data structures


Contents of Part 2: Graph Theory

How to color a map?


How to schedule exams/projects?

How to send data efficiently?


Contents of Part 1
Chapter 0: Sets, Relations
Chapter 1: Counting problem
Chapter 2: Existence problem
Chapter 3: Enumeration problem
Chapter 4: Combinatorial optimization problem

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 16
Contents of Part 1
Chapter 0: Sets, Relations
Chapter 1: Counting problem
Chapter 2: Existence problem
Chapter 3: Enumeration problem
Chapter 4: Combinatorial optimization problem

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 17
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI
VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG

Chapter 0
sets, relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations

19
1.Definitions
• We have already implicitly dealt with sets
– Integers (Z), rationals (Q), naturals (N), reals (R), etc.
• We will develop more fully
– The definitions of sets
– The properties of sets
– The operations on sets

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 20
1. Definitions
1.1 Set and element
1.2. Specification of set

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 21
1.1 Set and element
• Definition:
– A set is an unordered collection of (unique) objects
– The objects in a set are called elements or members of a set.
A set is said to contain its elements.
• Notation, for a set A:
– x  A: x is an element of A
– x  A: x is not an element of A
Example:
V={a, e, i, o, u} (vowels in English)
C = all students subscribed to IT3020E in Winter 2020
Note:
– We often denote sets with capitals
– Brackets are used to define the set. {.} NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 22
1.1 Set and element
• Definition: A multi-set is a set where you specify the number of
occurrences of each element: {m1a1,m2a2,…,mrar} is a set
where
– m1 occurs a1 times
– m2 occurs a2 times
–
– mr occurs ar times

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 23
1. Definitions
1.1 Set and element
1.2. Specification of set

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 24
1.2 Specification of set
Our first concern will be how to describe a set; that is, how do
we most conveniently describe a set and the elements that are
in it? Sets can be defined in various ways.
At first we consider two ways:
1. Set extension
2. Set intension

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 25
1.2 Specification of set
• A set is defined in extension when you enumerate all the
elements:
O={0,2,4,6,8}
• The set-builder notation
A = {x | conditions(x)}.
this could be read as “all x such that the conditions hold true”.
Example: O={ x | (xZ)  (x=2k) for some kZ}
reads: O is the set that contains all x such that x is an integer and x is even
• A set is defined in intension when you give its set-builder
notation
O={ x | (xZ)  (0  x  8)  (x=2k) for some k  Z }

26
1.2 Specification of set
Well-known sets in math:
• N = {0,1,2,3,...}
• Z = {...,-2,-1,0,1,2,...}
• Z+ = {1,2,3,...}
• Q = {p/q | p in Z, q in Z, q is not 0}
• R = {x | x is a real number}.

{,...} is used to indicate the the rest of the sequence once it’s clear how to
proceed
Example: {1,2,3,4,...}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 27
1.2 Specification of set
• There is a set with no elements. It is called the empty set (or
null set) and denoted {} or .
• A set that has one element is called a singleton set.
– For example: {a}, with brackets, is a singleton set
– a, without brackets, is an element of the set {a}
• Note the subtlety in   {} ??why
– The left-hand side is the empty set
– The right hand-side is a singleton set, and this set contains a set

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 28
1.2 Specification of set
• If there are exactly n distinct elements in a set S, with n is a nonnegative integer, we
say that:
– S is a finite set, and
– The cardinality of S is n. Notation: |S| = n.
• Definition. A set is a finite set if it has a finite number of elements. A set that is not
finite is an infinite set.
• Let A be a finite set. The number of different elements in A is called its cardinality
and is denoted by |A|. Other notations commonly used for the cardinality of A are
N(A), #A.
If A be a infinite set, then we write |A| = .
Example:
• || = 0 since  contains no elements.
• |{π, 2, Newton}| = 3.
• If Nn = {0, 1, …, n} then | Nn | = n + 1.
• |{n: n is a prime number}| = ∞.
• The sets N, Z, Q, R are all infinite NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 29
1.2 Specification of set
• Sets can be elements of other sets
Example:
– S1 = {,{a},{b},{a,b},c}
– S2={{1},{2,4,8},{3},{6},4,5,6}

Example: What is the cardinality of the set ?


• X = {{a, b}}
• A = {1, 2, {a, b}}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 30
1.2 Specification of set
– Let B = {x | (x100)  (x is prime)}
the cardinality of B is |B|= ?

25 because there are 25 primes less than or equal to 100.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 31
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations
6. Functions

32
2. Set operations
2.1 Set comparison
2.2 Venn diagram
2.3 Set operations
2.4 Partition and cover

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 33
2.1. Set comparison
• Definition: Two sets, A and B, are equal if they contain the
same elements. We write A=B.
Example:
– {2,3,5,7}={3,2,7,5}, because a set is unordered
– Also, {2,3,5,7}={2,2,3,5,3,7} because a set contains unique
elements
– However, {2,3,5,7} {2,3}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 34
2.1. Set comparison
if P(x) and Q(x) are propositional functions which are true for the same
objects x, then the sets they define are equal, i.e.
{x : P(x)} = {x : Q(x)}.

Example: there are 2 sets


A = {x: (x − 4)2 = 25}
B = {x: (x + 1)(x − 9) = 0}
Question: A = B ?
Yes: A = B, since the two propositional functions P(x): (x − 4)2 = 25 and
Q(x): (x + 1)(x − 9) = 0 are true for the same values of x, namely −1 and
5.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 35
2.1. Set comparison
• Definition: A is said to be a subset of B, if and only if every element
of A is also an element of B
that is:  x (x  A  x  B)
Denote: A  B or B  A,

Example: S =  1, 2, 3,  , 11, 12  and T =  1, 2, 3, 6  then T  S.

• Theorem: For any set S


–   S and
– SS

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 36
2.1. Set comparison
• Definition: If A  B and A  B then set A is called a proper subset
of set B.
(that is there is an element xB such that xA)
Denote: A  B

Example 1: A = { 1, 2, 3 }, B = { 2, 3, 1 }, C = { 3 }. Then:
B = A, C  A, C  B.
Example 2:

?
{1, 4, 9, 16, ...}  {1, 2, 3, ...}  {0, 1, 2, ...}.
{1, 4, 9, 16, ...}  {1, 2, 3, ...}  {0, 1, 2, ...}.

Here, we could have used the proper subset symbol  to link these three sets
instead.
37
2.1. Set comparison
• You may be asked to show that a set is
– a subset of,
– proper subset of, or
– equal to another set.
• To prove that A is a subset of B, use the equivalence discussed earlier
A  B  x(xA  xB)
– To prove that A  B it is enough to show that for an arbitrary
(nonspecific) element x, xA implies that x is also in B.
– Any proof method can be used.
• To prove that A is a proper subset of B (A  B), you must prove
– A is a subset of B and
– x (xB)  (xA)
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 38
2.1. Set comparison
• Finally to show that two sets are equal, it is sufficient to
show independently (much like a biconditional) that
– A  B and
–BA
• Logically speaking, you must show the following quantified
statements:
(x (xA  xB))  (x (xB  xA))
we will see an example later..

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 39
2.1. Set comparison
Examples:
• N = {0, 1, 2, 3, ...} the set of natural numbers.
• Z = {...,−2,−1, 0, 1, 2, ...} the set of integers.
• Z+ : the set of positive integers
• Q = {p/q : p, q  Z and q ≠ 0} the set of fractions or rational numbers.
• Q+ : the set of positive rational numbers
• R = the set of real numbers;
• R+ : the set of positive real numbers
• C = {x + iy : x, y  R and i2 = −1} the set of complex numbers.

Clearly the following subset relations hold amongst these sets:


N Z Q R C.
Question: ??? N = Z+
Note that N is not equal to Z+ since 0 belongs to the first but not the second

40
2.1. Set comparison
We shall sometimes use E and O to denote the sets of even and
odd integers respectively:
• E = {2n : n  Z } = {...,−4,−2, 0, 2, 4, ...}
• O = {2n+1 : n  Z } = {...,−3,−1, 1, 3, 5, ...}

Universal set (U) : contains as subsets all sets relevant to the


current task or study. Anything outside the universal set is
simply not considered. The universal set is not something
fixed for all time -we can change it to suit different contexts.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 41
2. Set operations
2.1 Set comparison
2.2 Venn diagram
2.3 Set operations
2.4 Partition and cover

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 42
2.2. Venn diagram John Venn
1834-1923
• A set can be represented graphically using a Venn Diagram

U x y B
A
z

a C

• The universal set U is represented by the interior of a rectangle


• The sets by region inside the rectangle and elements which belong to a given set are placed
inside the region representing it.
• If an element belongs to more than one set in the diagram, the two regions representing the
sets concerned must overlap and the element is placed in the overlapping region.
In this way the picture represents the relationships between the sets concerned. 43
2.2. Venn diagram
Example:

U
A

if A  B: the region representing A may be enclosed inside the region


representing B to ensure that every element in the region representing A
is also inside that representing B
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 44
2.2. Venn diagram
Example: Draw the Venn diagram that represents 3 sets:
A = {1, 2, …, 10},
B = {2, 4, 6, 8, 12, 13},
C = {2, 3, 5, 7, 11, 13}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 45
2. Set operations
2.1 Set comparison
2.2 Venn diagram
2.3 Set operations
2.4 Partition and cover

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 46
2.3. Set operations
• Arithmetic operators (+,-,  ,) can be used on pairs of numbers
to give us new numbers
• Similarly, set operators exist and act on two sets to give us new
sets:
1. Union
2. Generalized union
3. Intersection
4. Generalized intersection
5. Set difference
6. Set complement

47
Set Operators: Union
• Definition: The union of two sets A and B is the set that
contains all elements in A, B, or both. We write:
AB = { x | (x  A)  (x  B) }

U
A B

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Generalized Union
• Definition: The union of a collection of sets is the set that
contains those elements that are members of at least one set in
the collection
Let A1, A2, ..., An be sets. Their union is:

1 2

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Intersection
• Definition: The intersection of two sets A and B is the set that
contains all elements that are element of both A and B.
We write:
A  B = {x | (x  A)  (x  B) }

U
A B

Two sets A and B are disjoint if A ∩ B = . NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Generalized Intersection
• Definition: The intersection of a collection of sets is the set that
contains those elements that are members of every set in the
collection

A =A
n

i 1  A2 … An
i=1

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Disjoint Sets
• Definition: Two sets are said to be disjoint if their intersection is
the empty set: A  B = 

U
A B

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Generalized Intersection
• 𝒊∈𝑰 𝒊 𝒊 is used for the intersection of the family of sets
Ai indexed by the set I.
• A collection of sets {Ai | i  I} is disjoint if

𝒊
𝒊∈𝑰
A collection of sets is pairwise disjoint (or mutually disjoint) if every pair of sets in the
collection are disjoint.
Example:
A = A1 A2A3 A4
A1 = {1, 3, 5,7} ? A is not disjoint
A2 = {2, 4, 6} ? A is disjoint
A3 = {-1,-3,-5,-7} ? A is pairwise disjoint
A4 = {-2, -4, -6} ? B is not disjoint
A5 = {2} ? B is disjoint
B = A1 A2A3 A4 A5 ? B is pairwise disjoint
Set Operators: Set Difference
• Definition: The difference of two sets A and B is the set containing
those elements that are in A but not in B.
Denote: A\B or A−B

U
A B

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Set Difference
• The symmetric difference of two sets A and B, denoted A 
B, is defined as follows
A  B = (AB) \ (AB)

U
A B

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Operators: Set Complement
• Definition: The complement of a set A, denoted , or Ac or
 A consists of all elements not in A. That is the difference
of the universal set and U: U\A
= AC = {x | x  A }

U A
A

A − B = {x | x  A and x  B} = A ∩ Bc.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Complement
Examples:
Let A={1, 2, 3}, B = {3, 4, 5}. Then
• AB =
• AB =
• A\B=
• AB =

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Set Complement: Absolute & Relative
• Given the Universe U, and A,B  U.
• The (absolute) complement of A is
• The (relative) complement of A in B is B\A

U U
A A B
A

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
2. Set operations
2.1 Set comparison
2.2 Venn diagram
2.3 Set operations
2.4 Partition and cover

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 59
2.4. Partition and cover
Let E = be a collection of subsets of the set M,  .
Collection E will be called a cover of M if each element of
M must be an element of at least one of the sets of E :

The disjoint cover E of M is called a partition of M, i.e.

Example: M = {1, 2, 3, 4}
E1 = {{1, 2}, {3, 4}} is a partition of M
E2 = {{1, 2, 3}, {3, 4}} is not a partition of M
60
2.4. Partition and cover
Example: M= {11, 12, 13, 14}
E1 = {{11, 12}, {11, 13}, {12, 14}}
E2 = {{11, 12}, {13, 14}}
E3 = {{11, 12}, {13}}

E1, E2, E3 is cover / partition of M ?

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 61
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 62
Contents
1. Definitions
2. Set operations
3. The algebra of sets
3.1. Power set
3.2 Properties of set operations
4. Computer representation of sets
5. Relations

63
3.1. Power Set
• Definition: The power set of a set A, denoted P(A), is the
set of all subsets of A.
Examples
{
Let A = { } P (A) = {}
,
Let A = {a} P (A) = {, {a}} {a}, {b}, {c},
Let A = {a, b}  P(A)= {, {a}, {b}, {a, b}} {a, b}, {a, c}, {b, c},
{a, b, c}
Let A = {a, b, c}  P(A) = ?
}

• Note: the empty set  and the set itself are always elements
of the power set.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
3.1. Power Set
• Theorem: Let A be a set such that |A|=n, then
|P(A)| = 2n
Proof: Let A be the set {a1, a2, ..., an}.
• We can form a subset of A by considering each element ai in turn and either
including it or not in the subset.
• For each element there are two choices (either include it or don’t) and the
choice for each element is independent of the choices for the other
elements, so there are 2n choices altogether.
• Each of these 2n choices gives a different subset and every subset of A can
be obtained in this way.
{
,
Let A = {a, b, c}  P(A) = ? {a}, {b}, {c},

0 1 0 1 0 1

a {a, b}, {a, c}, {b, c},
{a, b, c}
}
3.1. Power Set
Let A = {a, b, c} and B = {a, b}. Determine whether each of the
following is true or false and give a brief justification.
1. B  P (A)
2. B  A
3. A  P (A)

4. A  P (A)

5. B  P (A)
6. {{a}, B}  P (A)

7.   P (A)
8.   P (A).
3.1. Power Set
Theorem.
For all sets A and B:
1. A  B if and only if P (A)  P (B).
2. P (A) ∩ P (B) = P (A ∩ B).
3. P (A)  P (B)  P (A  B).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
3.1. Power Set
Theorem.
For all sets A and B:
1. A  B if and only if P (A)  P (B).

We prove the two statements:


A  B  P (A)  P (B) and
P (A)  P (B)  A  B.
• Firstly, suppose A  B. Let X  P (A). This means X  A. Since A  B, it
follows that X  B, which means that X  P (B). Since X  P (A) implies X
 P (B), we conclude that P (A)  P (B), which completes the proof of the
first statement.
• To prove the converse statement, suppose P (A)  P (B). Since A P (A), it
follows that A P (B). This means that A  B, which completes the proof.
Contents
1. Definitions
2. Set operations
3. The algebra of sets
3.1. Power set
3.2 Properties of set operations
4. Computer representation of sets
5. Relations
6. Functions

69
3.2 Properties of set operations
Let A, B and C be any sets. The following laws hold
Equality Name
A=A Identity laws (Đồng nhất)
AU=A
AU=U Domination laws (Trội)
A=
AA=A Idempotent laws (Lũy đẳng)
AA=A
A =U Complementation laws (Bù)
A∩ =
=U
=
Involution laws (Bù kép)
(A)  A
3.2 Properties of set operations

Equality Name
AB=BA Commutative laws
AB=BA (Giao hoán)
A  (B  C) = (A  B)  C Associative laws
A  (B  C) = (A  B)  C (Kết hợp)
A  (B  C) = (A  B)  (A  C) Distributive laws
A  (B  C) = (A  B)  (A  C) (Phân phối)
AB  A B De Morgan’s laws
AB  A B (Luật De Morgan)
A ∩ (A  B) = A Absorption laws
A  (A ∩ B) = A.
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A  B and B  A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A  B and B  A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Proving Set Equivalences
• Recall that to prove such identity A = B, we must show that:
1. The left-hand side is a subset of the right-hand side
2. The right-hand side is a subset of the left-hand side
3. Then conclude that the two sides are thus equal

Example: Let
– A={x |x is even}
– B={x |x is a multiple of 3}
– C={x |x is a multiple of 6}
• Show that AB=C

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Show that AB=C

• The left-hand side is a subset of the right-hand side


AB  C:  x  AB
 x is a multiple of 2 and x is a multiple of 3
 we can write x =2*3*k for some integer k
 x = 6k for some integer k  x is a multiple of 6
xC
• The right-hand side is a subset of the left-hand side
C AB:  x C
 x is a multiple of 6  x = 6k for some integer k
 x = 2(3k)=3(2k)  x is a multiple of 2 and of 3
 x  AB
Proving Set Equivalences
Example 2: Proof that: A(BC)=(AB)(AC).
• Part 1: Proof A(BC)(AB)(AC).
– Assume xA(BC), need to proof x(AB)(AC).
– As xA, and either xB or xC.
• Case1: xB. Then xAB, therefore x(AB)(AC).
• Case2: xC. Then xAC , therefore x(AB)(AC).
– Thus, x(AB)(AC).
– So A(BC)(AB)(AC).
• Part 2: Proof (AB)(AC)  A(BC).
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A  B and B  A.
2. Using definitions and equivalence of logical
propositions that define the set.
3. Use the truth table.
Proving Set Equivalences
Example 3: Proof: A B  A B
A  B   x x  A  B According
theo ®Þnhto complementation
nghÜa phÇn bïdefinition
  x ( x  ( A  B)) According
theo ®Þnh nghÜa of ∉
to definition

  x ( x  A  x  B) According
theo ®Þnh nghÜa giao
to definition of intersection

  x x  A  x  B ) theo luËttoDeMorgan
According De Morgan law


 x x  A  x  B)  theo ®Þnh
According nghÜa phÇn bïdefinition
to complementation

  x x  A  B )
According to union definition
theo ®Þnh nghÜa hîp
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A  B and B  A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Truth table
• Building tables:
– The columns correspond to set expressions.
– The rows correspond to all possible combinations of membership in the set.
• Fill in the table: Use "1" to indicate a member, "0" to indicate non-member.
• Equality is proven if two columns corresponding to two expressions on both sides are
identical.
Example 4: Proof: (AB)B = AB.

A B A  B (A  B ) B A  B
0 0 0 0 0
0 1 1 0 0
1 0 1 1 1
1 1 1 0 0
Proving Set Equivalences
Example 5: Using the truth table, proof that
A  (B  C) = (A  B)  (A  C)

A B C BC A(BC) AB AC (AB)(AC)


1 1 1 1
1 1 0 1
1 0 1 1
1 0 0 0
0 1 1 1
0 1 0 1
0 0 1 1
0 0 0 0
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations
6. Functions

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 82
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
4.1. Characteristic vector
4.2. Subset enumeration
4.3. List of elements
5. Relations
6. Functions
83
4.1. Characteristic vector
Suppose that we have U = {u1, u2, ..., un}, where n is not too large. Then each
subset M  U can be represented by a vector b = (b1, b2, ..., bn) where
bi = 1  ui  M, i =1, 2, ..., n.
= 0 otherwise
• Vector b constructed by this rule is called characteristic vector of the set M.
• It is clear that each subset M  U corresponds to unique characteristic
vector b, and on the other hand, each binary n-vector b corresponds to
unique subset of U

01 1 0 1 01 0 0 0 1
Example:
Suppose that U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}.
Consider the subsets S, Q  U.
• S = {2, 3, 5, 7, 11}  01101010001
• Q = {1, 2, 4, 11}  11010000001
84
4.1. Characteristic vector
Note that all the set operation  (Union),  (Intersection),
(complement) can be done by correspondently logic operation OR,
AND, NOT

Example: Suppose that U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}.


Consider the subsets S, Q  U.
• S = {2, 3, 5, 7, 11}  01101010001
• Q = {1, 2, 4, 11}  11010000001
• S  Q  01101010001  11010000001
 S  Q  11111010001
• S  Q  01101010001  11010000001
 S  Q  01001000001
• S = 01101010001
  S  10010101110 85
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
4.1. Characteristic vector
4.2. Subset enumeration
4.3. List of elements
5. Relations
6. Functions
86
4.2. Subset enumeration
In many practical situation, we have to examine all the subsets of a given
set U = {u1, u2, ..., un}.
For example: Enumerate all subsets of U = {1, 2, 3}
1. 
2. {1}
3. {2}
4. {3}
5. {1, 2}
6. {1, 3}
7. {2, 3}
8. {1, 2, 3}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 87
4.2. Subset enumeration
In many practical situation, we have to examine all the subsets of a given set U
= {u1, u2, ..., un}. How to do it?
• Answer: Each subset of U ~ a characteristic vector
Enumeration of all the subsets of U ~ enumeration of all binary n-vector.
1 2
Since each binary n-vector can be considered as the binary representation of a
nonnegative integer (b) = b1b2...bn, 0  (b)  2n-1
 enumeration of all binary n-vector 2

~ enumeration of binary representation for all nonnegative integer from 0 to 2n-1.


3

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 88
1.4.2. Subset enumeration
For example: Enumerate all subsets of U = {1, 2, 3}
0) 000 
1) 001 {3}
2) 010 {2}
3) 011 {2,3}
4) 100 {1}
5) 101 {1,3}
6) 110 {1,2}
7) 111 {1,2,3}

Enumeration of all the subsets of U 1


~ enumeration of all binary n-vector 2
~ enumeration of binary representation for all nonnegative integer from 0 to 2n-1. 3

89
4.2. Subset enumeration
Subset Enumeration Algorithm:
• Step k = 0, 1, ..., 2n-1: Output binary representation of the number k.
• Clearly, if we have the binary representation of the number k
(b1b2...bn) then the binary representation of the number k+1 can be
obtained by binary addition b1b2...bn to 1.

For example: Enumerate all subsets of U = {1, 2, 3}


0) 000 
1) 001 {3}
2) 010 {2}

101
3) 011 {2,3}
4) 100 {1}
5) 101 {1,3} + 1
6) 110 {1,2}
7) 111 {1,2,3} 110 90
4.2. Subset enumeration
Subset Enumeration Algorithm
• Step k = 0, 1, ..., 2n-1: Output binary representation of the number k.
• Clearly, if we have the binary representation of the number k
(b1b2...bn) then the binary representation of the number k+1 can be
obtained by binary addition b1b2...bn to 1.

Algorithm: BINARY_INCREMENT(b1,b2,...,bn)
i = n;
while (n>=1) and (bi==1)
bi = 0;
i = i – 1 ;
endwhile
bi = 1;

91
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
4.1. Characteristic vector
4.2. Subset enumeration
4.3. List of elements
5. Relations
6. Functions
92
4.3. List of elements
• When the set U contain a large number of elements, but considered subset U have a
small cardinality, binary representation is not reasonable. In this case we can
represent the subset by list of all its elements.
• This list is usually implemented as the linked list structure. Each element of list is
a record that consists of two fields, one of which contains the information of the
element and the other one is a pointer to the next element:
class ListNode {
Object data ; //element information
ListNode next; //pointer to the next element
}
data1 data2 data3 data4 

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 93
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations
6. Functions

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 94
5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 95
5.1. Ordered pair
• An ordered pair is a set of a pair of objects with an order associated
with them.
• In general (x, y) is different from (y, x).
• Definition (equality of ordered pairs): Two ordered pairs (a, b) and
(c, d) are equal if and only if a = c and b = d.

Example: if the ordered pair (a, b) is equal to (1, 2), then a=1, and b=2.
(1, 2) is not equal to the ordered pair (2, 1).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 96
5.2. Cartesian product René Descartes
(1596-1650)

• Let A1, A2, …, An be any sets, where n  ℤ+ and n  3.


Cartesian product of n sets A1, A2, …, An is defined as follows:
A1  A2  …  An def {(a1, a2, …, an) | ai  Ai, 1  i  n}.

When A1 = A2 = …= An = A, it is usually to denote A  A  …  A by An

An element of A1  A2  …  An is called an ordered n-tuple.


When n=3, we have a triple.

Example: A = {1, 2}, B = {a, b} and C = {α, β} then


A × B × C = {(1, a, α), (1, a, β), (1, b, α), (1, b, β), (2, a, α), (2, a, β), (2,
b, α), (2, b, β)}.
97
5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 98
5.2. Cartesian product
Theorem : If X1, X2, ..., Xn are finite sets then
|X1 × X2 ×…× Xn| = |X1| × |X2|×…×|Xn|

Enumeration: To enumerate all elements of Cartesian product of the sets we


can use tree diagram.
Example: A = {2, 3, 4}, B = {4, 5}, and C = {x, y}.
Tree diagram for A  B:
Tree diagram for A  B  C :
(2,4) (2,4) (2,4,x)
(2,4,y)
(2,5)
2 (2,5) 2 (2,5,x)
(2,5,y)
(3,4) (3,4) (3,4,x)
3 (3,5) 3 (3,4,y)
(3,5) (3,5,x)
(4,4) 4 (3,5,y)
(4,5) (4,4) (4,4,x)
4 (4,4,y)
(4,5) (4,5,x) 99
(4,5,y)
5.2. Cartesian product
How the Cartesian product operation behaves with respect to the
other set theory operations such as intersection and union?

Theorem : For any three sets A, B, C:


A  (B ∩ C) = (A  B) ∩ (A  C);
A  (B  C) = (A  B)  (A  C);
(A ∩ B)  C = (A  C) ∩ (B  C);
(A  B)  C = (A  C)  (B  C).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 101
5.3. Binary Relation
Let A and B be sets:
• Definition (binary relation): A binary relation from a set A to
a set B is a set of ordered pairs (a, b) where a is an element of
A and b is an element of B.
– A binary relation from A to B is a subset R  A  B]
– A relation on a set A is a relation from A to A, i.e., a subset R  A  A
• Notation: When an ordered pair (a, b) is in a relation R, we
write a R b, or (a, b)  R. It means that element a is related to
element b in relation R. We will write aR b when a element a
is not related to element b in relation R.

102
5.3. Binary Relation
Example:
– Let A be the students in a the CS major
• A = {Tan, Bob, Michel, Amy}
– Let B be the courses the department offers
• B = {CS101, CS201, CS202}
– We specify relation R = A  B as the set that lists all students a  A
enrolled in class b  B
• R = { (Tan, CS101), (Bob, CS201), (Bob, CS202),
(Amy, CS201), (Amy, CS202) }

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 103
Representing relations

We can represent We can represent


relations graphically: relations in a table:
CS101 CS201 CS202

Tan Tan X
Bob X X
CS101
Bob Michel
Amy X X
CS201
Michel

CS202
Amy
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Relations on a Set
• A relation on a set A is a relation from A to A.

Examples of relations on Z+: R<, R, R> :


• R< = {(x, y)| x < y} (R< is relation “strictly less than”).
• R= {(x, y)| x  y} (R is relation “greater or equal”).
• R>= {(x, y)| x > y} (R> is relation “strictly greater than”).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 105
Relations on a Set
Consider the following relations on Z:
• R1 = {(a, b) | a  b} (1,1) (1,2) (2,1) (1,-1) (2,2)
• R2 = {(a, b) | a > b} R1   
• R3 = {(a, b) | a = b or a = -b} R2  
• R4 = {(a, b) | a = b} R3   
• R5 = {(a, b) | a = b+1} R4  
• R6 = {(a, b) | a + b  3} R5 
R6    

For each the following ordered pairs


(1,1), (1,2), (2,1), (1,-1), and (2,2)
show which relation it belongs to.
106
5.3. Binary relation

A binary relation is a set of ordered pairs (x, y)

The domain is the set of all x values in the relation


domain = {-1,0,2,4,9}
These are the x values written in a set from smallest to largest

This is a
{(2,3), (-1,5), (4,-2), (9,9), (0,-6)} relation

These are the y values written in a set from smallest to largest

range = {-6,-2,3,5,9}

The range is the set of all y values in the relation


5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 108
5.4. Relation representation
1. Set of ordered pairs
2. Mapping
3. Table
4. Grid graph
5. Binary matrix
6. Directed graph For relations on a set

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 109
5.4. Relation representation: set of ordered pairs

A ________
relation is a set of __________________.
ordered pairs (x, y)

Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

domain is the ______


The ________ set of ______
x values.

range
The ________ set
is the ______ y
of ______ values.
EXAMPLE

Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

-3 ____,
Domain: { ____, -2 ___,
0 ____}
3

-4 , ___,
Range: {____ 5 4
____}

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

2. Mapping:
Domain Range

-3 -4
-2 5
0 4
3

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

3. Table:

domain

range
x y
-3 4
-2 4
0 -4
3 5
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

4. Grid graph:
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }

5. Binary matrix

-3 ____,
Domain a: { ____, -2 0 ____}
___, 3

-4 , ___,
Range b: {____ 5 4
____}
MR = [mij]nm of zeros and ones with n (=4) rows and m (=3)columns
1, if ai R b j
mij  
0, if ai R b j
5.4. Relation representation
6. Directed graph

• Let A = {2, 3, 6, 8, 9}. Consider relation R: a is related to


b iff a is divisible by b. We have:
R = {(2,2), (3,3), (6,2), (6,3), (6,6), (8,2), (8,8), (9,3), (9,9)}.

6
2

8
3

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 116
5.4. Relation representation
Exercise: Given the following table, show the relation as set
of ordered pairs, domain, range and mapping

X -1 0 4 7
Y 3 6 -1 3

Relation = {(-1,3), (0,6), (4,-1), (7,3)}


Domain = {-1, 0, 4, 7}
-1 3
Range = {-1, 3, 6} 0 6
4 -1
7
117
5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 118
5.5. Operations on relations
• A relation is a set. It is a set of ordered pairs if it is a binary relation. Thus all the set
operations apply to relations such as union, intersection and complementing.
Example:
• The union of the "less than" and "equality" relations on the set of integers is the "less
than or equal to" relation on the set of integers.
• The intersection of the "less than" and "less than or equal to" relations on the set of
integers is the "less than" relation on the same set.
• The complement of the "less than" relation on the set of integers is the "greater than
or equal to" relation on the same set.
1. Complementary Relations
2. Inverse Relations
3. Identity relation
4. n-ary Relations
5. Composite Relation

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 119
5.5. Operations on relations
1. Complementary Relations
Let R A×B be a binary relation. Complementary relationR of R is defined as the set
R ≡def {(a,b) | (a,b)  R} = (A×B) − R .
Example:
R   {( a, b ) | ( a, b )  R}  {( a, b ) | a  b}  R .
2. Inverse Relations
Each binary relation R A×B has inverse relation R−1, which defined by
R−1 = {(b,a) | (a,b)R}.
Example1:
(R<)−1 = {(b,a) | a<b} = {(b,a) | b>a} = R>.
Example 2: Let B be the set of jobs, and A be the set of the workers. Consider R as
relation from A to B that defined as follows
aRb  a perform b.
Then b R−1 a  b is performed by a.
Note: We have (R−1)−1 = R.
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 120
5.5. Operations on relations
3. Identity Relation
Identity relation IA on the set A is defined as
IA = {(a, a)| a  A }.
4. n-ary Relations
An n-ary relation on sets A1, ..., An is a set of ordered n-tuples (a1, ..., an) where ai is an
element of Ai for all i, 1 ≤ i ≤ n. Thus an n-ary relation R on sets A1, ..., An is a subset of
Cartesian product A1 A2 ...  An :
R  A1 A2 ...  An.
Note that the sets A1, ..., An are not to be different.
Example: Application of n-ary Relations

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 121
Example: Teaching Assignments
Professor Department Course Number • A relational database models a
Cruz Chemistry 335 database as a relation.
Cruz Chemistry 412 • The relation’s domains are called
Farber Psychology 501 its attributes.
Farber Psychology 617 • How many attributes in the
Grammar Physics 544 Teaching Assignment table?
Grammar Physics 551
Rosen Computer Science 518
Rosen Mathematics 575

The relation’s primary key is an attribute whose value uniquely determines an element in the
relation.
In general, a primary key may consist of > 1 attribute.
What single attribute could serve as the primary key in the Teaching Assignment table?
122
5.5. Operations on relations
5. Composite Relations
Suppose R A×B and S B×C. Composite (or product) relation R  S of two
relations R and S is the following
R  S = {(a,c) | aRb  bSc}
Example: Let A = {1, 2, 3, 4, 5}, B = {a, b, c, d}, C = {, , }. Consider the relations
R, S which are displayed in the following diagram

RS =?

We have: RS = {(1, ), (1,  ), (4, ), (4,  ), (5, ), (5,  )} A×C 123
Example
• Let S be a set of students:
{ Bill, Jill, Will }.
• Let C be a set of courses:
{ 16, 24, 32, 40, 48, 56 }
• Let
R = { ( s, c ) | student s has taken course c }.
• Many students may have taken the same course.
• A student may have taken many courses.
124
Matrix representation of relation R
Relation R: Student s has taken course c
COURSE

S 16 24 32 40 48 56
T
Bill 1 1 0 0 0 0
U
D
Jill 1 1 1 0 0 1
E
N Will 1 0 0 1 0 0
T

( row i, column j ) = 1  student i has taken course j.


125
Matrix representation of relation S
Relation S: Course c has been taught by teacher t
TEACHER
Mike Diana Pete
16 1 1 0
24 1 1 1
COURSE 32 0 1 0
40 0 0 0
48 1 0 1
56 1 0 0
126
S  R = MR X MS“Boolean” matrix product
S  R = { ( s, t ) | c ( sRc  cSt ) }.
Describe in English what S  R represents ?

COURSE TEACHER TEACHER


S S
T 1 1 0 0 0 0 1 1 0 T 1 1 1
U U
1 1 1 0 0 1 C 1 1 1
D
E
O = D 1 1 1
N 1 0 0 1 0 0 U 0 1 0 E
R N
T 0 0 0 T
1 1 0
S
E 1 0 1
1 0 0
127
5. Relations
5.1. Ordered pair
5.2. Cartesian product
5.3. Binary relation
5.4. Relation representation
5.5. Operations on relations
5.6. Properties of relations

128
5.6. Properties of relations
Six properties of relations we will study:
1. Reflexive
2. Irreflexive
3. Symmetric
4. Asymmetric
5. Anti-symmetric
6. Transitive

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 129
5.6. Properties of relations
Let R be a relation on set A. We say that R is:
1. reflexive if and only if a R a for every a  A;
2. irreflexive if and only if its complementary relation is reflexive.
3. symmetric if and only if a R b implies b R a for every a, b  A;
4. asymmetric if and only if (a, b)  R  (b, a)  R (Asymmetry is the opposite of
symmetry)
5. anti-symmetric if and only if a R b and b R a implies a = b for every a, b  A
(Antisymmetry is not the opposite of symmetry)
6. transitive if and only if a R b and b R c implies a R c for every a, b, c  A.
Examples of reflexive relations: = , ≤ , ≥
Examples of irreflexive relations (relations that are not reflexive): < , >
Examples of symmetric relations: =
Examples of asymmetric relations: < , >
Examples of anti-symmetric relations: = , ≤ , ≥
Examples of transitive relations:
• If a < b and b < c, then a < c  Thus, < is transitive
• If a = b and b = c, then a = c  Thus, = is transitive 130
Notes on *symmetric relations
Let R be a relation on set A. We say that R is:
1. symmetric if and only if a R b implies b R a for every a, b  A;
2. asymmetric if and only if (a, b)  R  (b, a)  R (Asymmetry is the
opposite of symmetry)
3. anti-symmetric if and only if a R b and b R a implies a = b for every
a, b  A (Antisymmetry is not the opposite of symmetry)

Example: A relation can be neither symmetric or asymmetric


R = { (a,b) | a=|b| }
– This is not symmetric
-4 is not related to itself
– This is not asymmetric
4 is related to itself
– Note that it is antisymmetric
131
Properties of relations summary

= < > ≤ ≥

Reflexive

Irreflexive

Symmetric

Asymmetric

Antisymmetric

Transitive
132
Properties of relations summary

= < > ≤ ≥

Reflexive X X X

Irreflexive X X

Symmetric X

Asymmetric X X

Antisymmetric X X X

Transitive X X X X X
133
5.6. Properties of relations
Example: Consider the directed graph of a relation R on the set A = {a, b, c, d, e}.
Which of the properties does R satisfy?
1. reflexive if and only if a R a for every
a  A;
2. irreflexive if and only if its
complementary relation is reflexive.
3. symmetric if and only if a R b implies
b R a for every a, b  A;
4. asymmetric if and only if (a, b)  R 
(b, a)  R (Asymmetry is the opposite
of symmetry)
5. anti-symmetric if and only if a R b and
b R a implies a = b for every a, b  A
(Antisymmetry is not the opposite of
symmetry)
6. transitive if and only if a R b and b R
c implies a R c for every a, b, c  A.
134
5.6. Properties of relations
Example: Consider the directed graph of a relation R on the set A = {a, b, c, d, e}.
Which of the properties does R satisfy?

• R is not reflexive, since there is no arrow from d to itself, for example.


• R is symmetric, but not anti-symmetric, since every arrow connecting distinct
points is bidirectional.
• R is not transitive since, for instance, there are arrows from a to d, and from d to
b, but not from a to b. 135
Equivalence relation
Let R be a binary relation on the set S.
• (1) R is reflexive if sRs s  S
• (2) R is symmetric if s1Rs2  s2Rs1 s1,s2  S
• (3) R is transitive if s1Rs2 and s2Rs3  s1Rs3 s1,s2,s3  S
• (4) R is equivalence relation if it is reflexive, symmetric, and transitive

A binary relation is an equivalence relation on a non-empty set S if


and only if the relation is reflexive(R), symmetric(S) and transitive(T).

Example 1: S = {All people}. Define xRy if x has the same parents as y


 R is equivalence relation on S.
Example 2: S = . Define xRy if x <y
As x < x  R is not reflexive  R is not equivalence relation on S.
136
Equivalence relation
Let R be a binary relation on the set S.
• (1) R is reflexive if sRs s  S
• (2) R is symmetric if s1Rs2  s2Rs1 s1,s2  S
• (3) R is transitive if s1Rs2 and s2Rs3  s1Rs3 s1,s2,s3  S
• (4) R is equivalence relation if it is reflexive, symmetric, and transitive

A binary relation is an equivalence relation on a non-empty set S if


and only if the relation is reflexive(R), symmetric(S) and transitive(T).
A binary relation is a partial order if and only if the relation is
reflexive(R), antisymmetric(A) and transitive(T).

137
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations
6. Functions

138
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 139
6. Functions
• Definition: A function f from a set A to a set B, denote it by f: A→B,
is a relation from A to B that satisfies:
– for each element a in A, there is an element b in B such that (a, b) is
in the relation, and
– if (a, b) and (a, c) are in the relation, then b = c.  1 to 1
A function is also called a mapping or a transformation.
The set A in the above definition is called the domain of the function and
B its codomain.
Thus, f is a function if it covers the domain (maps every element of the
domain) and it is single valued.
The relation given by f between a and b represented by the ordered pair
(a, b) is denoted as f(a) = b, and b is called the image of a under f.
• Proposition: If |A| = m, |B| = n, then the number of possible functions
from A to B is nm 140
6. Functions
Thus, f: A→B is a function if it covers the domain (maps every element
of the domain) and it is single valued.

• Single valued: each element in the domain is used only once


• Not allowed: 1 – many and 1 to empty

A B A B A B
-1 -1 3 -1 3
3
0 0 6 0 6
6
4 4 -1 4 -1
-1
7 7 7

Which relation is function? 141


6. Functions
• The image of the set S under function f : A→B, denoted by f(S) is:
f(S) = { f(a) | a  S }
• The image of the domain under function f : A→B, denoted by range f is:
range f = f(A)
(is also called the range of f )
In general case: range f = f(A)  B.

f : A→B
142
6. Functions
Example 1: Let A = {a, b}, B = {1, 2, 3}. Which following
relations from A to B are functions from A to B ?
• P = {(a,1), (b,1)}
• Q = {(a,2), (b,3)}
• S = {(a,1)}
• T = {(a,2), (b,1), (b,3)}

Relation is function if:


• Single valued: each element in the domain is used only once
• Not allowed: 1 – many and 1 to empty

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 143
Example 2: Are the following relations also functions?

0
0
-4 -4
-2
-2
5 5
3
3
8 8
-7
-7

Each element of the 3 is used twice.


domain is only used once.
NOT A
FUNCTION FUNCTION
Example 2: Are the following relations also functions?

145
Example 2: Are the following relations also functions?

Will all vertical lines cross the graph at only one point?

YES. Each x is only used once.


Example 2: Are the following relations also functions?

Will all vertical lines cross the graph at only one point?
NO. x =-2 is used three times.
Example 2: Are the following relations also functions?

x y
-4 0
-2 -3
2 3
-4 1

Are all x values used only once?

NO. x = - 4 is used twice.


6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 149
6.2. Properties of function
f: A→B is a function from a set A to a set B, S A, and T B.
• Property 1: f( S T ) = f(S) f(T)
1. Proof for f(S T ) f(S) f(T):
– Let y be an arbitrary element of f(S T ). Then there is an element x in
S T such that y = f(x). If x is in S, then y is in f(S). Hence y is in f(S)
f(T).
– Similarly y is in f(S) f(T) if x is in T.
– Hence if y f(S T ), then y f(S) f(T).
2. Proof for f(S) f(T) f( S T ) :
– Let y be an arbitrary element of f(S) f(T). Then y is in f(S) or in f(T). If y
is in f(S), then there is an element x in S such that y = f(x). Since x S
implies x S T, f(x) f(S T ).
– Hence y f(S T ).
– Similarly y f(S T ) if y f(T).
Property 1 has been proven.
150
6.2. Properties of function
f: A→B is a function from a set A to a set B, S A, and T B.
• Property 2: f( S ∩ T ) f(S) ∩ f(T)
Proof.
• Let y be an arbitrary element of f(S ∩ T ). Then there is an element x
in S ∩ T such that y = f(x), that is there is an element x which is in S
and in T, and for which y = f(x) holds. Hence y f(S) and y f(T),
that is y f(S) ∩ f(T).
• Note here that the converse of Property 2 does not necessarily hold.
For example let S = {1}, T = {2}, and f(1) = f(2) = {3}. Then f(S ∩ T
) = f() = , while f(S) ∩ f(T) = {3}. Hence f(S) ∩ f(T) cannot be a
subset of f( S ∩ T ) giving a counterexample to the converse of
Property 2.

151
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 152
6.3. Injective, surjective and bijective function
• A function f from a set A to a set B is said to be injective (one-to-one)
if and only if:
for all elements a1, a2  A
if f (a1) = f (a2) then a1 = a2

The function f is not injective The function g is injective


a1, a2  A, a1  a2 f(a1)  f(a2) 153

6.3. Injective, surjective and bijective function
• A function f from a set A to a set B is said to be surjective (onto), if and only
if: bB,  aA: b = f(a).
(read: for any element b  B there is an element a A such that f (a) = b)
that is: f is onto if and only if f( A) = B.
Example: A = {1, 2, 3, 4} and B = {x, y, z}. Then the functions:
f1 = {(1, z), (2, y), (3, x), (4, y)} ; g={(1, x), (2, x), (3, y), (4, y)}

The function f1 is onto The function g is not onto because 154


g(A)={x,y}B
6.3. Injective, surjective and bijective function
• A function is called a bijection, if it is injective (1-1) and
surjective (onto).

155
6.3. Injective, surjective and bijective function
• A function is called a bijection, if it is injective (1-1) and
surjective (onto).

Examples:
1) Linear functions: f(x)=ax+b when a0
(with domain and co-domain R)
2) Exponential functions: f(x)=bx (b>0, b1)
(with domain R and co-domain R+)
3) Logarithmic functions: f(x)=logbx (b>0, b1)
(with domain R+ and co-domain R)

156
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN 157
6.4. Function representation
Functions can be represented four different ways:
mapping
1. ______________
graph
2. ______________
table
3. ______________
matrix
4. ______________
6.4. Function representation
• Let A = {Thắng, Mạnh, Hùng, Cường} and B = {Mai, Mơ,
Mận, Me, Muỗm}. Consider the function f : A → B defined by
the following diagram:

Represent this function by table and matrix

159
6.4. Function representation
• Represent this function by table and matrix

160

You might also like