05 - Relations

88
Relations www.tudorgirba.com

description

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.

Transcript of 05 - Relations

Page 1: 05 - Relations

Relations

www.tudorgirba.com

Page 3: 05 - Relations
Page 4: 05 - Relations
Page 6: 05 - Relations

computerinformation information

computation

Page 7: 05 - Relations

SetA set is a group of objects.

Page 8: 05 - Relations

SetA set is a group of objects.

{10, 23, 32}

N = {0, 1, 2, … }

Z = {… , -2, -1, 0, 1, 2, … }

Ø

U

empty set

universe

Page 9: 05 - Relations

SetA 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

Membershipa is a member of set A

Page 10: 05 - Relations

Subset A⊆B

∀x:: x∈A ⇒ x∈B

Every member of A is also an element of B.

Page 11: 05 - Relations

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.

Page 12: 05 - Relations

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.

Page 13: 05 - Relations

Union A∪B

∀x:: x∈A ∨ x∈BA∪B={ x | x∈A or x∈B }

Page 14: 05 - Relations

Union A∪B

∀x:: x∈A ∨ x∈BA∪B={ x | x∈A or x∈B }

Page 15: 05 - Relations

Union A∪B

∀x:: x∈A ∨ x∈BA∪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.

Page 16: 05 - Relations

Intersection A∩B

∀x:: x∈A ∧ x∈BA∩B={ x | x∈A and x∈B }

Page 17: 05 - Relations

Intersection A∩B

∀x:: x∈A ∧ x∈BA∩B={ x | x∈A and x∈B }

Page 18: 05 - Relations

Intersection A∩B

∀x:: x∈A ∧ x∈BA∩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.

Page 19: 05 - Relations

Complements A\B, A’

∀x:: x∈A ∧ x∉BA\B={ x | x∈A and x∉B }

Page 20: 05 - Relations

Complements A\B, A’

∀x:: x∈A ∧ x∉BA\B={ 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′.

Page 21: 05 - Relations
Page 22: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

Page 23: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

Page 24: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

Page 25: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

A ∪ B = B ∪ AA ∩ B = B ∩ A

Commutativity

Page 26: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

A ∪ B = B ∪ AA ∩ B = B ∩ A

Commutativity

A ∩ (B ∩ C) = (A ∩ B) ∩ CA ∪ (B ∪ C) = (A ∪ B) ∪ C

Associativity

Page 27: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

A ∪ B = B ∪ AA ∩ B = B ∩ A

Commutativity

A ∩ (B ∩ C) = (A ∩ B) ∩ CA ∪ (B ∪ C) = (A ∪ B) ∪ C

Associativity

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

Distributivity

Page 28: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

A ∩ A’ = ∅

A ∪ A’ = U

Complement

A ∪ B = B ∪ AA ∩ B = B ∩ A

Commutativity

A ∩ (B ∩ C) = (A ∩ B) ∩ CA ∪ (B ∪ C) = (A ∪ B) ∪ C

Associativity

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

Distributivity

Page 29: 05 - Relations

Similar to boolean algebra

a ∧ 1 = aa ∨ 0 = a

Neutral elements

a ∧ 0 = 0a ∨ 1 = 1

Zero elements

a ∧ a = aa ∨ a = a

Idempotence

a ∧ ¬ a = 0a ∨ ¬ a = 1

Negation

a ∨ b = b ∨ aa ∧ b = b ∧ a

Commutativity

a ∧ (b ∧ c) = (a ∧ b) ∧ ca ∨ (b ∨ c) = (a ∨ b) ∨ c

Associativity

a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c)a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c)

Distributivity

Page 30: 05 - Relations

A ∩ U = AA ∪ ∅ = A

Neutral elements

A ∩ ∅ = ∅

A ∪ U = U

Zero elements

A ∩ A = AA ∪ A = A

Idempotence

A ∩ A’ = ∅

A ∪ A’ = U

Complement

A ∪ B = B ∪ AA ∩ B = B ∩ A

Commutativity

A ∩ (B ∩ C) = (A ∩ B) ∩ CA ∪ (B ∪ C) = (A ∪ B) ∪ C

