License

c 2001-2016 T. Uyar, A. Yayımlı, E. Harmancı Discrete Mathematics You are free to: Relations and Functions I Share – copy and redistribute the material in any medium or format I Adapt – remix, transform, and build upon the material Under the following terms:

H. Turgut Uyar Ay¸segul¨ Gen¸cata Yayımlı Emre Harmancı I Attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. I NonCommercial – You may not use the material for commercial purposes. 2001-2016 I ShareAlike – If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. For more information: https://creativecommons.org/licenses/by-nc-sa/4.0/ Read the full license: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode

1 / 79 2 / 79

Topics

Relations Introduction Definition Relation Properties relation: α ⊆ A × B × C × · · · × N Equivalence Relations I tuple: of relation

Functions I : α ⊆ A × B Introduction I aαb :(a, b) ∈ α Pigeonhole Principle Recursion

3 / 79 4 / 79 Relation Example Relation Composition

Definition A = {a , a , a , a }, B = {b , b , b } 1 2 3 4 1 2 3 relation composition: α = {(a , b ), (a , b ), (a , b ), (a , b ), (a , b ), (a , b ), (a , b )} 1 1 1 3 2 2 2 3 3 1 3 3 4 1 α ⊆ A × B, β ⊆ B × C αβ = {(a, c) | a ∈ A, c ∈ C, ∃b ∈ B [aαb ∧ bβc]} b b b 1 2 3 1 0 1 a 1 0 1 1 0 1 1 example a 0 1 1 M = 2 α 1 0 1 a 1 0 1 3 1 0 0 a4 1 0 0

5 / 79 6 / 79

Relation Composition Relation Composition Associativity

(αβ)γ = α(βγ). I Mαβ = Mα × Mβ

I using logical operations: 1 : T 0 : F · : ∧ + : ∨ (a, d) ∈ (αβ)γ example ⇔ ∃c [(a, c) ∈ αβ ∧ (c, d) ∈ γ] ⇔ ∃c [∃b [(a, b) ∈ α ∧ (b, c) ∈ β] ∧ (c, d) ∈ γ] 1 0 0 1 1 0 0 ⇔ ∃b [(a, b) ∈ α ∧ ∃c [(b, c) ∈ β ∧ (c, d) ∈ γ]] 0 0 1 1 1 0 0 0 1 1 0 ⇔ ∃b [(a, b) ∈ α ∧ (b, d) ∈ βγ] Mα = 0 1 1 Mβ = 0 0 1 1 Mαβ = 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 ⇔ (a, d) ∈ α(βγ) 1 0 1 1 1 1 0

7 / 79 8 / 79 Relation Composition Theorems Converse Relation

α(β ∪ γ) = αβ ∪ αγ.

(a, c) ∈ α(β ∪ γ) Definition ⇔ ∃b [(a, b) ∈ α ∧ (b, c) ∈ (β ∪ γ)] α−1 = {(b, a) | (a, b) ∈ α} ⇔ ∃b [(a, b) ∈ α ∧ ((b, c) ∈ β ∨ (b, c) ∈ γ)] T M −1 = M ⇔ ∃b [((a, b) ∈ α ∧ (b, c) ∈ β) I α α ∨ ((a, b) ∈ α ∧ (b, c) ∈ γ)] ⇔ (a, c) ∈ αβ ∨ (a, c) ∈ αγ ⇔ (a, c) ∈ αβ ∪ αγ

9 / 79 10 / 79

Converse Relation Theorems Converse Relation Theorems

α−1 = α−1.

−1 −1 I (α ) = α −1 −1 −1 −1 I (α ∪ β) = α ∪ β (b, a) ∈ α −1 −1 −1 I (α ∩ β) = α ∩ β ⇔ (a, b) ∈ α −1 −1 I α = α ⇔ (a, b) ∈/ α −1 −1 −1 −1 I (α − β) = α − β ⇔ (b, a) ∈/ α ⇔ (b, a) ∈ α−1

11 / 79 12 / 79 Converse Relation Theorems Converse Relation Theorems

−1 −1 −1 (α ∩ β) = α ∩ β . (α − β)−1 = α−1 − β−1.

