Definition
A binary relation R from set A to set B is a subset of A×B:
R⊆A×B
If (a,b)∈R, we write aRb or R(a,b).
A relation on A is a relation from A to A: R⊆A×A.
Representations
Set of Ordered Pairs
R={(1,2),(1,3),(2,3)}
Matrix Representation
For A={a1,…,am} and B={b1,…,bn}:
MR[i,j]={10if (ai,bj)∈Rotherwise
Digraph (Directed Graph)
- Vertices represent elements
- Directed edge from a to b if aRb
Properties of Relations on a Set
Reflexive
Every element is related to itself:
∀a∈A:(a,a)∈R
Matrix: All diagonal entries are 1.
Digraph: Every vertex has a self-loop.
Irreflexive
No element is related to itself:
∀a∈A:(a,a)∈/R
Symmetric
If a is related to b, then b is related to a:
∀a,b∈A:(a,b)∈R→(b,a)∈R
Matrix: MR=MRT (symmetric matrix).
Digraph: Every edge has a reverse edge.
Antisymmetric
If a is related to b and b is related to a, then a=b:
∀a,b∈A:((a,b)∈R∧(b,a)∈R)→a=b
Equivalently: If a=b and (a,b)∈R, then (b,a)∈/R.
Asymmetric
If a is related to b, then b is not related to a:
∀a,b∈A:(a,b)∈R→(b,a)∈/R
Note: Asymmetric implies irreflexive and antisymmetric.
Transitive
If a is related to b and b is related to c, then a is related to c:
∀a,b,c∈A:((a,b)∈R∧(b,c)∈R)→(a,c)∈R
Examples
"Less than" on Z
| Property | < |
|---|
| Reflexive | No (a<a) |
| Symmetric | No (a<b⇒b<a) |
| Antisymmetric | Yes (vacuously) |
| Transitive | Yes |
"Divides" on Z+
a∣b means a divides b (i.e., b=ka for some integer k)
| Property | ∣ |
|---|
| Reflexive | Yes (a∣a) |
| Symmetric | No (2∣4 but 4∤2) |
| Antisymmetric | Yes (on Z+) |
| Transitive | Yes |
Combining Relations
Union
R1∪R2={(a,b)∣(a,b)∈R1∨(a,b)∈R2}
Intersection
R1∩R2={(a,b)∣(a,b)∈R1∧(a,b)∈R2}
Complement
R={(a,b)∣(a,b)∈/R}
Inverse
R−1={(b,a)∣(a,b)∈R}
Composition of Relations
If R is from A to B and S is from B to C:
S∘R={(a,c)∣∃b∈B:(a,b)∈R∧(b,c)∈S}
Matrix Representation
If MR and MS are relation matrices:
MS∘R=MR⊙MS
where ⊙ is Boolean matrix multiplication.
Powers of a Relation
R1=R
Rn+1=Rn∘R
Closure of Relations
The closure adds the minimum pairs to make a relation have a property.
Reflexive Closure
r(R)=R∪{(a,a)∣a∈A}=R∪IA
Symmetric Closure
s(R)=R∪R−1
Transitive Closure
t(R)=R∪R2∪R3∪⋯=⋃i=1∞Ri
For finite set with ∣A∣=n:
t(R)=⋃i=1nRi
Warshall's Algorithm
Computes transitive closure efficiently in O(n3):
for k = 1 to n:
for i = 1 to n:
for j = 1 to n:
M[i,j] = M[i,j] OR (M[i,k] AND M[k,j])