Professional Documents
Culture Documents
Representing Relations
Epp section ???
CS 202
Aaron Bloomfield
2
In this slide set
Matrix review
Via matrices
1 is true, 0 is false
1
1
1
1
]
1
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
4
Matrix transposition
6 5 4
3 2 1
M
1
1
1
1
]
1
16 15 14 13
12 11 10 9
8 7 6 5
4 3 2 1
M
1
1
1
]
1
6 3
5 2
4 1
t
M
1
1
1
1
]
1
16 12 8 4
15 11 7 3
14 10 6 2
13 9 5 1
t
M
5
Matrix join
1
1
1
1
]
1
1
1
1
1
]
1
0 1 1 1
1 1 0 1
0 1 1 0
0 1 1 1
0 0 1 1
1 1 0 0
0 1 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
6
Matrix meet
1
1
1
1
]
1
1
1
1
1
]
1
0 0 0 1
0 1 0 0
0 0 1 0
0 0 0 0
0 0 1 1
1 1 0 0
0 1 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
7
Matrix Boolean product
1
1
1
1
]
1
1
1
1
1
]
1
1 1 1 0
1 1 1 0
0 1 1 0
0 1 1 0
0 0 1 1
1 1 0 0
0 1 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
1
1
1
1
]
1
1
1
1
1
]
1
1
1
1
1
]
1
0
0 0 1 1
1 1 0 0
0 1 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
1
1
1
1
]
1
1
1
1
1
]
1
1
1
1
1
]
1
0 0 1 1
1 1 0 0
0 1 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 0 1 0
0 0 0 1
8
Relations using matrices
Create a matrix
] [
ij R
m M
'
R b a
R b a
m
j i
j i
ij
) , ( if 0
) , ( if 1
9
Relations using matrices
1 1 0
0 0 0
1 1 0
0 0 1
R
M
CS101 CS201 CS202
Alice
X
Bob
X X
Claire
Dan
X X
10
Relations using matrices
A 2-dimensional array
Let A = { 1, 2, 3, 4, 5 }
1
1
1
1
1
1
]
1
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
M
If the center (main)
diagonal is all 1s, a
relation is reflexive
12
Irreflexivity
Let A = { 1, 2, 3, 4, 5 }
1
1
1
1
1
1
]
1
0 0 0 0 0
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
M
If the center (main)
diagonal is all 0s, a
relation is irreflexive
13
1
1
1
1
1
1
]
1
1 0 0 1 0
0 1 0 0 1
0 0 0 0 1
1 0 0 0 0
0 1 1 0 1
M
Symmetry
Let A = { 1, 2, 3, 4, 5 }
0 0 0 0 0
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
M
Asymmetry
Let A = { 1, 2, 3, 4, 5 }
An asymmetric relation
must also be irreflexive
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
M
Antisymmetry
Let A = { 1, 2, 3, 4, 5 }
Let A = { 1, 2, 3, 4, 5 }
1
1
1
1
1
1
]
1
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
M
Let:
Join:
Meet:
1
1
1
]
1
0 1 0
0 0 1
1 0 1
R
M
1
1
1
]
1
0 0 1
1 1 0
1 0 1
S
M
1
1
1
]
1
0 1 1
1 1 1
1 0 1
S R S R
M M M
1
1
1
]
1
0 0 0
0 0 0
1 0 1
S R S R
M M M
18
Combining relations:
via relation composition
Let:
0 1 0
0 0 1
1 0 1
R
M
1
1
1
]
1
0 0 1
1 1 0
1 0 1
S
M
1
1
1
]
1
0 1 0
1 0 1
1 0 1
S R R S
M M M
a
b
c
d
e
f
d e f g h i
a
b
c
g h i
19
Representing relations using
directed graphs
Old way:
1
2
3
4
1
2
3
4
1 2
3 4
20
Reflexivity
Let A = { 1, 2, 3, 4, 5 }
If every node has a
loop, a relation is
reflexive
1
2
5 3
4
21
Irreflexivity
Let A = { 1, 2, 3, 4, 5 }
If every node does
not have a loop, a
relation is irreflexive
1
2
5 3
4
22
Symmetry
Let A = { 1, 2, 3, 4, 5 }
Let A = { 1, 2, 3, 4, 5 }
Let A = { 1, 2, 3, 4, 5 }
1
2
5 3
4
Let A = { 1, 2, 3, 4, 5 }
1
2
5 3
4
There are n
2
elements in the matrix
There are n elements in the center diagonal
Thus, there are 2
n
ways to fill in 0s and 1s in the diagonal
Thus, there are (n
2
-n)/2 elements in each triangle
Thus, there are ways to fill in 0s and 1s in the triangle
Answer: there are possible symmetric
relations on a set with n elements
1
1
1
1
1
1
]
1
1 0 1
0 0
0 1
1 0 1
2 / ) (
2
2
n n
2 / ) ( 2 / ) (
2 2
2 2 * 2
n n n n n +