(b, a) ∈ (α ∩ β)−1 (α − β)−1 = (α ∩ β)−1 ⇔ (a, b) ∈ (α ∩ β) −1 = α−1 ∩ β ⇔ (a, b) ∈ α ∧ (a, b) ∈ β = α−1 ∩ β−1 ⇔ (b, a) ∈ α−1 ∧ (b, a) ∈ β−1 = α−1 − β−1 ⇔ (b, a) ∈ α−1 ∩ β−1

13 / 79 14 / 79

Relation Composition Converse Relation Properties

Theorem (αβ)−1 = β−1α−1 I α ⊆ A × A Proof. n I α : αα ··· α

I identity relation: E = {(a, a) | a ∈ A} (c, a) ∈ (αβ)−1 ⇔ (a, c) ∈ αβ I reflexivity ⇔ ∃b [(a, b) ∈ α ∧ (b, c) ∈ β] I symmetry ⇔ ∃b [(b, a) ∈ α−1 ∧ (c, b) ∈ β−1] I transitivity ⇔ (c, a) ∈ β−1α−1

15 / 79 16 / 79 Reflexivity Reflexivity Examples

reflexive α ⊆ A × A R1 ⊆ {1, 2} × {1, 2} R2 ⊆ {1, 2, 3} × {1, 2, 3} ∀a ∈ A [aαa] R1 = {(1, 1), (1, 2), (2, 2)} R2 = {(1, 1), (1, 2), (2, 2)}

I E ⊆ α I R1 is reflexive I R2 is not reflexive

I irreflexive: I also not irreflexive ∀a ∈ A [¬(aαa)]

17 / 79 18 / 79

Reflexivity Examples Reflexivity Examples

R ⊆ {1, 2, 3} × {1, 2, 3} R ⊆ Z × Z R = {(1, 2), (2, 1), (2, 3)} R = {(a, b) | ab ≥ 0}

I R is irreflexive I R is reflexive

19 / 79 20 / 79 Symmetry Symmetry Examples

symmetric R ⊆ {1, 2, 3} × {1, 2, 3} α ⊆ A × A R = {(1, 2), (2, 1), (2, 3)} ∀a, b ∈ A [aαb ↔ bαa]

−1 I R is not symmetric I α = α I also not antisymmetric I antisymmetric: ∀a, b ∈ A [aαb ∧ bαa → a = b]

21 / 79 22 / 79

Symmetry Examples Symmetry Examples

R ⊆ Z × Z R ⊆ {1, 2, 3} × {1, 2, 3} R = {(a, b) | ab ≥ 0} R = {(1, 1), (2, 2)} R is symmetric and antisymmetric I R is symmetric I

23 / 79 24 / 79 Transitivity Transitivity Examples

transitive α ⊆ A × A R ⊆ {1, 2, 3} × {1, 2, 3} ∀a, b, c ∈ A [aαb ∧ bαc → aαc] R = {(1, 2), (2, 1), (2, 3)}

α2 ⊆ α I I R is antitransitive I antitransitive: ∀a, b, c ∈ A [aαb ∧ bαc → ¬(aαc)]

25 / 79 26 / 79

Transitivity Examples Converse Relation Properties

R ⊆ Z × Z R = {(a, b) | ab ≥ 0} Theorem Reflexivity, symmetry, and transitivity are preserved I R is not transitive in the converse relation. I also not antitransitive

27 / 79 28 / 79 Closures Special Relations

I reflexive closure: predecessor - successor r = α ∪ E α R ⊆ Z × Z R = {(a, b) | a − b = 1} I symmetric closure: −1 sα = α ∪ α I irreflexive transitive closure: I I antisymmetric S i 2 3 tα = i=1,2,3,... α = α ∪ α ∪ α ∪ · · · I antitransitive

29 / 79 30 / 79

Special Relations Special Relations

adjacency strict order R ⊆ Z × Z R ⊆ Z × Z R = {(a, b) | |a − b| = 1} R = {(a, b) | a < b}

I irreflexive I irreflexive

I symmetric I antisymmetric

I antitransitive I transitive

31 / 79 32 / 79 Special Relations Special Relations

partial order R ⊆ × Z Z R ⊆ × R = {(a, b) | a ≤ b} Z Z R = {(a, b) | |a| ≤ |b|}

I reflexive I reflexive I antisymmetric I transitive I transitive

33 / 79 34 / 79

Special Relations Special Relations