Associativity

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

Distributivity

Page 31: 05 - Relations

A ∩ U = A A ∪ B = B ∪ AA ∪ ∅ = A

A ∩ ∅ = ∅

A ∪ U = U

A ∩ A = AA ∪ 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

Page 32: 05 - Relations

A ⊆ A.

A ⊆ B ∧ B ⊆ A ⇔ A = B.

A ⊆ B ∧ B ⊆ C ⇔ A ⊆ C

Reflexivity

Anti-symmetry

Transitivity

Page 33: 05 - Relations

Relations

www.tudorgirba.com

Page 34: 05 - Relations

Scissors

Paper

Stone

Page 35: 05 - Relations

Scissors

Paper

Stone

beats

beats

beats

Page 36: 05 - Relations

Scissors

Paper

Stone

beats

beats

beats

beats Scissors Paper StoneScissors FALSE TRUE FALSEPaper FALSE FALSE TRUEStone TRUE FALSE FALSE

Page 37: 05 - Relations

beats Scissors Paper StoneScissors FALSE TRUE FALSEPaper FALSE FALSE TRUEStone TRUE FALSE FALSE

beats = {(Scissors, Paper), (Paper, Stone), (Stone, Scissors)}

Page 38: 05 - Relations

beats Scissors Paper StoneScissors FALSE TRUE FALSEPaper FALSE FALSE TRUEStone TRUE FALSE FALSE

beats = {(Scissors, Paper), (Paper, Stone), (Stone, Scissors)}

beats ⊆ {Scissor, Paper, Stone} x {Scissor, Paper, Stone}

Page 39: 05 - Relations

Cartesian product AxB

AxB={ (a,b) | a∈A and b∈B }

Page 40: 05 - Relations

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).

Page 41: 05 - Relations

N-ary Relation

A1, A2, ..., AnR ⊆ A1 x A2 x...x An

Page 42: 05 - Relations

Binary Relation

A1, A2R ⊆ A1 x A2

(a,b) ∈ RaRb

Page 43: 05 - Relations

Binary Relation

A1, A2R ⊆ A1 x A2

(a,b) ∈ RaRb

Page 44: 05 - Relations

Binary Relation

A1, A2R ⊆ A1 x A2

(a,b) ∈ RaRb

dom R = {a⏐∃b :: (a,b) ∈ R}range R = {b⏐∃a :: (a,b) ∈ R}

Page 45: 05 - Relations
Page 46: 05 - Relations

Reflexive relationevery element x of A is in relation R with itself

Page 47: 05 - Relations

∀x: x∈A: xRx

Reflexive relationevery element x of A is in relation R with itself

Page 48: 05 - Relations

Symmetric relationif there is a relation between x and y, then there is a relation between y and x

∀x: x∈A: xRx

Reflexive relationevery element x of A is in relation R with itself

Page 49: 05 - Relations

Symmetric relationif 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

Reflexive relationevery element x of A is in relation R with itself

Page 50: 05 - Relations

Transitive relation...

Symmetric relationif 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

Reflexive relationevery element x of A is in relation R with itself

Page 51: 05 - Relations

Transitive relation...

Symmetric relationif 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

Reflexive relationevery element x of A is in relation R with itself

Page 52: 05 - Relations

Transitive relation...

Symmetric relationif there is a relation between x and y, then there is a relation between y and x

Eq

uiva

lent

rel

atio

n

∀x: x∈A: xRx

∀x,y: x,y∈A: xRy ⇒ yRx

∀x,y,z: x,y,z∈A: (xRy ∧ yRz) ⇒ xRz

Reflexive relationevery element x of A is in relation R with itself

Page 53: 05 - Relations

Examples

=>, <≥, ≤beats

Page 54: 05 - Relations

Examples

=>, <≥, ≤beats

reflexive, symmetric, transitive

transitive

reflexive, transitive

-

Page 55: 05 - Relations

[x]R= {y | xRy}Equivalence class

Page 56: 05 - Relations

[x]R= {y | xRy}Equivalence class

[1]= =

Page 57: 05 - Relations

