Graphs with loops

Lax871432.LoopGraphs · concepts/Lax871432/LoopGraphs.lean · lax-871432

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural 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 hom(X,Y)\hom(X, Y) counts these maps as for simple graphs. Besides homomorphisms and isomorphisms, loop graphs carry here the full complement X^\widehat{X}, 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 vvvv, one for each loop.

    Loops arise from two constructions on simple graphs. The looped graph GG^\circ is obtained from a simple graph GG by adding a loop at every vertex; the complement then factors as G=G^\overline{G} = \widehat{G^\circ}, which is what makes a two-step expansion of homomorphism counts into a complement possible.

    The other is a quotient. For a simple graph FF and a set LL of unordered pairs of vertices, the contraction quotient FLF \oslash L has as vertices the connected components of the graph on V(F)V(F) with edge set LL, and joins two of them when some edge of E(F)LE(F) \setminus L joins a vertex of the one to a vertex of the other. It is a graph obtained from FF by contracting the edges of LL whenever it is loopless; in general it is not, carrying a loop at a component for every edge of E(F)LE(F) \setminus L with both endpoints inside it, which is why loops must be allowed here.

    Two operations on simple graphs accompany these: the spanning subgraph FsF_s, which keeps all vertices of FF and those of its edges that lie in a set ss, and the passage from a set of edges of FF to the underlying set of unordered pairs.

    Concept map
    1 concept; 3 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    In the paper

    • page 6 of this submission's paper

    Lean source view on GitHub

    1import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected
    2import Mathlib.SetTheory.Cardinal.Finite
    3
    4/-!
    5---
    6title: Graphs with loops
    7type: definition
    8---
    9A *loop graph* is a graph in which loops are allowed: a symmetric, not necessarily
    10irreflexive, relation on a vertex type. Simple graphs are the loopless case, and a loop graph
    11without loops is a simple graph again. A homomorphism of loop graphs sends adjacent vertices
    12to adjacent vertices, so a loop is sent to a loop and an edge to an edge or to a loop, and
    13hom(X,Y)\hom(X, Y) counts these maps as for simple graphs. Besides homomorphisms and isomorphisms,
    14loop graphs carry here the *full complement* X^\widehat{X}, which replaces every edge by a
    15non-edge *and* every loop by a non-loop, the sub-loop-graph induced on a set of vertices, and
    16the edge set, which for a loop graph may contain a pair vvvv, one for each loop.
    17
    18Loops arise from two constructions on simple graphs. The *looped graph* GG^\circ is obtained
    19from a simple graph GG by adding a loop at every vertex; the complement then factors as
    20G=G^\overline{G} = \widehat{G^\circ}, which is what makes a two-step expansion of homomorphism
    21counts into a complement possible.
    22
    23The other is a quotient. For a simple graph FF and a set LL of unordered pairs of vertices,
    24the *contraction quotient* FLF \oslash L has as vertices the connected components of the graph
    25on V(F)V(F) with edge set LL, and joins two of them when some edge of E(F)LE(F) \setminus L joins
    26a vertex of the one to a vertex of the other. It is a graph obtained from FF by contracting
    27the edges of LL whenever it is loopless; in general it is not, carrying a loop at a component
    28for every edge of E(F)LE(F) \setminus L with both endpoints inside it, which is why loops must be
    29allowed here.
    30
    31Two operations on simple graphs accompany these: the *spanning subgraph* FsF_s, which keeps
    32all vertices of FF and those of its edges that lie in a set ss, and the passage from a set
    33of edges of FF to the underlying set of unordered pairs.
    34
    35# Implementation notes
    36
    37A `LoopGraph` is a structure carrying an adjacency relation and a proof that it is symmetric,
    38with no irreflexivity field; `SimpleGraph` is the irreflexive case, `toLoopGraph` the
    39inclusion and `toSimpleGraph` the passage back, given a proof of `IsLoopless`. Homomorphisms
    40and isomorphisms, written `→lg` and `≃lg`, are those of the adjacency relations, so `F →g G`
    41and `toLoopGraph F →lg toLoopGraph G` are definitionally equal and `LoopGraph.homCount`
    42extends `homCount` along `toLoopGraph` with no transport needed.
    43
    44`spanningSubgraph F s` takes an arbitrary set `s` of unordered pairs, and `edgeSetOf F s`
    45turns a finite set of edges of `F` into the corresponding set of pairs; together they let the
    46deletion 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
    49connected components of `SimpleGraph.fromEdgeSet L`, which discards the diagonal pairs of `L`.
    50
    51Only as much API is developed as the expansion of hom(F,G)\hom(F, \overline{G}) needs. Loop graphs
    52enter that expansion through the contraction quotients on its right-hand side; every other
    53statement of the package is about simple graphs only.
    54-/
    55
    56namespace Lax871432.LoopGraphs
    57
    58variable {U V W : Type*}
    59
    60/-- A graph in which loops are allowed: a symmetric relation on the vertex type. Contrast
    61with `SimpleGraph`, which additionally requires irreflexivity, and with `Digraph`, which
    62requires nothing. -/
    63@[ext]
    64structure 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
    70namespace LoopGraph
    71
    72/-- A homomorphism of loop graphs is a map preserving adjacency; loops are therefore sent to
    73loops, and edges to edges or to loops. -/
    74abbrev Hom (X : LoopGraph V) (Y : LoopGraph W) := X.Adj →r Y.Adj
    75
    76/-- An isomorphism of loop graphs. -/
    77abbrev Iso (X : LoopGraph V) (Y : LoopGraph W) := X.Adj ≃r Y.Adj
    78
    79end 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
    84namespace LoopGraph
    85
    86/-- The number of homomorphisms from `X` to `Y`. -/
    87noncomputable 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. -/
    90def IsLoopless (X : LoopGraph V) : Prop := ∀ v, ¬ X.Adj v v
    91
    92/-- The simple graph underlying a loopless loop graph. -/
    93def 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. -/
    99def 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. -/
    104def 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
    109set may contain diagonal elements `s(v, v)`, one for each loop. -/
    110def edgeSet (X : LoopGraph V) : Set (Sym2 V) := Sym2.fromRel X.symm
    111
    112end LoopGraph
    113
    114/-- A simple graph, viewed as a loop graph. -/
    115def 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`. -/
    120def 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
    125vertex type as `F`. -/
    126def 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`. -/
    132def 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
    136on `V(F)` with edge set `L`, and `[v]` is adjacent to `[w]` when some edge of `E(F) \ L` joins
    137a vertex of `[v]` to a vertex of `[w]`.
    138
    139The result may have loops, so it is a `LoopGraph`. -/
    140def 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
    150end Lax871432.LoopGraphs
    151

    Implementation notes

    A LoopGraphLoopGraph is a structure carrying an adjacency relation and a proof that it is symmetric, with no irreflexivity field; SimpleGraphSimpleGraph is the irreflexive case, toLoopGraphtoLoopGraph the inclusion and toSimpleGraphtoSimpleGraph the passage back, given a proof of IsLooplessIsLoopless. Homomorphisms and isomorphisms, written lg→lg and lg≃lg, are those of the adjacency relations, so FgGF →g G and toLoopGraphFlgtoLoopGraphGtoLoopGraph F →lg toLoopGraph G are definitionally equal and LoopGraph.homCountLoopGraph.homCount extends homCounthomCount along toLoopGraphtoLoopGraph with no transport needed.

    spanningSubgraphFsspanningSubgraph F s takes an arbitrary set ss of unordered pairs, and edgeSetOfFsedgeSetOf F s turns a finite set of edges of FF into the corresponding set of pairs; together they let the deletion part of the expansion be indexed by FinsetF.edgeSetFinset F.edgeSet.

    contractionQuotientFLcontractionQuotient F L likewise takes an arbitrary set LL of pairs; its vertex type is the connected components of SimpleGraph.fromEdgeSetLSimpleGraph.fromEdgeSet L, which discards the diagonal pairs of LL.

    Only as much API is developed as the expansion of hom(F,G)\hom(F, \overline{G}) 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.

    Loading discussion…