0% found this document useful (0 votes)
34 views45 pages

6 Relations

The document discusses the concept of relations in mathematics and computer science, highlighting their applications in relational databases and artificial intelligence. It explains various types of relations, including binary relations, one-to-one, one-to-many, many-to-one, and many-to-many relations, along with their properties such as reflexive, symmetric, and transitive. Additionally, it covers methods for representing relations using matrices and directed graphs.

Uploaded by

CHA ZI YU Moe
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)
34 views45 pages

6 Relations

The document discusses the concept of relations in mathematics and computer science, highlighting their applications in relational databases and artificial intelligence. It explains various types of relations, including binary relations, one-to-one, one-to-many, many-to-one, and many-to-many relations, along with their properties such as reflexive, symmetric, and transitive. Additionally, it covers methods for representing relations using matrices and directed graphs.

Uploaded by

CHA ZI YU Moe
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/ 45

Relations

WIX1001 Computing MATHEMATICS 1


Relations: You, your courses and
your friends

2 / 45
Why we learn Relations

There are many applications in
Computer Science

The most widely used database system,
relational database is based on
relational model.

In artificial intelligence, some inference
systems are based on relational theory

Function is a special type of relation

3 / 45
Relations as Tables
Student Course
Bill Mathematics
Mary Introduction to IT
Bill Introduction to IT
Dave Introduction to IT
Mary Mathematics
Jane Mathematics

X = { Bill, Mary, Y = { Mathematics,


Dave, Jane } Introduction to IT }

4 / 45
Sets and Relations

Students, X Courses, Y

Relation

Domain Range
5 / 45
Binary Relations

A binary relation is a relation from a set X to a
set Y.

Example: X is Students, Y is Courses,

R is a relation “Enroll”

It is a subset of Cartesian product X x Y

Assume x ∈ X and y ∈ Y,

(x,y) ∈ R means x is in relation R with y. We
can write xRy.

6 / 45
Example
Student, X Course, Y

Bill Mathematics
Mary Introduction to IT
Bill Introduction to IT
Dave Introduction to IT
Mary Mathematics
Jane Mathematics

R = { (Bill, Mathematics), (Mary, Introduction to IT),


(Bill, Introduction to IT), (Dave, Introduction to IT),
(Mary, Mathematics), (Jane, Mathematics) }

(Bill, Mathematics) ∈ R Bill R Mathematics


7 / 45
Ordered Pair
(a,b) ≠ (b,a) unless a=b

(a,b) is an ordered pair.


We also can write (a,b) as a~b

Example:
R : Bill ~ Mathematics, Mary ~ Introduction to IT,
Bill ~ Introduction to IT,
Dave ~ Introduction to IT,
Mary ~ Mathematics, Jane ~ Mathematics

8 / 45
4 Types of Relations

One to One
One to Many
Many to One
Many to many

9 / 45
One to one relation

A relation A→B is one-to-one relation if no two


elements of A is paired with the same element
in B

10 / 45
One to Many relation

A relation A→B is one-to-many relation if an


element of A is related to 2 or more elements of
B

11 / 45
Many to One relation

A relation A→B is a many-to one relation if 2 or


more elements of A are related to 1 element of
B.

12 / 45
Many to Many relation

A relation A→B is many-to-many relation if 2 or


more elements of A are related to 2 or more
elements of B

13 / 45
Relations on a Set

A relation on the set A is a relation
from A to A.

In other words, a relation on the set A
is a subset of A X A.
RÍAXA

14 / 45
Relations on a Set

Example: Let A = {1, 2, 3, 4}
► If R = A x A,
► R = {(1,1), (1,2), (1,3), (1,4), (2,1), (2,2), (2,3),
(2,4) ... }

But, most of the time, R with conditions.

For example, if R = {(a, b) | a < b}
R = {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)}

15 / 45
Composite of Relations

Let a∈A, b∈B and c∈C,
and R⊆AxB , S⊆BxC

We can combine the relation R and S
together.

The composition of R and S is denoted
as S o R.
SoR⊆AxC

16 / 45
Example

Given
A = {1, 2, 3, 4}, B = {a, b, c, d}, C = {x, y, z)
R = {(1, a), (2, d), (3, a), (3, b), (3, d)}
S = {(b, x), (b, z), (c, y), (d, z)}


