The core type class for constructing algebraic graphs is defined by introducing the connect method to the standard MonadPlus class and reusing the following existing methods:
The empty method comes from the Alternative class and corresponds to the empty graph. This module simply re-exports it.
The vertex graph construction primitive is an alias for pure of the Applicative type class.
Graph overlay is an alias for
mplusof the MonadPlus type class.
The Graph type class is characterised by the following minimal set of axioms.
In equations we use + and * as convenient shortcuts for overlay and
connect, respectively.
overlay is commutative and associative:
x + y == y + x x + (y + z) == (x + y) + zconnect is associative and has empty as the identity:
x * empty == x empty * x == x x * (y * z) == (x * y) * zconnect distributes over overlay:
x * (y + z) == x * y + x * z (x + y) * z == x * z + y * zconnect can be decomposed:
x * y * z == x * y + x * z + y * z
The following useful theorems can be proved from the above set of axioms.
overlay has empty as the identity and is idempotent:
x + empty == x empty + x == x x + x == xAbsorption and saturation of connect:
x * y + x + y == x * y x * x * x == x * x
The core type class Graph corresponds to unlabelled directed graphs. Undirected, Reflexive, Transitive and Preorder graphs can be obtained by extending the minimal set of axioms.
When specifying the time and memory complexity of graph algorithms, n will denote the number of vertices in the graph, m will denote the number of edges in the graph, and s will denote the size of the corresponding Graph expression.
Methods
connect :: g a -> g a -> g aConnect two graphs.