inm175 topic 7 1 module inm175 discrete mathematics topic 7 set theoretic models

16
1 INM175 Topic 7 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

Upload: shon-owen

Post on 01-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

1INM175 Topic 7

Module INM175Discrete Mathematics

Topic 7

Set Theoretic Models

Page 2: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

2INM175 Topic 7

Some Useful Constructions in Set Theory (for the modeler)

Relational Join _ & _ : ( (X Y) (X Z) (X (Y Z) )(or direct product) x (R & S) (y, z) xRy xSz

Corresponding Function (of a relation) cf: (X Y) (X Y)

y cf(R)(x) xRy

The first line in each definition gives the signature of the operator being defined.This includes the number and signatures of its parametersand whether it is to be written infix, prefix or postfix

The second line gives its semantics.This consists of the application of the operator to variables universallyquantified over its domain and a predicate defining the criteria formembership in the result, subjected to a case analysis if necessary.

Page 3: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

3INM175 Topic 7

Modelling LIST in Set TheorySequence (or list) Seq X : N+ X

s: Seq X •dom(s) = [1..#s]

Catenation (of lists) _ ^ _ : ((Seq X) (Seq X))(Seq X)

i #s (s^t) i = s ii > #s (s^t) i = t ( i - #s )

Extract (from list) extract: N+ (Seq X ) (Seq X )i>j (extract i s) j = s ji j (extract i s) j = s (succ j)

The signature in the last definition is said to be Curried (after the logician Haskell B. Curry).

Instead of taking two arguments and delivering a result,extract takes one argument and delivers a function that takes the

next argument before delivering the final result.

Page 4: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

4INM175 Topic 7

Directed Graphs

A simple directed graph is just a homogeneous relation.

By separately identifying the edges and vertices, we can generalise our model of directed graph (or DG) to the 4-tuple (sequence of four sets),

DG = <V, E, in, out>

where V is the set of edges;

E is the set of vertices;

and in, out: EV

map each edge to the vertices that it goes to and comes from,

respectively.

(Note that this is the just structure that we used in our ‘airline timetable’ example earlier.)

Page 5: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

5INM175 Topic 7

Reachability

Now we can derive from the tuple the relation next, that maps each vertex to those that are ‘one step ahead’, thus

next: VV

next = in ° out-1

and we can use transitive closure to derive the relation reachable,

which maps each vertex to those that can be ‘reached’ from it,

along some ‘path’ of contiguous edges, thus:

reachable : VV

reachable = next+

Page 6: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

6INM175 Topic 7

Directed Acyclic GraphsCycles in graphs are paths that lead from a vertex to itself.

A directed acyclic graph (or DAG) is a DG in which,

from every vertex, no path returns to that vertex.

Clearly, a DG is acyclic iff no vertex is reachable from itself, that is,

its reachability relation and the identity relation on its vertices are disjoint

reachable Id(V) = .

The roots of a DAG are those vertices that no edges enter

roots: V

roots = dom(next) - ran(next)

The leaves of a DAG are those that no edges leave

leaves: V

leaves = ran(next) - dom(next)

Page 7: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

7INM175 Topic 7

Forests and TreesWe can also read a DAG backwards, by deriving from its 4-tuple the relation

that maps each vertex to its predecessors, thus:

pred : VV

pred = out ° in-1 = next-1

A DAG is a forest when no vertex has more than one predecessor, i.e.

pred: VV

‘Family trees’ are forests, because the family has more that one ‘ancestor’!

A forest with a single root is called a tree. A DAG is a tree when

#roots = 1

The directory structure in your computer is a tree, at the root of which is the name of a ‘volume’ (such as ‘C:\’ in Windows, or ‘\’ in Unix).

Page 8: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

8INM175 Topic 7

Adjacency and Connectivity

The adjacency relation maps each vertex to those that are ‘one step away’ in either direction. It is the union of next and pred

adj: VV

adj = next pred

(think of this as the original graph with the arrowheads removed)

The transitive closure of adjaceny gives the relation that maps each vertex to those that are connected to it by paths of any length in either direction

connected: VV

connected = adj+

Page 9: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

9INM175 Topic 7

Connected Graphs

connected is an equivalence relation.

(You should check that assertion for yourself!)

So the quotient of the set of vertices by connected will partition the set of vertices into equivalence classes, all the vertices in each of which are connected to each other but not to any vertex in any other set.

This quotient tells us whether the original graph had any ‘islands’: that is, zones which were entirely disconnected from the rest.

A connected graph has no islands, so satisfies the predicate

V/connected = {V}

Page 10: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

10INM175 Topic 7

Subtyping and Inheritance

The definition of directed graph has been extended by adding constraints.

Trees are restricted forests,

which are restricted directed acyclic graphs,

which are restricted directed graphs.

If we call the class of all trees TREE, etc., we have

TREE FOREST DAG DG

and similarly for connected and undirected graphs.

These are examples of subtyping, or inheritance, which you will meet much more of in object-oriented design.

Page 11: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

11INM175 Topic 7

Quick Revision of Set Theorythe empty set {} or

Definition by extension eg A = {1, 2, 3}, B = {5, 12, 13, 3, 2}

membership eg 2 A, 2 B, 5 B

non-membership but 5 A

Definition by comprehension {x X | P(x)} where P is some property that

each member of the set X may or may not possess.

eg S = {b B | even(b)} = {2, 12}cardinality the number of elements in a set

eg = 0, A = 3, B = 5subset X Y if and only if

every member of X is a member of Y, or formally:

x•((x X) (x Y))

proper subset X Y (X Y) (X Y)

Page 12: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

12INM175 Topic 7

Some Set Operatorsx•

union x (X Y) (x X) (x Y)eg A B = {1,2,3,5,12,13}

intersection x (X Y) (x X) (x Y)eg A B = {2,3}

difference - x (X-Y) (x X) (x Y)eg A-B = {1} and B-A = {5, 12, 13}

complement the difference between a set and thecurrent Universe of Discourseeg S = B-S = {5, 13, 3}

powerset X = {s | s X} eg X = {,{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}

Page 13: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

13INM175 Topic 7

Products and Relations

Cartesian product (x,y) (XY) (xX) (yY)Relation (XY) = (XY)

XY denotes the set of all relations from X to Yi.e. any relation R of signature XY is a subset of XY.If a pair (x,y) R, we may write xRy.

Given any relation R: X Ydomain dom dom R = {xX | y:Y • xRy}range ran cod(R) = {yY | x:X • xRy}inverse -1 (y,x)R-1 (x,y) R

Page 14: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

14INM175 Topic 7

More Relational Operators

Given any X’ Ximage [ _ ] yR[X’] xX’ •

xRy

Given any relation S: Y Zcomposition (x,z)SR y:Y •xRy

ySz

Given any ZX domain restriction R Z = R (ZY)

Page 15: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

15INM175 Topic 7

Properties of RelationsGiven a set X and a relation R: X X, R isReflexive if x:X• xRxIrreflexive if x:X•¬ xRx i.e. R(Id X) =Symmetric if x,y:X• xRy yRxAntisymmetric if x,y:X• xRy yRx x=yTransitive if x,y,z:X• xRy yRz xRz

Some Special Relations and their propertiesEquivalence relations are reflexive, symmetric and transitive.Partial Orders are reflexive, transitive and antisymmetric.Strict Orders are irreflexive, transitive and antisymmetric.

Page 16: INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models

16INM175 Topic 7

Functions

A relation F: X Y is a function if x:X• y,z:Y• xFy xFz y = zWe indicate that such a relation is a function by writingF: X YIf dom F =X, the function F is total and we writeF : X Y

Some Properties of FunctionsSurjective (onto) F [dom X] = YInjective (one-to-one) F-1 Y XBijective (one-to-one and onto) surjective and injective

FX Y•••••

••••