OOSS Topic 7
Module INM175Discrete Mathematics
Topic 7
Set Theoretic Models
Some Useful Constructions in Set Theory (for the modeler)
Modelling LIST in Set Theory
Sequence (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 i
i > #s (s^t) i = t ( i - #s )
Extract (from list) extract: N+ (Seq X ) (Seq X )
i>j (extract i s) j = s j
i 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.
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 =
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.)
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+
Directed Acyclic Graphs
Cycles 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)
Forests and Trees
We can also read a DAG backwards, by deriving from its 4-tuple the relation that maps each vertex to its predecessors, thus:
pred : V«V
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).
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: V«V
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: V«V
connected = adj+
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}
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.
Quick Revision of Set Theory
Some Set Operators
Products and Relations
Cartesian product (x,y) (XY) (xX) (yY)
Relation (XY) = (XY)
XY denotes the set of all relations from X to Y
i.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 Y
domain dom dom R = {xX | y:Y • xRy}
range ran cod(R) = {yY | x:X • xRy}
inverse -1 (y,x)R-1 (x,y) R
More Relational Operators
Given any X’ X
image [ _ ] yR[X’] x:X’ • xRy
Given any relation S: Y Z
composition (x,z)SR y:Y •xRy ySz
Given any ZX
domain restriction R Z = R (ZY)
Properties of Relations
Functions
Blank Presentation
