Relations and Functions
Relations and Functions
Properties
1
What is a relation
• Let A and B be sets. A binary relation R is a subset of
AB
• Example
– Let A be the students in class
• A = {Alice, Bob, Claire, Dan}
– Let B be the courses the NIBM 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 = { (Alice, CS101), (Bob, CS201), (Bob, CS202),
(Dan, CS201), (Dan, CS202) }
2
Representing relations
We can represent We can represent
relations graphically: relations in a table:
CS101 CS201 CS202
Alice
CS101
Alice X
Bob Bob X X
CS201
Claire
Claire
Dan X X
CS202
Dan
4
Is a relation a function?
•Focus on the x-coordinates, when given a relation
5
Example
{(0, −5),(1, −4),(2, −3),(3, −2),(4, −1),(5, 0)}
YES
6
Example
{(–1, −7),(1, 0),(2, −3),(0, −8),(0, 5),(–2, −1)}
NO
7
Example
Which mapping represents a function?
Choice 1
8
Example 6
Which mapping represents a function?
A. B.
B
9
Relations vs. functions
• Not all relations are functions
• But consider the following function:
a 1
b 2
c 3
d 4
10
When to use which?
• A function is used when you need to obtain a
SINGLE result for any element in the domain
– Example: sin, cos, tan
11
Review
• A relation between two variables x and y is a
set of ordered pairs
• An ordered pair consist of a x and y-
coordinate
– A relation may be viewed as ordered pairs,
mapping design, table, equation, or written in
sentences
• x-values are inputs, domain, independent
variable
• y-values are outputs, range, dependent
variable
12
Example 1
Input 4 –5 0 9 –1
Output –2 7
15
Relations on a set
• Let A be the set { 1, 2, 3, 4 }
• Which ordered pairs are in the relation R = { (a,b) | a divides b }
• R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4) }
1 1 R 1 2 3 4
1 X X X X
2 2
2 X X
3 3 3 X
4 X
4 4 16
More examples
• Consider some relations on the set Z
• Are the following ordered pairs in the relation?
17
Relation properties
• Six properties of relations we will study:
– Reflexive
– Irreflexive
– Symmetric
– Asymmetric
– Antisymmetric
– Transitive
18
Reflexivity
• A relation is reflexive if every element is related
to itself
– Or, (a,a)R
19
Irreflexivity
• A relation is irreflexive if every element is not related to
itself
– Or, (a,a)R
– Irreflexivity is the opposite of reflexivity
20
Reflexivity vs. Irreflexivity
• A relation can be neither reflexive nor irreflexive
– Some elements are related to themselves, others are
not
• We will see an example of this later on
21
Symmetry
• A relation is symmetric if, for every (a,b)R, then (b,a)R
22
Asymmetry
• A relation is asymmetric if, for every (a,b)R,
then (b,a)R
– Asymmetry is the opposite of symmetry
25
Transitivity
• A relation is transitive if, for every (a,b)R and
(b,c)R, then (a,c)R
• If a = b and b = c, then a = c
– Thus, = is transitive
26
Transitivity examples
• Consider isAncestorOf()
– Let Alice be Bob’s parent, and Bob be Claire’s parent
– Thus, Alice is an ancestor of Bob, and Bob is an ancestor of
Claire
– Thus, Alice is an ancestor of Claire
– Thus, isAncestorOf() is a transitive relation
• Consider isParentOf()
– Let Alice be Bob’s parent, and Bob be Claire’s parent
– Thus, Alice is a parent of Bob, and Bob is a parent of Claire
– However, Alice is not a parent of Claire
– Thus, isParentOf() is not a transitive relation
27
Relations 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
28