limited difference comparability + R ⊆ Z × Z, m ∈ Z R ⊆ U × U R = {(a, b) | |a − b| ≤ m} R = {(a, b) | (a ⊆ b) ∨ (b ⊆ a)}

I reflexive I reflexive

I symmetric I symmetric

35 / 79 36 / 79 Special Relations Compatibility Relations

Definition I siblings? compatibility relation: γ

I reflexive I irreflexive I symmetric I symmetric

I transitive I when drawing, lines instead of arrows

I matrix representation as a triangle matrix I can a relation be symmetric and transitive, but irreflexive? −1 I αα is a compatibility relation

37 / 79 38 / 79

Compatibility Relation Example Compatibility Relation Example

I P: persons, L: languages

I P = {p1, p2, p3, p4, p5, p6}

A = {a1, a2, a3, a4} 1 1 0 0 I L = {l1, l2, l3, l4, l5} 1 1 0 1 R = {(a1, a1), (a2, a2), I α ⊆ P × L 0 0 1 1 (a3, a3), (a4, a4), 0 1 1 1 1 1 0 0 0 (a1, a2), (a2, a1), 1 1 0 1 0 0 1 1 0 0 0 (a , a ), (a , a ), 1 1 0 0 0 1 2 4 4 2 0 0 1 0 1 1 M = M −1 = 0 0 1 1 0 1 (a3, a4), (a4, a3)} α 1 0 1 1 0 α 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0

39 / 79 40 / 79 Compatibility Relation Example Compatibility Block

Definition −1 I αα ⊆ P × P compatibility block: C ⊆ A ∀a, b [a ∈ C ∧ b ∈ C → aγb] 1 1 0 1 0 1

1 1 0 1 0 1 I maximal compatibility block: 0 0 1 1 0 1 not a subset of another compatibility block M −1 = αα 1 1 1 1 1 1 I an element can be a member of more than one MCB 0 0 0 1 1 0 1 1 1 1 0 1 I complete cover: Cγ set of all MCBs

41 / 79 42 / 79

Compatibility Block Example Equivalence Relations

Definition C = {p , p } I 1 4 6 :  I C2 = {p2, p4, p6} I reflexive I C3 = {p1, p2, p4, p6} (MCB) I symmetric

I transitive

Cγ = {{p1, p2, p4, p6}, I equivalence classes (partitions)

{p3, p4, p6}, I every element is a member of exactly one equivalence class {p4, p5}} I complete cover: C

43 / 79 44 / 79 Equivalence Relation Example References

Required Reading: Grimaldi R ⊆ Z × Z Chapter 5: Relations and Functions R = {(a, b) | ∃m ∈ Z [a − b = 5m]} I I 5.1. Cartesian Products and Relations

I Chapter 7: Relations: The Second Time Around I R partitions Z into 5 equivalence classes I 7.1. Relations Revisited: Properties of Relations I 7.4. Equivalence Relations and Partitions

45 / 79 46 / 79

Functions Subset Image Examples

Definition : f : X → Y ∀x ∈ X ∀y1, y2 ∈ Y [(x, y1), (x, y2) ∈ f → y1 = y2] f : R → R f (x) = x2 I X : domain, Y : codomain (or range) f (Z) = {0, 1, 4, 9, 16,... } I y = f (x):(x, y) ∈ f f ({−2, 1}) = {1, 4} I y: image of x under f

0 I f : X → Y , X ⊆ X subset image: f (X 0) = {f (x) | x ∈ X 0}

47 / 79 48 / 79 One-to-One Functions One-to-One Function Examples

I one-to-one I not one-to-one Definition f : R → R g : Z → Z f : X → Y is one-to-one (or injective): f (x) = 3x + 7 g(x) = x4 − x ∀x1, x2 ∈ X [f (x1) = f (x2) → x1 = x2] 4 f (x1) = f (x2) g(0) = 0 − 0 = 0 4 ⇒ 3x1 + 7 = 3x2 + 7 g(1) = 1 − 1 = 0 ⇒ 3x1 = 3x2 ⇒ x1 = x2

49 / 79 50 / 79

Onto Functions Onto Function Examples

Definition

f : X → Y is onto (or surjective): I onto I not onto ∀y ∈ Y ∃x ∈ X [f (x) = y] f : R → R f : Z → Z I f (X ) = Y f (x) = x3 f (x) = 3x + 1

51 / 79 52 / 79 Bijective Functions