[x]R= {y | xRy}Equivalence class

[1]= = {1}

Page 58: 05 - Relations

Example

Consider the relation ≡5 over the integer numbers Z defined as x≡5y if and only if x-y is a multiple of 5 (where x,y∈Z).Is ≡5 an equivalence relation?

Page 59: 05 - Relations

Example

Consider the relation ≡5 over the integer numbers Z defined 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 ?

Page 60: 05 - Relations

R ⊆ AxA{(a,b), (b,c), (c,d)}

Page 61: 05 - Relations

a b c dR ⊆ AxA{(a,b), (b,c), (c,d)}

Page 62: 05 - Relations

a b c dR ⊆ AxA{(a,b), (b,c), (c,d)}

Page 63: 05 - Relations

a b c dR ⊆ AxA{(a,b), (b,c), (c,d)}

Page 64: 05 - Relations

a b c dR ⊆ AxA{(a,b), (b,c), (c,d)}

Page 65: 05 - Relations

a b c dR ⊆ 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

Page 66: 05 - Relations

Irreflexive relationno element x of A is in relation R with itself

Page 67: 05 - Relations

∀x: x∈A: ¬(xRx)

Irreflexive relationno element x of A is in relation R with itself

Page 68: 05 - Relations

Antisymmetric relationif there is a relation between x and y and one between y and x, then x equals y

∀x: x∈A: ¬(xRx)

Irreflexive relationno element x of A is in relation R with itself

Page 69: 05 - Relations

Antisymmetric relationif 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

Irreflexive relationno element x of A is in relation R with itself

Page 70: 05 - Relations

Asymmetric relationxRy and yRx cannot hold at the same time

Antisymmetric relationif 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

Irreflexive relationno element x of A is in relation R with itself

Page 71: 05 - Relations

Asymmetric relationxRy and yRx cannot hold at the same time

Antisymmetric relationif 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)

Irreflexive relationno element x of A is in relation R with itself

Page 72: 05 - Relations

Examples

=>, <≥, ≤beats

Page 73: 05 - Relations

Examples

=>, <≥, ≤beats

antisymmetric

irreflexive, asymmetric

antisymmetric

irreflexive

Page 74: 05 - Relations
Page 75: 05 - Relations

Non-symmetric relationa relation that is not symmetric

Page 76: 05 - Relations

∀x,y: x,y∈A: (xRy) ∧ ¬(yRx)

Non-symmetric relationa relation that is not symmetric

Page 77: 05 - Relations

∀x,y: x,y∈A: (xRy) ∧ ¬(yRx)

Non-symmetric relationa relation that is not symmetric

Total relationR is defined on the entire A.

Page 78: 05 - Relations

∀x,y: x,y∈A: (xRy) ∧ ¬(yRx)

Non-symmetric relationa relation that is not symmetric

∀x,y: x,y∈A: xRy ∨ yRx

Total relationR is defined on the entire A.

Page 79: 05 - Relations

Examples

=>, <≥, ≤beats

Page 80: 05 - Relations

Examples

=>, <≥, ≤beats

-

non-symmetric

non-symmetric, total

-

Page 81: 05 - Relations

Acyclic relationthere are no elements with transitive closure to themselves

Page 82: 05 - Relations

Acyclic relationthere are no elements with transitive closure to themselves

∀n: n∈N:( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) )

Page 83: 05 - Relations

Acyclic relationthere are no elements with transitive closure to themselves

∀n: n∈N:( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) )

>, <

Page 84: 05 - Relations

Acyclic relationthere are no elements with transitive closure to themselves

∀n: n∈N:( ¬(∃x1, x2, ...,xn: x1, x2, ...,xn∈A: x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) )

>, < acyclic

Page 85: 05 - Relations

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

Page 86: 05 - Relations

A, BF ⊆ A x B(a,b)∈F ∧ (a,c)∈F ⇒ b=cdomF = A

F:A -> B

Function

Page 87: 05 - Relations

A, BF ⊆ A x B(a,b)∈F ∧ (a,c)∈F ⇒ b=cdomF = A

F:A -> B

Function

FºG(x) = F(G(x))Function composition