Upcoming SlideShare
×

05 - Relations

750 views

Published on

I used this set of slides for the lecture on Relations I gave at the University of Zurich for the 1st year students following the course of Formale Grundlagen der Informatik.

Published in: Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
750
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
6
0
Likes
1
Embeds 0
No embeds

No notes for slide

05 - Relations

1. 1. Relations www.tudorgirba.com
2. 2. Wax on … wax off … these are the basics http://www.youtube.com/watch?v=3PycZtfns_U
3. 3. Sets www.tudorgirba.com
4. 4. computer information information computation
5. 5. Set A set is a group of objects.
6. 6. Set A set is a group of objects. {10, 23, 32} N = {0, 1, 2, … } Z = {… , -2, -1, 0, 1, 2, … } Ø U empty set universe
7. 7. Set A set is a group of objects. {10, 23, 32} N = {0, 1, 2, … } Z = {… , -2, -1, 0, 1, 2, … } 10 ∈ {10, 23, 32} -1 ∉ N Ø U empty set universe Membership a is a member of set A
8. 8. Subset A⊆B ∀x:: x∈A x∈B Every member of A is also an element of B.
9. 9. Subset A⊆B ∀x:: x∈A x∈B ∅ ⊆ A. A ⊆ A. A = B A ⊆ B ∧ B ⊆ A. Every member of A is also an element of B.
10. 10. Subset A⊆B ∀x:: x∈A x∈B ∅ ⊆ A. A ⊆ A. A = B A ⊆ B ∧ B ⊆ A. Proper subset A⊂B ∀x:: A⊆B ∧ A≠B A is a subset of B and not equal to B. Every member of A is also an element of B.
11. 11. Union A∪B ∀x:: x∈A ∨ x∈B A∪B={ x | x∈A or x∈B }
12. 12. Union A∪B ∀x:: x∈A ∨ x∈B A∪B={ x | x∈A or x∈B }
13. 13. Union A∪B ∀x:: x∈A ∨ x∈B A∪B={ x | x∈A or x∈B } A ∪ B = B ∪ A. A ∪ (B ∪ C) = (A ∪ B) ∪ C. A ⊆ (A ∪ B). A ∪ A = A. A ∪ ∅ = A. A ⊆ B A ∪ B = B.
14. 14. Intersection A∩B ∀x:: x∈A ∧ x∈B A∩B={ x | x∈A and x∈B }
15. 15. Intersection A∩B ∀x:: x∈A ∧ x∈B A∩B={ x | x∈A and x∈B }
16. 16. Intersection A∩B ∀x:: x∈A ∧ x∈B A∩B={ x | x∈A and x∈B } A ∩ B = B ∩ A. A ∩ (B ∩ C) = (A ∩ B) ∩ C. A ∩ B ⊆ A. A ∩ A = A. A ∩ ∅ = ∅. A ⊆ B A ∩ B = A.
17. 17. Complements AB, A’ ∀x:: x∈A ∧ x∉B AB={ x | x∈A and x∉B }
18. 18. Complements AB, A’ ∀x:: x∈A ∧ x∉B AB={ x | x∈A and x∉B } A B ≠ B A. A ∪ A′ = U. A ∩ A′ = ∅. (A′)′ = A. A A = ∅. U′ = ∅. ∅′ = U. A B = A ∩ B′.
19. 19. A ∩ U = A A ∪ ∅ = A Neutral elements
20. 20. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements
21. 21. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence
22. 22. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence A ∪ B = B ∪ A A ∩ B = B ∩ A Commutativity
23. 23. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence A ∪ B = B ∪ A A ∩ B = B ∩ A Commutativity A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∪ (B ∪ C) = (A ∪ B) ∪ C Associativity
24. 24. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence A ∪ B = B ∪ A A ∩ B = B ∩ A Commutativity A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∪ (B ∪ C) = (A ∪ B) ∪ C Associativity A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) Distributivity
25. 25. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence A ∩ A’ = ∅ A ∪ A’ = U Complement A ∪ B = B ∪ A A ∩ B = B ∩ A Commutativity A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∪ (B ∪ C) = (A ∪ B) ∪ C Associativity A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) Distributivity
26. 26. Similar to boolean algebra a ∧ 1 = a a ∨ 0 = a Neutral elements a ∧ 0 = 0 a ∨ 1 = 1 Zero elements a ∧ a = a a ∨ a = a Idempotence a ∧ ¬ a = 0 a ∨ ¬ a = 1 Negation a ∨ b = b ∨ a a ∧ b = b ∧ a Commutativity a ∧ (b ∧ c) = (a ∧ b) ∧ c a ∨ (b ∨ c) = (a ∨ b) ∨ c Associativity a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c) a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c) Distributivity
27. 27. A ∩ U = A A ∪ ∅ = A Neutral elements A ∩ ∅ = ∅ A ∪ U = U Zero elements A ∩ A = A A ∪ A = A Idempotence A ∩ A’ = ∅ A ∪ A’ = U Complement A ∪ B = B ∪ A A ∩ B = B ∩ A Commutativity A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∪ (B ∪ C) = (A ∪ B) ∪ C Associativity A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) Distributivity
28. 28. A ∩ U = A A ∪ B = B ∪ A A ∪ ∅ = A A ∩ ∅ = ∅ A ∪ U = U A ∩ A = A A ∪ A = A A ∩ A’ = ∅ A ∪ A’ = U Neutral elements Zero elements Idempotence Complement A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∩ B = B ∩ A A ∪ (B ∪ C) = (A ∪ B) ∪ C A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) (A ∩ B)’ = (A’) ∪ (B’) (A ∪ B)’ = (A’) ∩ (B’) Commutativity Associativity Distributivity DeMorgan’s
29. 29. A ⊆ A. A ⊆ B ∧ B ⊆ A A = B. A ⊆ B ∧ B ⊆ C A ⊆ C Reﬂexivity Anti-symmetry Transitivity
30. 30. Relations www.tudorgirba.com
31. 31. Scissors Paper Stone
32. 32. Scissors Paper Stone beats beats beats
33. 33. Scissors Paper Stone beats beats beats beats Scissors Paper Stone Scissors FALSE TRUE FALSE Paper FALSE FALSE TRUE Stone TRUE FALSE FALSE
34. 34. beats Scissors Paper Stone Scissors FALSE TRUE FALSE Paper FALSE FALSE TRUE Stone TRUE FALSE FALSE beats = {(Scissors, Paper), (Paper, Stone), (Stone, Scissors)}
35. 35. beats Scissors Paper Stone Scissors FALSE TRUE FALSE Paper FALSE FALSE TRUE Stone TRUE FALSE FALSE beats = {(Scissors, Paper), (Paper, Stone), (Stone, Scissors)} beats ⊆ {Scissor, Paper, Stone} x {Scissor, Paper, Stone}
36. 36. Cartesian product AxB AxB={ (a,b) | a∈A and b∈B }
37. 37. Cartesian product AxB AxB={ (a,b) | a∈A and b∈B } A × ∅ = ∅. A × (B ∪ C) = (A × B) ∪ (A × C). (A ∪ B) × C = (A × C) ∪ (B × C).
38. 38. N-ary Relation A1, A2, ..., An R ⊆ A1 x A2 x...x An
39. 39. Binary Relation A1, A2 R ⊆ A1 x A2 (a,b) ∈ R aRb
40. 40. Binary Relation A1, A2 R ⊆ A1 x A2 (a,b) ∈ R aRb
41. 41. Binary Relation A1, A2 R ⊆ A1 x A2 (a,b) ∈ R aRb dom R = {a⏐∃b :: (a,b) ∈ R} range R = {b⏐∃a :: (a,b) ∈ R}
42. 42. Reﬂexive relation every element x of A is in relation R with itself
43. 43. ∀x: x∈A: xRx Reﬂexive relation every element x of A is in relation R with itself
44. 44. Symmetric relation if there is a relation between x and y, then there is a relation between y and x ∀x: x∈A: xRx Reﬂexive relation every element x of A is in relation R with itself
45. 45. Symmetric relation if there is a relation between x and y, then there is a relation between y and x ∀x: x∈A: xRx ∀x,y: x,y∈A: xRy yRx Reﬂexive relation every element x of A is in relation R with itself
46. 46. Transitive relation ... Symmetric relation if there is a relation between x and y, then there is a relation between y and x ∀x: x∈A: xRx ∀x,y: x,y∈A: xRy yRx Reﬂexive relation every element x of A is in relation R with itself
47. 47. Transitive relation ... Symmetric relation if there is a relation between x and y, then there is a relation between y and x ∀x: x∈A: xRx ∀x,y: x,y∈A: xRy yRx ∀x,y,z: x,y,z∈A: (xRy ∧ yRz) xRz Reﬂexive relation every element x of A is in relation R with itself
48. 48. Transitive relation ... Symmetric relation if there is a relation between x and y, then there is a relation between y and x Equivalentrelation ∀x: x∈A: xRx ∀x,y: x,y∈A: xRy yRx ∀x,y,z: x,y,z∈A: (xRy ∧ yRz) xRz Reﬂexive relation every element x of A is in relation R with itself
49. 49. Examples = >, < ≥, ≤ beats
50. 50. Examples = >, < ≥, ≤ beats reﬂexive, symmetric, transitive transitive reﬂexive, transitive -
51. 51. [x]R= {y | xRy} Equivalence class
52. 52. [x]R= {y | xRy} Equivalence class [1]= =
53. 53. [x]R= {y | xRy} Equivalence class [1]= = {1}
54. 54. Example Consider the relation ≡5 over the integer numbers Z deﬁned as x≡5y if and only if x-y is a multiple of 5 (where x,y∈Z). Is ≡5 an equivalence relation?
55. 55. Example Consider the relation ≡5 over the integer numbers Z deﬁned as x≡5y if and only if x-y is a multiple of 5 (where x,y∈Z). Is ≡5 an equivalence relation? What is [1]≡5 ?
56. 56. R ⊆ AxA {(a,b), (b,c), (c,d)}
57. 57. a b c d R ⊆ AxA {(a,b), (b,c), (c,d)}
58. 58. a b c d R ⊆ AxA {(a,b), (b,c), (c,d)}
59. 59. a b c d R ⊆ AxA {(a,b), (b,c), (c,d)}
60. 60. a b c d R ⊆ AxA {(a,b), (b,c), (c,d)}
61. 61. a b c d R ⊆ AxA {(a,b), (b,c), (c,d)} R1 = R; ∀i:i>1:Ri = Ri-1 ∪ {(a,b) | ∃c:: (a,c)∈Ri-1 ∧ (c,b)∈Ri-1}. Rt = ∪i≥1Ri = R1 ∪ R2 ∪ R3 ∪ ... Transitive closure
62. 62. Irreﬂexive relation no element x of A is in relation R with itself
63. 63. ∀x: x∈A: ¬(xRx) Irreﬂexive relation no element x of A is in relation R with itself
64. 64. Antisymmetric relation if there is a relation between x and y and one between y and x, then x equals y ∀x: x∈A: ¬(xRx) Irreﬂexive relation no element x of A is in relation R with itself
65. 65. Antisymmetric relation if there is a relation between x and y and one between y and x, then x equals y ∀x: x∈A: ¬(xRx) ∀x,y: x,y∈A: (xRy ∧ yRx) x=y Irreﬂexive relation no element x of A is in relation R with itself
66. 66. Asymmetric relation xRy and yRx cannot hold at the same time Antisymmetric relation if there is a relation between x and y and one between y and x, then x equals y ∀x: x∈A: ¬(xRx) ∀x,y: x,y∈A: (xRy ∧ yRx) x=y Irreﬂexive relation no element x of A is in relation R with itself
67. 67. Asymmetric relation xRy and yRx cannot hold at the same time Antisymmetric relation if there is a relation between x and y and one between y and x, then x equals y ∀x: x∈A: ¬(xRx) ∀x,y: x,y∈A: (xRy ∧ yRx) x=y ∀x,y: x,y∈A: xRy ¬(yRx) Irreﬂexive relation no element x of A is in relation R with itself
68. 68. Examples = >, < ≥, ≤ beats
69. 69. Examples = >, < ≥, ≤ beats antisymmetric irreﬂexive, asymmetric antisymmetric irreﬂexive
70. 70. Non-symmetric relation a relation that is not symmetric
71. 71. ∀x,y: x,y∈A: (xRy) ∧ ¬(yRx) Non-symmetric relation a relation that is not symmetric
72. 72. ∀x,y: x,y∈A: (xRy) ∧ ¬(yRx) Non-symmetric relation a relation that is not symmetric Total relation R is deﬁned on the entire A.
73. 73. ∀x,y: x,y∈A: (xRy) ∧ ¬(yRx) Non-symmetric relation a relation that is not symmetric ∀x,y: x,y∈A: xRy ∨ yRx Total relation R is deﬁned on the entire A.
74. 74. Examples = >, < ≥, ≤ beats
75. 75. Examples = >, < ≥, ≤ beats - non-symmetric non-symmetric, total -
76. 76. Acyclic relation there are no elements with transitive closure to themselves
77. 77. Acyclic relation there are no elements with transitive closure to themselves ∀n: n∈N: ( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) )
78. 78. Acyclic relation there are no elements with transitive closure to themselves ∀n: n∈N: ( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) ) >, <
79. 79. Acyclic relation there are no elements with transitive closure to themselves ∀n: n∈N: ( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) ) >, < acyclic
80. 80. R is partial order; R is total relation. Total order R is reflexive; R is transitive; R is antisymmetric. Partial order R is reflexive; R is transitive. Strict partial order
81. 81. A, B F ⊆ A x B (a,b)∈F ∧ (a,c)∈F b=c domF = A F:A -> B Function
82. 82. A, B F ⊆ A x B (a,b)∈F ∧ (a,c)∈F b=c domF = A F:A -> B Function FºG(x) = F(G(x)) Function composition
83. 83. Tudor Gîrba www.tudorgirba.com creativecommons.org/licenses/by/3.0/