Definition f : X → Y , g : Y → Z Definition g ◦ f : X → Z f : X → Y is bijective: (g ◦ f )(x) = g(f (x)) f is one-to-one and onto

I not commutative

I associative: f ◦ (g ◦ h) = (f ◦ g) ◦ h

53 / 79 54 / 79

Composition Commutativity Example Composite Function Theorems

f : R → R Theorem f (x) = x2 f : X → Y , g : Y → Z f is one-to-one ∧ g is one-to-one ⇒ g ◦ f is one-to-one g : R → R g(x) = x + 5 Proof.

g ◦ f : R → R (g ◦ f )(x1) = (g ◦ f )(x2) 2 (g ◦ f )(x) = x + 5 ⇒ g(f (x1)) = g(f (x2)) ⇒ f (x ) = f (x ) f ◦ g : → 1 2 R R ⇒ x = x (f ◦ g)(x) = (x + 5)2 1 2

55 / 79 56 / 79 Composite Function Theorems

Theorem f : X → Y , g : Y → Z Definition f is onto ∧ g is onto ⇒ g ◦ f is onto identity function: 1X

Proof. 1X : X → X ∀z ∈ Z ∃y ∈ Y g(y) = z 1X (x) = x ∀y ∈ Y ∃x ∈ X f (x) = y ⇒ ∀z ∈ Z ∃x ∈ X g(f (x)) = z

57 / 79 58 / 79

Inverse Function Examples

f : R → R f (x) = 2x + 5 Definition f : X → Y is invertible: f −1 : → −1 −1 −1 R R ∃f : Y → X [f ◦ f = 1X ∧ f ◦ f = 1Y ] −1 x−5 f (x) = 2 −1 I f : inverse of function f −1 −1 −1 (2x+5)−5 2x (f ◦ f )(x) = f (f (x)) = f (2x + 5) = 2 = 2 = x −1 −1 x−5 x−5 (f ◦ f )(x) = f (f (x)) = f ( 2 ) = 2 2 + 5 = (x − 5) + 5 = x

59 / 79 60 / 79 Inverse Function Invertible Function

Theorem If a function is invertible, its inverse is unique.

Proof. Theorem f : X → Y A function is invertible if and only if it is one-to-one and onto. g, h : Y → X g ◦ f = 1X ∧ f ◦ g = 1Y h ◦ f = 1X ∧ f ◦ h = 1Y

h = h ◦ 1Y = h ◦ (f ◦ g) = (h ◦ f ) ◦ g = 1X ◦ g = g

61 / 79 62 / 79

Invertible Function Invertible Function

If bijective then invertible. If invertible then one-to-one. If invertible then onto. f : X → Y f : X → Y f : X → Y I f is onto ⇒ ∀y ∈ Y ∃x ∈ X f (x) = y f (x1) = f (x2) y I let g : Y → X be defined by x = g(y) −1 −1 ⇒ f (f (x1)) = f (f (x2)) = 1Y (y) −1 −1 −1 I is it possible that g(y) = x1 6= x2 = g(y)? ⇒ (f ◦ f )(x1) = (f ◦ f )(x2) = (f ◦ f )(y) −1 I this would mean: f (x1) = y = f (x2) ⇒ 1X (x1) = 1X (x2) = f (f (y)) I but f is one-to-one ⇒ x1 = x2

63 / 79 64 / 79 Pigeonhole Principle Pigeonhole Principle Examples

Definition pigeonhole principle (Dirichlet drawers): I Among 367 people, at least two have the same birthday. If m pigeons go into n holes and m > n, then at least one hole contains more than one pigeon. I In an exam where the grades are integers between 0 and 100, how many students have to take the exam to make sure that I f : X → Y at least two students will have the same grade? |X | > |Y | ⇒ f is not one-to-one

I ∃x1, x2 ∈ X [x1 6= x2 ∧ f (x1) = f (x2)]

65 / 79 66 / 79

Generalized Pigeonhole Principle Pigeonhole Principle Example

Definition generalized pigeonhole principle: If m objects are distributed to n drawers, Theorem then at least one of the drawers contains dm/ne objects. S = {1, 2, 3,..., 9}, T ⊂ S, |T | = 6 ∃s1, s2 ∈ T [s1 + s2 = 10] example Among 100 people, at least d100/12e = 9 were born in the same month.

