CmSc175 Discrete Mathematics
Lesson 14: Set Relations
1. Introduction
A college cafeteria line has two stations: main courses and desserts. The main course
station offers spaghetti or fish; the dessert station offers pie or cake. Three students Ann,
Paul, and Tom, go through the line and make the following choices:
Ann: spaghetti, pie
Tom: fish, pie, cake
Paul: spaghetti, fish, pie
Ann
Tom
Paul
Main course
spaghetti
fish
X
X
X
X
Desserts
pie
cake
X
X
X
X
This table describes a relation between the set of persons {Ann, Tom, Paul} and the set
of food items {spaghetti, fish, pie, cake}
Let
A = {Ann, Tom, Paul}
B = { spaghetti, fish, pie, cake }
Each checked box in the table corresponds to a pair (a,b), a ∈ A, b ∈ B.
The relation is given by the set of all such pairs:
R = {(Ann, spaghetti), (Ann, pie),
(Tom, fish), (Tom, pie), (Tom, cake),
(Paul, spaghetti), (Paul, fish), (Paul, pie) }
Consider the Cartesian product of A and B:
A x B = {(Ann, spaghetti), (Ann, fish), (Ann, pie), (Ann, cake),
(Tom, spaghetti), (Tom, fish), (Tom, pie), (Tom, cake),
(Paul, spaghetti), (Paul, fish), (Paul, pie), (Paul, cake)}
The relation R is a subset of A x B.
1
2. Definition
Let A and B be two sets. A relation R from A to B is any set of pairs (x,y),
x є A, y є B, i.e. any subset of A x B.
If x and y are in relation R, we write xRy, or (x,y) ∈ R..
R is a set defined as
R = {(x,y) | x ∈ A, y ∈ B, xRb.}
3. Relations and Cartesian products
Relations between two sets A and B are sets of pairs of elements of A and B.
The Cartesian product A x B consists of all pairs of elements of A and B.
Thus relations between two sets are subsets of the Cartesian product of the sets.
Example:
Let
A = {1, 3, 4, 5}
B = {2, 7, 8}
The relation R1 :"less than" from set A to set B is defined by the following set:
R1 = {(1, 2), (1, 7), (1, 8), (3, 7), (3, 8), (4, 7), (4, 8), (5, 7), (5, 8)}
This set is a subset of the Cartesian product of A and B:
A x B = {(1,2),(1,7),(1,8),
(3,2), (3,7), (3,8),
(4,2), (4,7), (4,8),
(5,2),(5,7),(5,8)}
(the members of R1 are in boldface)
The relation R2: "greater than" from set A to set B is defined by the set:
R2 = {(3, 2), (4, 2), (5, 2)}
It is also a subset of A x B.
The relation R3 "equal to" from A to B is the empty set, since no element in A is equal to
an element in B.
2
Relations can be defined between three or more sets.
Example:
A = set of students in a college
B = set of courses
C = set of professors
R = {(student , course, professor) | student is registered for course taught by professor}
In general:
If we have n sets, we can build their Cartesian product.
Any subset of the Cartesian product gives some relation between the elements of the sets.
The Cartesian product is called universal relation between the sets.
If n = 2 the relation is called binary relation
4. Representing relations as tables and matrices.
Consider the relation
Main course
spaghetti
fish
X
X
X
X
Ann
Tom
Paul
pie
X
X
X
Desserts
cake
X
The example shows how relations can be represented by tables.
A table can be converted into a matrix, by dropping the headings.
If a relation between two elements holds, we write 1 in the matrix, if not - we write 0.
Hence the above relation can be represented also as:
1
0
1
0
1
1
1
1
1
0
1
0
This representation is very useful for computer processing.
3
5. Relations and predicates
Predicates describe properties and relations.
(usually properties are considered to be unary relations)
Thus we can specify a relation between n sets using n-ary predicate a predicate with n arguments.
For the above example we can define the predicate
choose(x,y) , where x is in the set of students, and y is in the set of items,
to be true if student x has chosen item y and false otherwise.
Thus choose(Ann, pie) will be true, while choose(Ann, cake) will be false.
Using predicates allows us to apply the predicate calculus apparatus to process relations.
In particular we can apply logic programming languages for processing relations.
6. Relations and directed graphs
Graphs are defined as sets of objects called nodes and links between the objects.
Example:
Nodes: a, b, c, d
Links: (a,b), (a,c), (b,d)
Obviously, if A is the set of objects, we can consider the set of links as a subset of A x A.
For example, A can be the set of all towns in a state, and
R -the relation "connected by a freeway"
In directed graphs the links have orientation, i.e. (a,b) ≠ (b,a)
Example:
Let A = {2, 3, 6, 8, 12}
Let R be a relation on A: xRy iff y is a multiple of x, y ≠ x.
R can be represented as a directed graph:
2
6
12
3
8
4
If the relation is defined between two different sets, the nodes in the graph would belong
to the union of these sets. The "cafeteria" example can be represented by the following
graph:
Ann
spaghetti
fish
Tom
pie
Paul
cake
7. Domains and ranges
Let R be a relation from X to Y,
the domain of R is the set of all elements in X that occur in at least one pair of the
relation,
the range of R is the set of all elements in Y that occur in at least one pair of the relation.
In the above example, the domain of R: choose(x,y) is the set of students {Ann, Tom ,
Paul}, and the range is the set of food items: {spaghetti, fish, pie, cake}.
The domain and the range are easily found using the matrix or the graph representations
of the relation.
5
Summary
1. Definition
Let A and B be two sets. A relation R from A to B is any set of pairs (x,y),
x є A, y є B, i.e. any subset of A x B.
The empty set is a subset of the Cartesian product – the empty relation
2. How to write relations
a. as set of pairs
A = {1,2,3}, {B = 4,5,6}
R = {{1,4), (1,5), (1,6), (2,4), (2,6), (3,6)}
b. using predicates
A = {1,2,3}, {B = 4,5,6}
R = {(x,y) | x ∈ A, y ∈ B, y is a multiple of x}
3. Graph and matrix representation
A = {1,2,3}, {B = 4,5,6}
R = {{1,4), (1,5), (1,6), (2,4), (2,6), (3,6)}
1
2
3
4
1
1
0
5
1
0
0
6
1
1
1
6
Problems
Let A = {1,2,3,4} and R be a relation on A defined as follows:
R = {(x,y) | x2 ≥ y, x, y ∈ A}
1. write the relation as a binary matrix
2. write the relation as a directed graph (digraph)
For each problem below, determine the domain and the range and write the relation as a
set of pairs
1)
Domain:
Range:
a
b
c
d
write the relation as a set of pairs:
7
2)
Domain:
Range
1
2
3
4
5
write the relation as a set of pairs:
3)
Domain:
Range:
1
2
write the relation as a set of pairs:
8
4)
Domain:
Range:
a
b
c
write the relation as a set of pairs
9
Solutions
Let A = {1,2,3,4} and R be a relation on A defined as follows:
R = {(x,y) | x2 ≥ y, x, y ∈ A}
1. Write the relation as a binary matrix
1
1
1
1
1
1
2
3
4
2
0
1
1
1
3
0
1
1
1
4
0
1
1
1
2. Write the relation as a directed graph (digraph)
1
3
2
4
For each problem: determine the domain and the range and write the relation as a set of
pairs
1): Domain: {a, b, c}
Range: {a, b, c, d}
a
b
c
d
write the relation as a set of pairs: {(a,b), (a, c), (b, a), (b, d), (c,c), (c,d)}
10
2): Domain:
{1, 2, 3, 4, 5}
Range{1, 2, 3, 4, 5}
1
2
3
4
5
write the relation as a set of pairs: {(1, 1), (2, 2), (3, 3), (3, 5), (4, 4), (4, 3), (5, 5), (5, 4)}
3): Domain:
∅
Range: ∅
1
2
write the relation as a set of pairs: the relation is the empty relation : R = ∅
11
5): Domain:
{a, b, c}
a
Range: {a, b, c}
b
c
write the relation as a set of pairs: {(a, b), (b, a), (c, c)}
12
© Copyright 2026 Paperzz