A finite simple undirected graph on the vertex set Fin n, as a dense
Boolean adjacency matrix constrained to be symmetric and loopless.
The dense Boolean adjacency matrix.
The edge relation is symmetric.
The edge relation is irreflexive: no loops.
Instances For
Build a graph from a symmetric irreflexive Boolean adjacency function.
Equations
- Hex.Graph.ofAdj f hs hi = { adjMatrix := Hex.Matrix.ofFn f, symm := ⋯, loopless := ⋯ }
Instances For
Build a graph from an arbitrary Boolean relation by symmetrizing it
and removing loops: i and j are adjacent when i ≠ j and the
relation holds in either direction.
Equations
- Hex.Graph.ofRel f = Hex.Graph.ofAdj (fun (i j : Fin n) => i != j && (f i j || f j i)) ⋯ ⋯
Instances For
The graph on n vertices with no edges.
Equations
- Hex.Graph.empty n = Hex.Graph.ofAdj (fun (x x_1 : Fin n) => false) ⋯ ⋯
Instances For
The complete graph on n vertices.
Equations
- Hex.Graph.complete n = Hex.Graph.ofAdj (fun (i j : Fin n) => i != j) ⋯ ⋯
Instances For
The membership test behind ofEdges?: an unordered edge {i, j} is
present when the input list contains it in either orientation.
Equations
Instances For
Checked edge-list builder. Returns none when some listed edge has an
endpoint out of range or is a loop; otherwise builds the graph whose edges
are the listed unordered pairs, collapsing duplicates in either
orientation.
Equations
- Hex.Graph.ofEdges? n edges = if h : edges.all (Hex.Graph.validEdge n) = true then some (Hex.Graph.ofAdj (Hex.Graph.edgeListAdj edges) ⋯ ⋯) else none
Instances For
Total edge-list builder over Fin pairs: the graph whose edges are
the listed unordered pairs, collapsing duplicates in either orientation
and dropping diagonal pairs. Beware that numeric literals in a
Fin n pair wrap modulo n; use ofEdges? to range-check plain
Nat input instead.
Equations
Instances For
The sorted duplicate-free array of neighbours of i. O(n) adjacency
reads; the order is increasing vertex order.
Equations
- G.nbrs i = (List.filter (fun (j : Fin n) => G.adj i j) (List.finRange n)).toArray
Instances For
Relabel a graph along a vertex map: (G.relabel f).adj i j = G.adj (f i) (f j).
For a bijective f this is relabelling by the inverse bijection; stated for
an arbitrary map because neither invariant needs injectivity.
Equations
- G.relabel f = Hex.Graph.ofAdj (fun (i j : Fin n) => G.adj (f i) (f j)) ⋯ ⋯