The Bipartite.AdjacencyMap data type represents an undirected bipartite
graph. The two type parameters determine the types of vertices of each part. If
the types coincide, the vertices of the left part are still treated as disjoint
from the vertices of the right part. See examples for more details.
We define a Num instance as a convenient notation for working with bipartite graphs:
0 == rightVertex 0
swap 1 == leftVertex 1
swap 1 + 2 == vertices [1] [2]
swap 1 * 2 == edge 1 2
swap 1 + 2 * swap 3 == overlay (leftVertex 1) (edge 3 2)
swap 1 * (2 + swap 3) == connect (leftVertex 1) (vertices [3] [2])
Note: the Num instance does not satisfy several "customary laws" of Num,
which dictate that fromInteger 0 and fromInteger 1 should act as
additive and multiplicative identities, and negate as additive inverse.
Nevertheless, overloading fromInteger, + and * is very convenient when
working with algebraic graphs; we hope that in future Haskell's Prelude will
provide a more fine-grained class hierarchy for algebraic structures, which we
would be able to utilise without violating any laws.
The Show instance is defined using basic graph construction primitives:
show empty == "empty"
show 1 == "rightVertex 1"
show (swap 2) == "leftVertex 2"
show (1 + 2) == "vertices [] [1,2]"
show (swap (1 + 2)) == "vertices [1,2] []"
show (swap 1 * 2) == "edge 1 2"
show (swap 1 * 2 * swap 3) == "edges [(1,2),(3,2)]"
show (swap 1 * 2 + swap 3) == "overlay (leftVertex 3) (edge 1 2)"
The Eq instance satisfies all axioms of undirected bipartite algebraic graphs:
overlay is commutative and associative:
x + y == y + x x + (y + z) == (x + y) + zconnect is commutative, associative and has empty as the identity:
x * empty == x empty * x == x x * y == y * 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 * zconnect has the same effect as overlay on vertices of the same part:
leftVertex x * leftVertex y == leftVertex x + leftVertex y rightVertex x * rightVertex y == rightVertex x + rightVertex y
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
When specifying the time and memory complexity of graph algorithms, n and m will denote the number of vertices and edges of the graph, respectively. In addition, l and r will denote the number of vertices in the left and right parts of the graph, respectively.
Instances8Eq, Num, Ord, Show, Generic, Semigroup, …
(Ord a, Ord b) => Eq (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMap(Ord a, Ord b, Num b) => Num (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMapNote: this does not satisfy the usual ring laws; see AdjacencyMap for more details.
(Ord a, Ord b) => Ord (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMap(Ord a, Ord b, Show a, Show b) => Show (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMapGeneric (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMap(Ord a, Ord b) => Semigroup (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMapDefined via overlay.
(Ord a, Ord b) => Monoid (AdjacencyMap a b)Defined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMaptype Rep (AdjacencyMap a b) = D1 ('MetaDataDefined in algebraic-graphs-0.8 · Algebra.Graph.Bipartite.AdjacencyMap"AdjacencyMap"
"Algebra.Graph.Bipartite.AdjacencyMap"
"algebraic-graphs-0.8-8JX2W3BiNP382gnPBc0Np8"
'False) (C1 ('MetaCons"BAM"
'PrefixI 'True) (S1 ('MetaSel ('Just"leftAdjacencyMap"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map a (Set b))) :*: S1 ('MetaSel ('Just"rightAdjacencyMap"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map b (Set a)))))