SoR=?

17 / 45
Example

Given
A = {1, 2, 3, 4}, B = {a, b, c, d}, C = {x, y, z)
R = {(1, a), (2, d), (3, a), (3, b), (3, d)}
S = {(b, x), (b, z), (c, y), (d, z)}

We can find:
(b, x) o (3, b) = (3, x)
(b, z) o (3, b) = (3, z)

S o R = {(2, z), (3, x), (3, z)}

18 / 45
Example 2
Let D and S be relations on A = {1, 2, 3, 4}
Given: D = {(a, b) | b=5−a}
S = {(a, b) | a < b}
where both a,b∈A. Find S o D

19 / 45
Example 2
Let D and S be relations on A = {1, 2, 3, 4}
Given: D = {(a, b) | b=5−a}
S = {(a, b) | a < b}
where both a,b∈A. Find S o D

First, please note that:


A x A = { (1, 1), (1, 2), (1, 3), (1, 4),
(2, 1), (2, 2), (2, 3), (2, 4),
(3, 1), (3, 2), (3, 3), (3, 4),
(4, 1), (4, 2), (4, 3), (4, 4) }

And both D,S are subsets of AXA

20 / 45
Example 2
Let D and S be relations on A = {1, 2, 3, 4}
Given: D = {(a, b) | b=5−a}
S = {(a, b) | a < b}
where both a,b∈A. Find S o D
A x A = { (1, 1), (1, 2), (1, 3), (1, 4),
(2, 1), (2, 2), (2, 3), (2, 4),
(3, 1), (3, 2), (3, 3), (3, 4),
Find elements in A x A (4, 1), (4, 2), (4, 3), (4, 4) }
that satisfy D:

D = { (1,4), (2,3), (3,2), (4,1) }

21 / 45
Example 2
Let D and S be relations on A = {1, 2, 3, 4}
Given: D = {(a, b) | b=5−a}
S = {(a, b) | a < b}
where both a,b∈A. Find S o D
A x A = { (1, 1), (1, 2), (1, 3), (1, 4),
(2, 1), (2, 2), (2, 3), (2, 4),
(3, 1), (3, 2), (3, 3), (3, 4),
Find elements in A x A (4, 1), (4, 2), (4, 3), (4, 4) }
that satisfy S:

S = { (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4) }

22 / 45
Example 2
Let D and S be relations on A = {1, 2, 3, 4}
Given: D = {(a, b) | b=5−a}
S = {(a, b) | a < b}
where both a,b∈A. Find S o D
D = { (1,4), (2,3), (3,2), (4,1) }
S = { (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4) }

S o D = { (2, 4),(3, 3),(3, 4),(4, 2),(4, 3),(4, 4) }

23 / 45
Inverse Relations

The inverse of a relation R from A to B is
denoted R-1 , and defined from B to A as:
R−1 = { (b, a) | (a, b) ∈ R }

Example:

24 / 45
Representing Relations Using Matrix

A way to represent relations is by using the Zero – One


Matrix

If R is a relation from A={a1, a2 , ..., am} to B = {b1, b2, ...,


bn}, then R can be represented by the zero-one matrix:
MR = [mij ]
with mij = 1 if (ai, bj) ∈ R
mij = 0 if (ai, bj) Ï R

Note that for creating this matrix we first need to list the
elements in A and B in order
25 / 45
Example

Suppose that A={1, 2, 3} and B={1, 2}. Let R
be the relation from A to B containing (a,b) if
a∈A, b∈B , and a>b. How can we represent
the relation R={(2,1), (3,1), (3,2)} as a zero-
one matrix?

Solution: a=1

a=2

a=3

b=1 b=2
26 / 45
Representing Relations using Directed
Graphs (Digraphs)

When R is a relation on a set A, we can
draw it using a directed graph.

A directed graph consists of a set V of
vertices (or nodes), and a set E of
ordered pairs of elements of V called
edges (or arcs).

27 / 45
Example

If R = {(1,1), (2,4), (3,2), (4,1), (4,3)},
then its directed graph is:

28 / 45
Properties of Relation

A relation may hold the following properties:
► Reflexive
► Symmetric
► Transitive
► Equivalence

29 / 45
Reflexive Relations