67 / 79 68 / 79 Pigeonhole Principle Example Pigeonhole Principle Example

Theorem + S ⊆ Z , ∀a ∈ S [a ≤ 14], |S| = 6 T = P(S) − ∅ Theorem X = {Σ | A ∈ T }, Σ : sum of the elements in A A A S = {1, 2, 3,..., 200}, T ⊂ S, |T | = 101 |X | < |T | ∃s1, s2 ∈ T [s2|s1] first, show that: Proof Attempt Proof. I ∀n ∃!p [n = 2r p ∧ r ∈ ∧ ∃t ∈ [p = 2t + 1]] consider T − S N Z I holes: I then, use this to prove the main theorem 1 ≤ ΣA ≤ 9 + ··· + 14 = 69 I holes: 6 1 ≤ sA ≤ 10 + ··· + 14 = 60 I pigeons: 2 − 1 = 63 6 I pigeons: 2 − 2 = 62

69 / 79 70 / 79

Pigeonhole Principle Example Pigeonhole Principle Example

Theorem Theorem r ∀n ∃!p [n = 2 p ∧ r ∈ N ∧ ∃t ∈ Z [p = 2t + 1]] S = {1, 2, 3,..., 200}, T ⊂ S, |T | = 101 ∃s1, s2 ∈ T [s2|s1] Proof of existence. Proof of uniqueness. Proof. n = 1: r = 0, p = 1 if not unique: P = {p | p ∈ S, ∃i ∈ [p = 2i + 1]}, |P| = 100 n ≤ k: assume n = 2r p I Z r n = k + 1: I f : S → P, r ∈ N, s = 2 p → f (s) = p n = 2r1 p = 2r2 p n = 2 : r = 1, p = 1 1 2 I |T | = 101 ⇒ at least two elements have the same image in P: r1−r2 ⇒ 2 p = p r1 r2 n prime (n > 2) : r = 0, p = n 1 2 f (s1) = f (s2) ⇒ 2 p = 2 p ⇒ 2|p ¬(n prime): n = n1n2 2 r1 r1 r2 s1 2 p n = 2 p1 · 2 p2 r1−r2 = r = 2 r1+r2 s 2 2 p n = 2 · p1p2 2

71 / 79 72 / 79 Recursive Functions Recursion Examples

Definition recursive function: a function defined in terms of itself ( n − 10 if n > 100 f (n) = h(f (m)) f 91(n) = f 91(f 91(n + 11)) if n ≤ 100

I inductively defined function: a recursive function where the size is reduced at every step ( 1 if n = 0 n! = ( n · (n − 1)! if n > 0 k if n = 0 f (n) = h(f (n − 1)) if n > 0

73 / 79 74 / 79

Greatest Common Divisor Fibonacci Sequence

( b if b | a gcd(a, b) = gcd(b, a mod b) if b a -  1 if n = 1  Fn = fib(n) = 1 if n = 2 gcd(333, 84) = gcd(84, 333 mod 84) fib(n − 2) + fib(n − 1) if n > 2 = gcd(84, 81)

= gcd(81, 84 mod 81) F1 F2 F3 F4 F5 F6 F7 F8 ... = gcd(81, 3) 1 1 2 3 5 8 13 21 ... = 3

75 / 79 76 / 79 Fibonacci Sequence Ackermann Function

Theorem Pn 2 i=1 Fi = Fn · Fn+1

Proof.  n = 2 : P2 F 2 = F 2 + F 2 = 1 + 1 = 1 · 2 = F · F y + 1 if x = 0 i=1 i 1 2 2 3  Pk 2 ack(x, y) = ack(x − 1, 1) if y = 0 n = k : i=1 Fi = Fk · Fk+1 ack(x − 1, ack(x, y − 1)) if x > 0 ∧ y > 0 Pk+1 2 Pk 2 2 n = k + 1 : i=1 Fi = i=1 Fi + Fk+1 2 = Fk · Fk+1 + Fk+1

= Fk+1 · (Fk + Fk+1)

= Fk+1 · Fk+2

77 / 79 78 / 79

References

Required Reading: Grimaldi

I Chapter 5: Relations and Functions

I 5.2. Functions: Plain and One-to-One I 5.3. Onto Functions: Stirling Numbers of the Second Kind I 5.5. The Pigeonhole Principle I 5.6. Function Composition and Inverse Functions

79 / 79