Skip to content
UoL CS Notes

Relations - 3

COMP109 Lectures

Building New Relations from Given Ones

Inverse Relation

Given a realtion RA×B. We define the inverse relation R1B×A by:

R1={(b,a)|(a,b)R}

Example:

  • The inverse of the relation is a parent of on the set of people is the relation is a child of.

In other words if you swap the elements of a given relation you should get the inverse relation.

Example

A={1,2,3,4},R={(x,y)|xy}

Therefore:

R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}

And:

R={(1,1),(2,1),(3,1),(4,1),(2,2),(3,2),(4,2),(3,3),(4,3),(4,4)}

You could also say:

R1={(y,x)|xy}={(u,v)|uv}

In these examples you either swap the predicate to denote the inverse or you swap the evaluation such that it produces the inverse.

Composition of Relations

Let RA×b and sB×C. The (functional) composition of R and S, denoted by SR, is the binary relation between A and C given by: $S\circ R =\(\{(a,c)\vert \text{ exists } b\in B \text{ such that }\)aRb \text{ and } bSc\}$

The notation aRb is another way of writing (a,b)R.

C

B

A

R subset A * B

S subset B * C

1

2

Example:

  • If R is the relation is a sister of and S is the relation is a parent of then:
    • SR is the relation is an aunt of.
    • SS is the relation is a grandparent of.

Example

  • R: is a sister of
  • S: is a parent of
  • SR={(a,c)| exists bB such that aRb and bSc}

Fred and Mavis

Alice

Ken and Sue

Jane

Fiona

Alan

John and Mary

Mike

Penny

  • Alice R Ken and Ken S Alan so Alice SR Alan.
    • This can also be written as (Alice, Alan)SR

Diagraph Representation of Compositions

For this diagram A={a,b},B={1,2,3},C={x,y}:

S

R

1

2

3

1

2

3

S circ R

a

x

y

b

a

b

y

x

Computer Friendly Representation of Binary Relations - Matrices

Let A={a1,,an},B={b1,,bm} and RA×B.

We represent R by an array M of n rows and m columns. Such an array is called an n by m matrix.

The entry in row i and column j of this matrix is given by M(i,j) where:

M(i,j)={1 if (ai,bj)R0 if (a1,bj)R

Example 1

Let A={1,3,5,7},B={2,4,6} and:

U={(x,y)A×B|x+y=9}

Assume an enumeration a1=1,a2=3,a3=5,a4=7 and b1=2,b2=4,b3=6. Then M represents U, where:

M=[000001010100]

When representing in a matrix the rows are the items in set A going down and the columns are the items in set B going across.

You can then read the answers from the matrix as: U={(7,2),(5,4),(4,6)}.

Example 2

The binary relation R on A={1,2,3,4} has the following digraph representation:

1

2

3

4

  1. What are the ordered pairs?

    R={(4,3),(3,2),(2,1)}

  2. Draw the matrix.

    [0000100001000010]
  3. Explain the relation.

    x is 1 larger than y.

Matrices and Composition

This is working on the same relation as was seen in the section Diagraph Representation of Compositions.

Z

Y

X

1

2

3

a

b

x

y

This result in the following for the composition of SR:

a

x

y

b

From these graphs we can deduce that RX×Y,SY×Z.

Given the matrices of R and S:

R:[111010]S:[011010]

Calculate the binary relation matrix of SR:

If you transpose the row a in the matrix R on the column x in the matrix S you can compare to see of a is a subset of y. If it is then you put a 1 in the resultant matrix and if not you put a zero:

SR:[1110]

Boolean Matrix Product

Given two matrices with entries 1 and 0 representing the relations we can form the matrix representing the composition. This is called the logical (Boolean) matrix product.

Let A={a1,,an},B={b1,,bm} and C={c1,,cp}.

The logical matrix M representing R is given by:

M(i,j)={1 if (ai,bj)R0 if (a1,bj)R

The logical matrix N representing S is given by:

N(i,j)={1 if (bi,cj)S0 if (b1,cj)S

Then the entries P(i,) of the logical matrix P representing SR are given by:

  • P(i,j)=1 if there existsw l with 1lm such that M(i,l)=1 and N(i,j)=1.
  • P(i,j)=0, otherwise.

This is the same as a product of matrices, P=MN. Instead of addition and multiplication we use logical OR and AND.