Graphs with loops
Lax871432.LoopGraphs · concepts/Lax871432/LoopGraphs.lean · lax-871432
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A loop graph is a graph in which loops are allowed: a symmetric, not necessarily irreflexive, relation on a vertex type. Simple graphs are the loopless case, and a loop graph without loops is a simple graph again. A homomorphism of loop graphs sends adjacent vertices to adjacent vertices, so a loop is sent to a loop and an edge to an edge or to a loop, and counts these maps as for simple graphs. Besides homomorphisms and isomorphisms, loop graphs carry here the full complement , which replaces every edge by a non-edge and every loop by a non-loop, the sub-loop-graph induced on a set of vertices, and the edge set, which for a loop graph may contain a pair , one for each loop.
Loops arise from two constructions on simple graphs. The looped graph is obtained from a simple graph by adding a loop at every vertex; the complement then factors as , which is what makes a two-step expansion of homomorphism counts into a complement possible.
The other is a quotient. For a simple graph and a set of unordered pairs of vertices, the contraction quotient has as vertices the connected components of the graph on with edge set , and joins two of them when some edge of joins a vertex of the one to a vertex of the other. It is a graph obtained from by contracting the edges of whenever it is loopless; in general it is not, carrying a loop at a component for every edge of with both endpoints inside it, which is why loops must be allowed here.
Two operations on simple graphs accompany these: the spanning subgraph , which keeps all vertices of and those of its edges that lie in a set , and the passage from a set of edges of to the underlying set of unordered pairs.
Concept map
In the paper
- page 6 of this submission's paper
Lean source view on GitHub
| 1 | import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected |
| 2 | import Mathlib.SetTheory.Cardinal.Finite |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Graphs with loops |
| 7 | type: definition |
| 8 | --- |
| 9 | A *loop graph* is a graph in which loops are allowed: a symmetric, not necessarily |
| 10 | irreflexive, relation on a vertex type. Simple graphs are the loopless case, and a loop graph |
| 11 | without loops is a simple graph again. A homomorphism of loop graphs sends adjacent vertices |
| 12 | to adjacent vertices, so a loop is sent to a loop and an edge to an edge or to a loop, and |
| 13 | counts these maps as for simple graphs. Besides homomorphisms and isomorphisms, |
| 14 | loop graphs carry here the *full complement* , which replaces every edge by a |
| 15 | non-edge *and* every loop by a non-loop, the sub-loop-graph induced on a set of vertices, and |
| 16 | the edge set, which for a loop graph may contain a pair , one for each loop. |
| 17 | |
| 18 | Loops arise from two constructions on simple graphs. The *looped graph* is obtained |
| 19 | from a simple graph by adding a loop at every vertex; the complement then factors as |
| 20 | , which is what makes a two-step expansion of homomorphism |
| 21 | counts into a complement possible. |
| 22 | |
| 23 | The other is a quotient. For a simple graph and a set of unordered pairs of vertices, |
| 24 | the *contraction quotient* has as vertices the connected components of the graph |
| 25 | on with edge set , and joins two of them when some edge of joins |
| 26 | a vertex of the one to a vertex of the other. It is a graph obtained from by contracting |
| 27 | the edges of whenever it is loopless; in general it is not, carrying a loop at a component |
| 28 | for every edge of with both endpoints inside it, which is why loops must be |
| 29 | allowed here. |
| 30 | |
| 31 | Two operations on simple graphs accompany these: the *spanning subgraph* , which keeps |
| 32 | all vertices of and those of its edges that lie in a set , and the passage from a set |
| 33 | of edges of to the underlying set of unordered pairs. |
| 34 | |
| 35 | # Implementation notes |
| 36 | |
| 37 | A `LoopGraph` is a structure carrying an adjacency relation and a proof that it is symmetric, |
| 38 | with no irreflexivity field; `SimpleGraph` is the irreflexive case, `toLoopGraph` the |
| 39 | inclusion and `toSimpleGraph` the passage back, given a proof of `IsLoopless`. Homomorphisms |
| 40 | and isomorphisms, written `→lg` and `≃lg`, are those of the adjacency relations, so `F →g G` |
| 41 | and `toLoopGraph F →lg toLoopGraph G` are definitionally equal and `LoopGraph.homCount` |
| 42 | extends `homCount` along `toLoopGraph` with no transport needed. |
| 43 | |
| 44 | `spanningSubgraph F s` takes an arbitrary set `s` of unordered pairs, and `edgeSetOf F s` |
| 45 | turns a finite set of edges of `F` into the corresponding set of pairs; together they let the |
| 46 | deletion part of the expansion be indexed by `Finset F.edgeSet`. |
| 47 | |
| 48 | `contractionQuotient F L` likewise takes an arbitrary set `L` of pairs; its vertex type is the |
| 49 | connected components of `SimpleGraph.fromEdgeSet L`, which discards the diagonal pairs of `L`. |
| 50 | |
| 51 | Only as much API is developed as the expansion of needs. Loop graphs |
| 52 | enter that expansion through the contraction quotients on its right-hand side; every other |
| 53 | statement of the package is about simple graphs only. |
| 54 | -/ |
| 55 | |
| 56 | namespace Lax871432.LoopGraphs |
| 57 | |
| 58 | variable {U V W : Type*} |
| 59 | |
| 60 | /-- A graph in which loops are allowed: a symmetric relation on the vertex type. Contrast |
| 61 | with `SimpleGraph`, which additionally requires irreflexivity, and with `Digraph`, which |
| 62 | requires nothing. -/ |
| 63 | @[ext] |
| 64 | structure LoopGraph (V : Type*) where |
| 65 | /-- The adjacency relation. A vertex may be adjacent to itself, i.e. carry a loop. -/ |
| 66 | Adj : V → V → Prop |
| 67 | /-- The adjacency relation is symmetric. -/ |
| 68 | symm : Std.Symm Adj := by aesop |
| 69 | |
| 70 | namespace LoopGraph |
| 71 | |
| 72 | /-- A homomorphism of loop graphs is a map preserving adjacency; loops are therefore sent to |
| 73 | loops, and edges to edges or to loops. -/ |
| 74 | abbrev Hom (X : LoopGraph V) (Y : LoopGraph W) := X.Adj →r Y.Adj |
| 75 | |
| 76 | /-- An isomorphism of loop graphs. -/ |
| 77 | abbrev Iso (X : LoopGraph V) (Y : LoopGraph W) := X.Adj ≃r Y.Adj |
| 78 | |
| 79 | end LoopGraph |
| 80 | |
| 81 | @[inherit_doc LoopGraph.Hom] scoped infixl:50 " →lg " => Lax871432.LoopGraphs.LoopGraph.Hom |
| 82 | @[inherit_doc LoopGraph.Iso] scoped infixl:50 " ≃lg " => Lax871432.LoopGraphs.LoopGraph.Iso |
| 83 | |
| 84 | namespace LoopGraph |
| 85 | |
| 86 | /-- The number of homomorphisms from `X` to `Y`. -/ |
| 87 | noncomputable def homCount (X : LoopGraph V) (Y : LoopGraph W) : ℕ := Nat.card (X →lg Y) |
| 88 | |
| 89 | /-- A loop graph is *loopless* if no vertex is adjacent to itself. -/ |
| 90 | def IsLoopless (X : LoopGraph V) : Prop := ∀ v, ¬ X.Adj v v |
| 91 | |
| 92 | /-- The simple graph underlying a loopless loop graph. -/ |
| 93 | def toSimpleGraph (X : LoopGraph V) (h : X.IsLoopless) : SimpleGraph V where |
| 94 | Adj := X.Adj |
| 95 | symm := X.symm |
| 96 | loopless := ⟨h⟩ |
| 97 | |
| 98 | /-- The *full complement* of `X`: every edge becomes a non-edge and every loop a non-loop. -/ |
| 99 | def fullCompl (X : LoopGraph V) : LoopGraph V where |
| 100 | Adj u v := ¬ X.Adj u v |
| 101 | symm := ⟨fun _ _ h h' => h (X.symm.symm _ _ h')⟩ |
| 102 | |
| 103 | /-- The sub-loop-graph induced on a set of vertices. -/ |
| 104 | def induce (X : LoopGraph V) (s : Set V) : LoopGraph s where |
| 105 | Adj a b := X.Adj a b |
| 106 | symm := ⟨fun _ _ h => X.symm.symm _ _ h⟩ |
| 107 | |
| 108 | /-- The edges (and loops) of `X`, as a set of unordered pairs. Unlike for simple graphs this |
| 109 | set may contain diagonal elements `s(v, v)`, one for each loop. -/ |
| 110 | def edgeSet (X : LoopGraph V) : Set (Sym2 V) := Sym2.fromRel X.symm |
| 111 | |
| 112 | end LoopGraph |
| 113 | |
| 114 | /-- A simple graph, viewed as a loop graph. -/ |
| 115 | def toLoopGraph (G : SimpleGraph V) : LoopGraph V where |
| 116 | Adj := G.Adj |
| 117 | symm := G.symm |
| 118 | |
| 119 | /-- The *looped* graph `G°`: a loop is added at every vertex of `G`. -/ |
| 120 | def looped (G : SimpleGraph V) : LoopGraph V where |
| 121 | Adj u v := G.Adj u v ∨ u = v |
| 122 | symm := ⟨fun _ _ h => h.imp (fun ha => ha.symm) (fun he => he.symm)⟩ |
| 123 | |
| 124 | /-- The spanning subgraph of `F` whose edges are those of `F` lying in `s`. It has the same |
| 125 | vertex type as `F`. -/ |
| 126 | def spanningSubgraph (F : SimpleGraph V) (s : Set (Sym2 V)) : SimpleGraph V where |
| 127 | Adj u v := F.Adj u v ∧ s(u, v) ∈ s |
| 128 | symm := ⟨fun _ _ h => ⟨h.1.symm, Sym2.eq_swap ▸ h.2⟩⟩ |
| 129 | loopless := ⟨fun _ h => F.irrefl h.1⟩ |
| 130 | |
| 131 | /-- The set of unordered pairs selected by a finite set of edges of `F`. -/ |
| 132 | def edgeSetOf (F : SimpleGraph V) (s : Finset F.edgeSet) : Set (Sym2 V) := |
| 133 | Subtype.val '' (s : Set F.edgeSet) |
| 134 | |
| 135 | /-- The *contraction quotient* `F ⊘ L`: its vertices are the connected components of the graph |
| 136 | on `V(F)` with edge set `L`, and `[v]` is adjacent to `[w]` when some edge of `E(F) \ L` joins |
| 137 | a vertex of `[v]` to a vertex of `[w]`. |
| 138 | |
| 139 | The result may have loops, so it is a `LoopGraph`. -/ |
| 140 | def contractionQuotient (F : SimpleGraph V) (L : Set (Sym2 V)) : |
| 141 | LoopGraph (SimpleGraph.fromEdgeSet L).ConnectedComponent where |
| 142 | Adj c d := ∃ x y, F.Adj x y ∧ s(x, y) ∉ L ∧ |
| 143 | (SimpleGraph.fromEdgeSet L).connectedComponentMk x = c ∧ |
| 144 | (SimpleGraph.fromEdgeSet L).connectedComponentMk y = d |
| 145 | symm := ⟨fun _ _ ⟨x, y, hxy, hL, hx, hy⟩ => |
| 146 | ⟨y, x, hxy.symm, Sym2.eq_swap ▸ hL, hy, hx⟩⟩ |
| 147 | |
| 148 | @[inherit_doc] scoped notation:70 F:70 " ⊘ " L:71 => Lax871432.LoopGraphs.contractionQuotient F L |
| 149 | |
| 150 | end Lax871432.LoopGraphs |
| 151 |
Implementation notes
A is a structure carrying an adjacency relation and a proof that it is symmetric, with no irreflexivity field; is the irreflexive case, the inclusion and the passage back, given a proof of . Homomorphisms and isomorphisms, written and , are those of the adjacency relations, so and are definitionally equal and extends along with no transport needed.
takes an arbitrary set of unordered pairs, and turns a finite set of edges of into the corresponding set of pairs; together they let the deletion part of the expansion be indexed by .
likewise takes an arbitrary set of pairs; its vertex type is the connected components of , which discards the diagonal pairs of .
Only as much API is developed as the expansion of needs. Loop graphs enter that expansion through the contraction quotients on its right-hand side; every other statement of the package is about simple graphs only.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments