Relations
Relations
(Relations)
Pramod Ganapathi
Department of Computer Science
State University of New York at Stony Brook
Problem
Are these functions?
− rational p = rational q
−m<n
− d does not divide n
− n leaves a remainder of 5 when divided by d
− line `1 is parallel to line `2
− person a is a parent of person b
− triangle t1 is congruent to triangle t2
− edge e1 is adjacent to edge e2
− matrix A is orthogonal to matrix B
No! (Because an input is mapped to more than one output.)
What are these mappings called?
Relations!
Functions vs. relations
Relations
congruence modulo
n2 n−2 2n
log x x1/x sin x
orthogonal adjacent
<, >, ≤, ≥
Functions vs. relations
y
100 y
10 x = y2
80
60 5
40 y = x2 x
20 40 60 80 100
20
x -5
-10 -5 5 10
-10
√
y = x2 y=± x
Function? 3 7
Relation? 3 3
Functions vs. relations
y y
10 10
5 5
-10 -5 5 10
x -10 -5 5 10
x
-5 -5
-10 -10
y=x y≥x
Function? 3 7
Relation? 3 3
What is a binary relation?
Definition
If A and B are sets, then a binary relation from A to B
is a subset of A × B.
We say that x is related to y by R, written x R y, if, and only
if, (x, y) ∈ R. Denoted as x R y ⇔ (x, y) ∈ R .
Relationship
Set of all functions is a proper subset of the set of all relations.
Example: Marriage relation
Female
Male
F1
M1
F2
M2
F3
M3
F4
M4
F5
Example: Less than
Problem
A relation L : R → R as follows.
For all real numbers x and y, (x, y) ∈ L ⇔ x L y ⇔ x < y.
Draw the graph of L as a subset of the Cartesian plane R × R.
Solution
L = {(−10.678, 30.23), (17.13, 45.98), (100/9, 200), . . .}
Graph:
Example: Congruence modulo 2
Problem
Define a relation C : Z → Z as follows.
For all (m, n) ∈ Z × Z, m C n ⇔ m − n is even.
Prove that if n is any odd integer, then n C 1.
Solution
A = {(2, 4), (56, 10), (−88, −64), . . .}
B = {(7, 7), (57, 11), (−87, −63), . . .}
C =A∪B
Proof. (n, 1) ∈ C ⇔ n C 1 ⇔ n − 1 is even
Suppose n is odd i.e., n = 2k + 1 for some integer k.
This implies that n − 1 = 2k is even.
Example: Congruence modulo 2
Inverse of a relation
Female Female
Male Male
F1 F1
M1 M1
F2 F2
M2 M2
F3 F3
M3 M3
F4 F4
M4 M4
F5 F5
Inverse of a relation
Definition
Let R be a relation from A to B.
Then inverse relation R−1 from B to A is:
R−1 = {(y, x) ∈ B × A | (x, y) ∈ R} .
For all x ∈ A and y ∈ B,
(x, y) ∈ R ⇔ (y, x) ∈ R−1 .
Example: Inverse of a finite relation
Problem
Let A = {2, 3, 4} and B = {2, 6, 8}.
Let R : A to B. For all (a, b) ∈ A × B, a R b ⇔ a | b
Determine R and R−1 . Draw arrow diagrams for both.
Describe R−1 in words.
Solution
R = {(2, 2), (2, 6), (2, 8), (3, 6), (4, 8)}
R−1 = {(2, 2), (6, 2), (8, 2), (6, 3), (8, 4)}
For all (b, a) ∈ B × A,
(b, a) ∈ R−1 ⇔ b is a multiple of a
Example: Inverse of an infinite relation
Problem
Define a relation R from R to R as follows:
For all (u, v) ∈ R × R, u R v ⇔ v = 2|u|.
Draw the graphs of R and R−1 in the Cartesian plane.
Is R−1 a function?
Solution
R−1 is not a function. Why?
Relation on a set
Definition
A relation on a set A is a relation from A to A.
The resulting arrow diagram is a directed graph possibly con-
taining loops
Example: Relation on a set
Problem
Let A = {3, 4, 5, 6, 7, 8}. Define relation R on A as follows.
For all x, y ∈ A, x R y ⇔ 2|(x − y). Draw the graph of R.
Solution
Reflexivity, symmetry, and transitivity
Properties
Set A = {2, 3, 4, 6, 7, 9}
Relation R on set A is: ∀x, y ∈ A, x R y ⇔ 3 | (x − y)
Reflexivity. ∀x ∈ A, (x, x) ∈ R.
Symmetry. ∀x, y ∈ A, if (x, y) ∈ R, then (y, x) ∈ R.
Transitivity.
∀x, y, z ∈ A, if (x, y) ∈ R and (y, z) ∈ R, then (x, z) ∈ R.
Example
Problem
A = {0, 1, 2, 3}.
R = {(0, 0), (0, 1), (0, 3), (1, 0), (1, 1), (2, 2), (3, 0), (3, 3)}.
Is R reflexive, symmetric, and transitive?
Solution
Reflexive. ∀x ∈ A, (x, x) ∈ R.
Symmetric. ∀x, y ∈ A, if (x, y) ∈ R, then (y, x) ∈ R.
Not transitive. e.g.: (1, 0), (0, 3) ∈ R but (1, 3) 6∈ R.
∃x, y, z ∈ A, if (x, y) ∈ R and (y, z) ∈ R, then (x, z) 6∈ R.
Example
Problem
A = {0, 1, 2, 3}. R = {(0, 0), (0, 2), (0, 3), (2, 3)}.
Is R reflexive, symmetric, and transitive?
Solution
Problem
A = {0, 1, 2, 3}. R = {(0, 1), (2, 3)}.
Is R reflexive, symmetric, and transitive?
Solution
Definition
Relation R on set A is an equivalence relation iff
R is reflexive, symmetric, and transitive.
Equivalence class of element a, denoted by [a], for an equiva-
lence relation is defined as:
[a] = {x ∈ A | (x, a) ∈ R}.
Example: Less than
Problem
Suppose R is a relation on R such that x R y ⇔ x < y.
Is R an equivalence relation?
Solution
Not reflexive. e.g.: 0 6< 0. ∃x ∈ R, x 6< x.
Not symmetric. e.g.: 0 < 1 but 1 6< 0.
∃x, y ∈ R, if x < y, then y 6< x.
Transitive. ∀x, y, z ∈ R, if x < y and y < z, then x < z.
So, R is not an equivalence relation.
Example: Equality (or Identity relation)
Problem
Suppose R is a relation on R such that x R y ⇔ x = y.
Is R an equivalence relation?
Solution
Reflexive. ∀x ∈ R, x = x.
Symmetric. ∀x, y ∈ R, if x = y, then y = x.
Transitive. ∀x, y, z ∈ R, if x = y and y = z, then x = z.
So, R is an equivalence relation.
Equivalence classes: [a] = {a}.
Example: Partition
Problem
Suppose R is a partition relation on A such that
∀x, y ∈ A, x R y ⇔ x, y ∈ Ai for some subset Ai .
A = {0, 1, 2, 3, 4}. Partition of A is {{0, 3, 4}, {1}, {2}}.
Is R an equivalence relation?
Solution
Problem
Suppose R is a partition relation on A such that
∀x, y ∈ A, x R y ⇔ x, y ∈ Ai for some subset Ai .
Is R an equivalence relation?
Solution
Reflexive. ∀m ∈ A, (m, m) ∈ R.
Symmetric. ∀m, n ∈ A, if (m, n) ∈ R, then (n, m) ∈ R.
Transitive.
∀m, n, p ∈ A, if (m, n) ∈ R and (n, p) ∈ R, then (m, p) ∈ R.
So, R is an equivalence relation.
Example: Least element
Problem
Let X denote the power set of {1, 2, 3}.
Suppose R is a relation on X such that ∀A, B ∈ X
A R B ⇔ Least element of A is same as that of B.
Is R an equivalence relation?
Solution
Problem
Suppose R is a relation on Z such that m R n ⇔ 3 | (m − n).
Is R an equivalence relation?
Solution
Reflexive. ∀m ∈ A, 3 | (m − m).
Symmetric. ∀m, n ∈ A, if 3 | (m − n), then 3 | (n − m).
Transitive.
∀m, n, p ∈ A, if 3 | (m − n) and 3 | (n − p), then 3 | (m − p).
So, R is an equivalence relation.
Example: Congruence modulo 3
Solution
Equivalence classes.
Three distinct equivalence classes are [0], [1], and [2].
[0] = {a ∈ Z | a ≡ 0 (mod 3)} = {0, ±3, ±6, ±9, . . .}
[1] = {a ∈ Z | a ≡ 1 (mod 3)} = {1, 1 ± 3, 1 ± 6, 1 ± 9, . . .}
[2] = {a ∈ Z | a ≡ 2 (mod 3)} = {2, 2 ± 3, 2 ± 6, 2 ± 9, . . .}
Intuition.
[0] = Set of integers when divided by 3 leave a remainder of 0.
[1] = Set of integers when divided by 3 leave a remainder of 1.
[2] = Set of integers when divided by 3 leave a remainder of 2.
Congruence modulo n
Definition
Let a and b be integers and n be a positive integer.
The following statements are equivalent:
a and b leave the same remainder when divided by n.
a mod n = b mod n.
n | (a − b).
a is congruent to b modulo n.
a ≡ b (mod n)
a = b + kn for some integer k.
Examples
12 ≡ 7 (mod 5)
6 ≡ −6 (mod 4)
3 ≡ 3 (mod 7)
Example: Congruence modulo n
Problem
Suppose R is a relation on Z such that
a R b ⇔ a ≡ b (mod n).
Is R an equivalence relation?
Solution
Reflexive. ∀a ∈ Z, a ≡ a (mod n).
Symmetric.
∀a, b ∈ Z, if a ≡ b (mod n), then b ≡ a (mod n).
Transitive.
∀a, b, c ∈ Z, if a ≡ b (mod n) and b ≡ c (mod n), then
a ≡ c (mod n).
So, R is an equivalence relation.
Equivalence classes: [0], [1], . . . , [n − 1].
Example: Congruence modulo n
Solution
R is Reflexive. Show that ∀a ∈ Z, n | (a − a). We know that
a − a = 0 and n | 0. Hence, n | (a − a).
R is Symmetric. Show that ∀a, b ∈ Z, if a ≡ b (mod n),
then b ≡ a (mod n). We see that a ≡ b (mod n) means
n | (a − b).
Let (a − b) = nk, for some integer k.
=⇒ −(a − b) = −nk (multiply both sides by -1)
=⇒ (b − a) = n(−k) (simplify)
=⇒ n | (b − a) (−k is an integer; use defn. of divisibility)
In other words, b ≡ a (mod n).
Example: Congruence modulo n
Solution
R is transitive. Show that ∀a, b, c ∈ Z, if a ≡ b (mod n) and
b ≡ c (mod n), then a ≡ c (mod n).
We see that a ≡ b (mod n) and b ≡ c (mod n) imply that
n | (a − b) and n | (b − c), respectively.
Let (a − b) = nk and (b − c) = n`, for some integers k and `.
Adding the two equations, we get
(a − c) = (k + `)n, where k + ` is an integer because addition
is closed on integers.
By definition of divisibility, n | (a − c) or a ≡ c (mod n).
Modular arithmetic
Modular arithmetic
Let a, b, c, d, n be integers with n > 1.
Suppose a ≡ c (mod n) and b ≡ d (mod n). Then
1. (a + b) ≡ (c + d) (mod n)
2. (a − b) ≡ (c − d) (mod n)
3. (ab) ≡ (cd) (mod n)
4. (am ) ≡ (cm ) (mod n) for all positive integers m
Units digit
Problem
What is the units digit of 14838650 ?
Solution
Units digit of 14838650 is the units digit of 38650 .
Units digit of 30 , 31 , 32 , 33 , and 34 are
1, 3, 9, 7, and 1, respectively.
Periodicity is 4. Therefore,
Units digit of 34k+0 is 1.
Units digit of 34k+1 is 3.
Units digit of 34k+2 is 9.
Units digit of 34k+3 is 7.
Units digit of 38650 = 34×2162+2 is 9.
Hence, the answer is 9.
Equation solving
Problem
Use modular arithmetic to solve the equations.
16x + 12y = 32 and 40x − 9y = 7.
Solution
Apply mod 3 on both sides of the first equation.
(16x + 12y) mod 3 ≡ 32 mod 3
=⇒ x ≡ 2 mod 3
Similarly, apply mod 3 on both sides of the second equation.
(40x − 9y) mod 3 ≡ 7 mod 3
=⇒ x ≡ 1 mod 3
These two congruences are contradictory.
Hence, the system of equations does not have a solution.
Universal product code (UPC)
Problem
The first eleven digits of the UPC for a package of ink cartridges
are 88442334010. What is the check digit?
Solution
k = 3(8 + 4 + 2 + 3 + 0 + 0) + (8 + 4 + 3 + 4 + 1) = 71
check digit = (210 − 71) mod 10 = 9