Agenda School of Technology

• Binary relations • Operations on relations Relations • Properties of relations

Andrew Simpson Revised by David Lightfoot

2 1 School of Technology

Binary relations Binary relations

• The Cartesian product X × Y is the set of all pairs of • Any R of a Cartesian product X × Y is a the form (x, y) where x ∈ X and y ∈ Y • For example • If some pair (x, y) appears in R, then we say that ‘the { (jack, 65), (jack, 60) } relation R holds between x and y’ ⊆ • This may be written: { (jack, 65), (jack, 60), (jill, 65), (jill, 60) } (x, y) ∈ R or R(x, y) or ∈ • The set { (jack, 65), (jack, 60) } associates each x å y R or (‘the maplet x, y is an element of R’) person with their age. It is termed a relation – some xRy relationship exists between the name and the age

3 4 School of Technology School of Technology

Example Notation

• The relation LessThan on the natural numbers may •We let X ↔ Y denote the set of all relations between be defined as follows: sets X and Y

LessThan = {m, n: N | m < n} X ↔ Y = P(X × Y) LessThan ∈ N ↔ N

• Given the relation R ∈ X ↔ Y, the set X is referred to as the source of R and the set Y is the target of R

5 6 School of Technology School of Technology

1 Potato diagrams Example

• One means of illustrating relations is via ‘potato • Take the relation: diagrams’ HouseMates = {Karen, Kerry, Matt}

• In such diagrams, all elements of the source and likes ∈ HouseMates ↔ HouseMates target are illustrated, together with an indication of which elements of the source are related to which elements of the target likes = {Karen å Matt, Matt å Kerry}

7 8 School of Technology School of Technology

Example Domain and range

• The domain of a relation R consists of those elements of the source which appear in the relation, likes that is, those elements which are mapped from: Karen Karen dom R = { x: X | (∃y: Y • x å y ∈ R) }

Kerry Kerry • The range of a relation R consists of those elements Matt Matt of the target which appear in the relation, that is, those elements which are mapped to: ran R = { y: Y | (∃x: X • x å y ∈ R) }

9 10 School of Technology School of Technology

Example Restrictions

•domlikes = { Karen, Matt } • We may restrict our relations to specific of the domain or range by using restriction operators: • ran likes = { Kerry, Matt } • Domain restriction: A ∈ PX A r R = {x: X; y: Y | x å y ∈ R ∧ x ∈ A • x å y}

• Range restriction: B ∈ PY R t B = {x: X; y: Y | x å y ∈ R ∧ y ∈ B • x å y}

11 12 School of Technology School of Technology

2 Examples Subtractions

•{ Matt } r likes = { Matt å Kerry } • The subtraction operators are the complement of the restriction operators: • likes t { Matt } = { Karen å Matt } • Domain subtraction : A ∈ PX A y R = {x: X; y: Y | x å y ∈ R ∧ x ∉ A • x å y}

• Range subtraction : B ∈ PY R u B = {x: X; y: Y | x å y ∈ R ∧ y ∉ B • x å y}

13 14 School of Technology School of Technology

Examples Relational inverse

•{ Matt } y likes = { Karen å Matt } • The inverse of a relation R: X ↔ Y is its ‘mirror image’, written R~ or R-1 • likes u { Matt } = { Matt å Kerry } R~ = {x: X; y: Y | x å y ∈ R • y å x}

The source of R~ is Y and its target is X

likes = { Karen å Matt, Matt å Kerry } likes~ = { Matt å Karen, Kerry å Matt }

15 16 School of Technology School of Technology

Example Relational image

• If R is a relation R: X ↔ Y likes~ and A ∈ PX Karen Karen then Kerry Kerry R · A ‚ denotes the relational image of A under R – Matt Matt the set of elements of Y that are mapped to R by elements of A

R · A ‚ = { x: X; y: Y | x å y ∈ R ∧ x ∈ A • y }

17 18 School of Technology School of Technology

3 Relational composition Relational composition

• Given two relations R ; Q RQ R: X ↔ Y Q: Y ↔ Z The relational composition of R and Q, written

R ; Q XYZ ∈ ∧ ∈ • = { x: X; y: Y; z: Z | x å y R y å z Q x å z } Figure 9.4

R ; Q = { x: X; y: Y; z: Z | x å y ∈ R ∧ y å z ∈ Q • x å z }

19 20 School of Technology School of Technology

Homogeneous relation Reflexive relations

• A relation that has a source and target of the same • A homogeneous relation type is called homogeneous R: X ↔ X R: X ↔ X • is said to be reflexive, if and only if ∀x: X • xRx • Others are called heterogeneous Examples: Q: X ↔ Y =, for natural numbers is reflexive < is not reflexive loves is not reflexive looksLike is reflexive

21 22 School of Technology School of Technology

Symmetric relations Transitive relations

• A homogeneous relation • A homogeneous relation R: X ↔ X R: X ↔ X • is said to be symmetric, if and only if • is said to be transitive, if and only if ∀ • ∀ • ∧ x1, x2: X x1 Rx2 ⇒ x2 Rx1 x1, x2, x3 : X x1 Rx2 x2 Rx3 ⇒ x1 Rx3 Examples: Examples: =, for natural numbers is symmetric =, for natural numbers is transitive < is not symmetric < is transitive loves is not symmetric loves is not transitive looksLike is symmetric looksLike is transitive

23 24 School of Technology School of Technology

4 Closures Reflexive

• If a relation does not have a specific property, then • To obtain the reflexive closure of R: X ↔ X we have we may add maplets until it does only to add the maplets of the identify relation: • If we add precisely those maplets that are missing, then the resulting relation is called a closure id X == { x: X • x å x } (== means ‘is defined to be’)

25 26 School of Technology School of Technology

Symmetric closure Iteration

• To obtain the symmetric closure of R: X ↔ X we have • R0 = id X only to add the maplets • R1 = R • R2 = R ; R y å x that are not present • R3 = R ; R ; R •where • R3 = R2 ; R x å y is present • Rn+1 = Rn ; R, for n ≥ 1 • “I’ve danced with a man who’s danced with a girl The symmetric closure of R is: who’s danced with the Prince of Wales” Rs = R ∪ R ~ I dancedWith ; dancedWith ; dancedWith POW I dancedWith3 POW

27 28 School of Technology School of Technology

Transitive closures Summary

• Binary relations: R: X ↔ Y = P(X × Y) • R+ = ∪ { n: N | n ≥ 1 • Rn } of R • Operations on relations: dom, ran, ~, r, t, y, u, ·‚, ; •R* = R+ ∪ id X reflexive transitive closure of R • Properties of relations: reflexivity, symmetry and transitivity • If a relation direct relates two airports a and b exactly •Closures when there is a direct flight from a to b, then the transitive closure of direct, direct+, relates two airports c and d, when it is possible to fly from c to d by a sequence of direct flights

29 30 School of Technology School of Technology

5