For all x ∈ X, a relation R on a set X is :
► Reflexive if (x,x) ∈ R
► Not reflexive otherwise

30 / 45
Reflexive Relations

For all x ∈ X, a relation R on a set X is :
► Reflexive if (x,x) ∈ R
► Not reflexive otherwise

Example:
The relation R on {1,2,3} given by
R = {(1,1), (2,2), (2,3), (3,3)}
is reflexive.

31 / 45
Examples

Example:
Is R = {(1,1), (2,2), (3,3)} reflexive on
{1,2,3,4}?
Answer:


Example:
X = {1, 2, 3, 4} and (a,b) ∈ R if a ≥ b .
R is ____________ relation.
32 / 45
Examples

Example:
Is R = {(1,1), (2,2), (3,3)} reflexive on
{1,2,3,4}?
Answer: No, because missing of (4,4), R is
not reflexive.


Example:
X = {1, 2, 3, 4} and (a,b) ∈ R if a ≥ b .
R is a reflexive relation.
33 / 45
Symmetric Relations

For all a,b ∈ X, a relation R on a set X is :
► symmetric if (a,b) ∈ R then (b,a) ∈ R
► antisymmetric if (a,b) ∈ R and (b,a) ∈ R
only when a=b
► not symmetric otherwise

34 / 45
Symmetric Relations

For all a,b ∈ X, a relation R on a set X is :
► symmetric if (a,b) ∈ R then (b,a) ∈ R
► antisymmetric if (a,b) ∈ R and (b,a) ∈ R
only when a=b
► not symmetric otherwise

Example:
► The relation R on {1, 2, 3} given by

R = {(1,1), (1,2), (2,1), (1,3), (3,1)} is


symmetric.
35 / 45
Example

Example:
Why is R = {(1,2), (2,1), (3,1)} not symmetric?
Solution: Because ___________

36 / 45
Example

Example:
Why is R = {(1,2), (2,1), (3,1)} not symmetric?
Solution: Because (1,3) is missing


Example:
X = {1, 2, 3 } and
R = {(1,1), (1,3), (3,1), (2,3) , (3,2), (3,3) }
R is a _______ relation.

37 / 45
Example

Example:
Why is R = {(1,2), (2,1), (3,1)} not symmetric?
Solution: Because (1,3) is missing


Example:
X = {1, 2, 3 } and
R = {(1,1), (1,3), (3,1), (2,3) , (3,2), (3,3) }
R is a symmetric relation.

38 / 45
Transitive Relations

For all a,b,c ∈ X, a relation R on a set X is :
► transitive if (a,b) ∈ R and (b,c) ∈ R, then
(a,c) ∈ R
► not transitive otherwise

39 / 45
Transitive Relations

For all a,b,c ∈ X, a relation R on a set X is :
► transitive if (a,b) ∈ R and (b,c) ∈ R, then
(a,c) ∈ R
► not transitive otherwise

Example:
The relation R on {1,2,3} given by
R = {(1,1), (1,2), (2,1), (2,2), (2,3), (1,3)} is
transitive.

40 / 45
Examples

Example:
Why is R = {(1,2), (2,3), (1,3), (2,1)} not
transitive?
Because ______________________ .


Example:
X is real numbers and (x,y) ∈ R if x < y .
R is a ___________ relation.

41 / 45
Examples

Example:
Why is R = {(1,2), (2,3), (1,3), (2,1)} not
transitive?
Because (1,1) and (2,2) are missing


Example:
X is real numbers and (x,y) ∈ R if x < y .
R is a transitive relation.

42 / 45
Exercise

Determine whether each R defined on
the set of positive integers is reflexive,
symmetric and/or transitive.
► (x,y) ∈ R if x = y2
► (x,y) ∈ R if x > y

► (x,y) ∈ R if 3 divides x - y

43 / 45
Equivalence Relation

A relation R on a set X is called
equivalence relation if R is:
1) reflexive,
2) symmetric, and
3) transitive.

44 / 45
Example

Consider the relation

R = {(1,1), (1,3), (1,5), (2,2), (2,4), (3,1), (3,3),
(3,5), (4,2), (4,4), (5,1), (5,3), (5,5)}
on X = {1,2,3,4,5}.


The relation is reflexive

The relation is symmetric

The relation is transitive

Conclusion: Equivalence Relation
45 / 45

You might also like