state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
e : Sym2 V
v : V
he : e ∈ edgeSet G'
⊢ v ∈ e → v ∈ G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
|
refine' Sym2.ind (fun v w he ↦ _) e he
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.245_0.BlhiAiIDADcXv8t
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
e : Sym2 V
v✝ : V
he✝ : e ∈ edgeSet G'
v w : V
he : ⟦(v, w)⟧ ∈ edgeSet G'
⊢ v✝ ∈ ⟦(v, w)⟧ → v✝ ∈ G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
|
intro hv
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.245_0.BlhiAiIDADcXv8t
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
e : Sym2 V
v✝ : V
he✝ : e ∈ edgeSet G'
v w : V
he : ⟦(v, w)⟧ ∈ edgeSet G'
hv : v✝ ∈ ⟦(v, w)⟧
⊢ v✝ ∈ G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
|
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.245_0.BlhiAiIDADcXv8t
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case inl
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
e : Sym2 V
v : V
he✝ : e ∈ edgeSet G'
w : V
he : ⟦(v, w)⟧ ∈ edgeSet G'
hv : v ∈ ⟦(v, w)⟧
⊢ v ∈ G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
·
|
exact G'.edge_vert he
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.245_0.BlhiAiIDADcXv8t
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case inr
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
e : Sym2 V
v✝ : V
he✝ : e ∈ edgeSet G'
v : V
he : ⟦(v, v✝)⟧ ∈ edgeSet G'
hv : v✝ ∈ ⟦(v, v✝)⟧
⊢ v✝ ∈ G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
·
|
exact G'.edge_vert (G'.symm he)
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.245_0.BlhiAiIDADcXv8t
|
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
⊢ ∀ {v w : V}, (fun a b => ∃ G' ∈ s, Adj G' a b) v w → SimpleGraph.Adj G v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
|
rintro a b ⟨G', -, hab⟩
|
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.327_0.BlhiAiIDADcXv8t
|
instance : SupSet G.Subgraph where
sSup s
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a✝ b✝ : V
s : Set (Subgraph G)
a b : V
G' : Subgraph G
hab : Adj G' a b
⊢ SimpleGraph.Adj G a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
|
exact G'.adj_sub hab
|
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.327_0.BlhiAiIDADcXv8t
|
instance : SupSet G.Subgraph where
sSup s
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
⊢ ∀ {v w : V}, (fun a b => ∃ G' ∈ s, Adj G' a b) v w → v ∈ ⋃ G' ∈ s, G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
|
rintro a b ⟨G', hG', hab⟩
|
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.327_0.BlhiAiIDADcXv8t
|
instance : SupSet G.Subgraph where
sSup s
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a✝ b✝ : V
s : Set (Subgraph G)
a b : V
G' : Subgraph G
hG' : G' ∈ s
hab : Adj G' a b
⊢ a ∈ ⋃ G' ∈ s, G'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
|
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
|
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.327_0.BlhiAiIDADcXv8t
|
instance : SupSet G.Subgraph where
sSup s
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a✝ b✝ : V
s : Set (Subgraph G)
a b : V
h : (fun a b => ∃ G' ∈ s, Adj G' a b) a b
⊢ (fun a b => ∃ G' ∈ s, Adj G' a b) b a
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by
|
simpa [adj_comm] using h
|
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.327_0.BlhiAiIDADcXv8t
|
instance : SupSet G.Subgraph where
sSup s
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ Adj (⨆ i, f i) a b ↔ ∃ i, Adj (f i) a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
|
simp [iSup]
|
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.397_0.BlhiAiIDADcXv8t
|
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ Adj (⨅ i, f i) a b ↔ (∀ (i : ι), Adj (f i) a b) ∧ SimpleGraph.Adj G a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
|
simp [iInf]
|
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.402_0.BlhiAiIDADcXv8t
|
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
hs : Set.Nonempty s
⊢ (∀ G' ∈ s, Adj G' a b) → SimpleGraph.Adj G a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
|
obtain ⟨G', hG'⟩ := hs
|
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.407_0.BlhiAiIDADcXv8t
|
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
G' : Subgraph G
hG' : G' ∈ s
⊢ (∀ G' ∈ s, Adj G' a b) → SimpleGraph.Adj G a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
|
exact fun h => G'.adj_sub (h _ hG')
|
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.407_0.BlhiAiIDADcXv8t
|
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
inst✝ : Nonempty ι
f : ι → Subgraph G
⊢ Adj (⨅ i, f i) a b ↔ ∀ (i : ι), Adj (f i) a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
|
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
|
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.415_0.BlhiAiIDADcXv8t
|
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
inst✝ : Nonempty ι
f : ι → Subgraph G
⊢ (∀ G' ∈ Set.range fun i => f i, Adj G' a b) ↔ ∀ (i : ι), Adj (f i) a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
|
simp
|
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.415_0.BlhiAiIDADcXv8t
|
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ (⨆ i, f i).verts = ⋃ i, (f i).verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by
|
simp [iSup]
|
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.431_0.BlhiAiIDADcXv8t
|
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ (⨅ i, f i).verts = ⋂ i, (f i).verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by
|
simp [iInf]
|
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.435_0.BlhiAiIDADcXv8t
|
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
⊢ Function.Injective fun G' => (G'.verts, Subgraph.spanningCoe G')
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
|
intro G₁ G₂ h
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.439_0.BlhiAiIDADcXv8t
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁✝ G₂✝ : Subgraph G
a b : V
G₁ G₂ : Subgraph G
h : (fun G' => (G'.verts, Subgraph.spanningCoe G')) G₁ = (fun G' => (G'.verts, Subgraph.spanningCoe G')) G₂
⊢ G₁ = G₂
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
|
rw [Prod.ext_iff] at h
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.439_0.BlhiAiIDADcXv8t
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁✝ G₂✝ : Subgraph G
a b : V
G₁ G₂ : Subgraph G
h :
((fun G' => (G'.verts, Subgraph.spanningCoe G')) G₁).1 = ((fun G' => (G'.verts, Subgraph.spanningCoe G')) G₂).1 ∧
((fun G' => (G'.verts, Subgraph.spanningCoe G')) G₁).2 = ((fun G' => (G'.verts, Subgraph.spanningCoe G')) G₂).2
⊢ G₁ = G₂
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
|
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.439_0.BlhiAiIDADcXv8t
|
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
src✝ : DistribLattice (Subgraph G) := distribLattice
s : Set (Subgraph G)
G' : Subgraph G
hG' : G' ∈ s
⊢ G'.verts ⊆ (sSup s).verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by
|
apply Set.subset_iUnion₂ G' hG'
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
src✝ : DistribLattice (Subgraph G) := distribLattice
s : Set (Subgraph G)
G' : Subgraph G
hG' : ∀ b ∈ s, b ≤ G'
⊢ ∀ ⦃v w : V⦄, Adj (sSup s) v w → Adj G' v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
|
rintro a b ⟨H, hH, hab⟩
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a✝ b✝ : V
src✝ : DistribLattice (Subgraph G) := distribLattice
s : Set (Subgraph G)
G' : Subgraph G
hG' : ∀ b ∈ s, b ≤ G'
a b : V
H : Subgraph G
hH : H ∈ s
hab : Adj H a b
⊢ Adj G' a b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
|
exact (hG' _ hH).2 hab
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
src✝ : DistribLattice (Subgraph G) := distribLattice
ι✝ : Type u
κ✝ : ι✝ → Type u
f : (a : ι✝) → κ✝ a → Subgraph G
⊢ (⨅ a, ⨆ b, f a b).verts = (⨆ g, ⨅ a, f a (g a)).verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by
|
simpa using iInf_iSup_eq
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
src✝ : DistribLattice (Subgraph G) := distribLattice
ι✝ : Type u
κ✝ : ι✝ → Type u
f : (a : ι✝) → κ✝ a → Subgraph G
⊢ (⨅ a, ⨆ b, f a b).Adj = (⨆ g, ⨅ a, f a (g a)).Adj
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by
|
ext
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h.h.a
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
src✝ : DistribLattice (Subgraph G) := distribLattice
ι✝ : Type u
κ✝ : ι✝ → Type u
f : (a : ι✝) → κ✝ a → Subgraph G
x✝¹ x✝ : V
⊢ Adj (⨅ a, ⨆ b, f a b) x✝¹ x✝ ↔ Adj (⨆ g, ⨅ a, f a (g a)) x✝¹ x✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext;
|
simp [Classical.skolem]
|
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext;
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.460_0.BlhiAiIDADcXv8t
|
instance : CompletelyDistribLattice G.Subgraph
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
v : V
⊢ neighborSet (sSup s) v = ⋃ G' ∈ s, neighborSet G' v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
|
ext
|
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.506_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
v x✝ : V
⊢ x✝ ∈ neighborSet (sSup s) v ↔ x✝ ∈ ⋃ G' ∈ s, neighborSet G' v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
|
simp
|
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.506_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
v : V
⊢ neighborSet (sInf s) v = (⋂ G' ∈ s, neighborSet G' v) ∩ SimpleGraph.neighborSet G v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
|
ext
|
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.513_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
v x✝ : V
⊢ x✝ ∈ neighborSet (sInf s) v ↔ x✝ ∈ (⋂ G' ∈ s, neighborSet G' v) ∩ SimpleGraph.neighborSet G v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
|
simp
|
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.513_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
v : V
⊢ neighborSet (⨆ i, f i) v = ⋃ i, neighborSet (f i) v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by
|
simp [iSup]
|
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.520_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
v : V
⊢ neighborSet (⨅ i, f i) v = (⋂ i, neighborSet (f i) v) ∩ SimpleGraph.neighborSet G v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by
|
simp [iInf]
|
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.525_0.BlhiAiIDADcXv8t
|
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
⊢ ∀ (x y : V), ⟦(x, y)⟧ ∈ edgeSet ⊥ ↔ ⟦(x, y)⟧ ∈ ∅
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by
|
simp
|
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.534_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
H₁ H₂ : Subgraph G
⊢ ∀ (x y : V), ⟦(x, y)⟧ ∈ edgeSet (H₁ ⊓ H₂) ↔ ⟦(x, y)⟧ ∈ edgeSet H₁ ∩ edgeSet H₂
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by
|
simp
|
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.539_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
H₁ H₂ : Subgraph G
⊢ ∀ (x y : V), ⟦(x, y)⟧ ∈ edgeSet (H₁ ⊔ H₂) ↔ ⟦(x, y)⟧ ∈ edgeSet H₁ ∪ edgeSet H₂
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by
|
simp
|
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.544_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
⊢ edgeSet (sSup s) = ⋃ G' ∈ s, edgeSet G'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
|
ext e
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.549_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G'
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
e : Sym2 V
⊢ e ∈ edgeSet (sSup s) ↔ e ∈ ⋃ G' ∈ s, edgeSet G'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
|
induction e using Sym2.ind
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.549_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G'
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h.h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
x✝ y✝ : V
⊢ ⟦(x✝, y✝)⟧ ∈ edgeSet (sSup s) ↔ ⟦(x✝, y✝)⟧ ∈ ⋃ G' ∈ s, edgeSet G'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
|
simp
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.549_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G'
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
⊢ edgeSet (sInf s) = (⋂ G' ∈ s, edgeSet G') ∩ SimpleGraph.edgeSet G
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
|
ext e
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.556_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
e : Sym2 V
⊢ e ∈ edgeSet (sInf s) ↔ e ∈ (⋂ G' ∈ s, edgeSet G') ∩ SimpleGraph.edgeSet G
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
|
induction e using Sym2.ind
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.556_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case h.h
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
s : Set (Subgraph G)
x✝ y✝ : V
⊢ ⟦(x✝, y✝)⟧ ∈ edgeSet (sInf s) ↔ ⟦(x✝, y✝)⟧ ∈ (⋂ G' ∈ s, edgeSet G') ∩ SimpleGraph.edgeSet G
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
|
simp
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.556_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ edgeSet (⨆ i, f i) = ⋃ i, edgeSet (f i)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by
|
simp [iSup]
|
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.564_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
f : ι → Subgraph G
⊢ edgeSet (⨅ i, f i) = (⋂ i, edgeSet (f i)) ∩ SimpleGraph.edgeSet G
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
|
simp [iInf]
|
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.569_0.BlhiAiIDADcXv8t
|
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
H₁ H₂ : Subgraph G
h : Disjoint H₁ H₂
⊢ SimpleGraph.Subgraph.edgeSet H₁ ⊓ SimpleGraph.Subgraph.edgeSet H₂ ≤ ⊥
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by
|
simpa using edgeSet_mono h.le_bot
|
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.629_0.BlhiAiIDADcXv8t
|
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
⊢ ∀ {v w : W}, Relation.Map H.Adj (⇑f) (⇑f) v w → SimpleGraph.Adj G' v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
|
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
u v : V
h : Adj H u v
⊢ SimpleGraph.Adj G' (f u) (f v)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
exact f.map_rel (H.adj_sub h)
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
⊢ ∀ {v w : W}, Relation.Map H.Adj (⇑f) (⇑f) v w → v ∈ ⇑f '' H.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
|
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
u v : V
h : Adj H u v
⊢ f u ∈ ⇑f '' H.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
exact Set.mem_image_of_mem _ (H.edge_vert h)
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
⊢ Symmetric (Relation.Map H.Adj ⇑f ⇑f)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
|
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
u v : V
h : Adj H u v
⊢ Relation.Map H.Adj (⇑f) (⇑f) (f v) (f u)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
exact ⟨v, u, H.symm h, rfl, rfl⟩
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.634_0.BlhiAiIDADcXv8t
|
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
⊢ Monotone (Subgraph.map f)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
|
intro H H' h
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
⊢ Subgraph.map f H ≤ Subgraph.map f H'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
|
constructor
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
⊢ (Subgraph.map f H).verts ⊆ (Subgraph.map f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
·
|
intro
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
a✝ : W
⊢ a✝ ∈ (Subgraph.map f H).verts → a✝ ∈ (Subgraph.map f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
|
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
a✝ : W
⊢ ∀ x ∈ H.verts, f x = a✝ → ∃ x ∈ H'.verts, f x = a✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
rintro v hv rfl
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
v : V
hv : v ∈ H.verts
⊢ ∃ x ∈ H'.verts, f x = f v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
|
exact ⟨_, h.1 hv, rfl⟩
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
⊢ ∀ ⦃v w : W⦄, Adj (Subgraph.map f H) v w → Adj (Subgraph.map f H') v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
·
|
rintro _ _ ⟨u, v, ha, rfl, rfl⟩
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right.intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
h : H ≤ H'
u v : V
ha : Adj H u v
⊢ Adj (Subgraph.map f H') (f u) (f v)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
|
exact ⟨_, _, h.2 ha, rfl, rfl⟩
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.650_0.BlhiAiIDADcXv8t
|
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
⊢ Subgraph.map f (H ⊔ H') = Subgraph.map f H ⊔ Subgraph.map f H'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
|
ext1
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case verts
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
⊢ (Subgraph.map f (H ⊔ H')).verts = (Subgraph.map f H ⊔ Subgraph.map f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
·
|
simp only [Set.image_union, map_verts, verts_sup]
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
⊢ (Subgraph.map f (H ⊔ H')).Adj = (Subgraph.map f H ⊔ Subgraph.map f H').Adj
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
·
|
ext
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
x✝¹ x✝ : W
⊢ Adj (Subgraph.map f (H ⊔ H')) x✝¹ x✝ ↔ Adj (Subgraph.map f H ⊔ Subgraph.map f H') x✝¹ x✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
|
simp only [Relation.Map, map_adj, sup_adj]
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
x✝¹ x✝ : W
⊢ (∃ a b, (Adj H a b ∨ Adj H' a b) ∧ f a = x✝¹ ∧ f b = x✝) ↔
(∃ a b, Adj H a b ∧ f a = x✝¹ ∧ f b = x✝) ∨ ∃ a b, Adj H' a b ∧ f a = x✝¹ ∧ f b = x✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
|
constructor
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mp
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
x✝¹ x✝ : W
⊢ (∃ a b, (Adj H a b ∨ Adj H' a b) ∧ f a = x✝¹ ∧ f b = x✝) →
(∃ a b, Adj H a b ∧ f a = x✝¹ ∧ f b = x✝) ∨ ∃ a b, Adj H' a b ∧ f a = x✝¹ ∧ f b = x✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
·
|
rintro ⟨a, b, h | h, rfl, rfl⟩
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mp.intro.intro.intro.inl.intro
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a✝ b✝ : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
a b : V
h : Adj H a b
⊢ (∃ a_1 b_1, Adj H a_1 b_1 ∧ f a_1 = f a ∧ f b_1 = f b) ∨ ∃ a_1 b_1, Adj H' a_1 b_1 ∧ f a_1 = f a ∧ f b_1 = f b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
·
|
exact Or.inl ⟨_, _, h, rfl, rfl⟩
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mp.intro.intro.intro.inr.intro
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a✝ b✝ : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
a b : V
h : Adj H' a b
⊢ (∃ a_1 b_1, Adj H a_1 b_1 ∧ f a_1 = f a ∧ f b_1 = f b) ∨ ∃ a_1 b_1, Adj H' a_1 b_1 ∧ f a_1 = f a ∧ f b_1 = f b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
·
|
exact Or.inr ⟨_, _, h, rfl, rfl⟩
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mpr
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a b : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
x✝¹ x✝ : W
⊢ ((∃ a b, Adj H a b ∧ f a = x✝¹ ∧ f b = x✝) ∨ ∃ a b, Adj H' a b ∧ f a = x✝¹ ∧ f b = x✝) →
∃ a b, (Adj H a b ∨ Adj H' a b) ∧ f a = x✝¹ ∧ f b = x✝
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
·
|
rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mpr.inl.intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a✝ b✝ : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
a b : V
h : Adj H a b
⊢ ∃ a_1 b_1, (Adj H a_1 b_1 ∨ Adj H' a_1 b_1) ∧ f a_1 = f a ∧ f b_1 = f b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
·
|
exact ⟨_, _, Or.inl h, rfl, rfl⟩
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case Adj.h.h.a.mpr.inr.intro.intro.intro.intro
ι : Sort u_1
V : Type u
W : Type v
G✝ : SimpleGraph V
G₁ G₂ : Subgraph G✝
a✝ b✝ : V
G : SimpleGraph V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G
a b : V
h : Adj H' a b
⊢ ∃ a_1 b_1, (Adj H a_1 b_1 ∨ Adj H' a_1 b_1) ∧ f a_1 = f a ∧ f b_1 = f b
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
·
|
exact ⟨_, _, Or.inr h, rfl, rfl⟩
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.661_0.BlhiAiIDADcXv8t
|
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
⊢ Monotone (Subgraph.comap f)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
|
intro H H' h
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
⊢ Subgraph.comap f H ≤ Subgraph.comap f H'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
|
constructor
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
⊢ (Subgraph.comap f H).verts ⊆ (Subgraph.comap f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
·
|
intro
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
a✝ : V
⊢ a✝ ∈ (Subgraph.comap f H).verts → a✝ ∈ (Subgraph.comap f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
|
simp only [comap_verts, Set.mem_preimage]
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case left
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
a✝ : V
⊢ f a✝ ∈ H.verts → f a✝ ∈ H'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
|
apply h.1
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
⊢ ∀ ⦃v w : V⦄, Adj (Subgraph.comap f H) v w → Adj (Subgraph.comap f H') v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
·
|
intro v w
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
v w : V
⊢ Adj (Subgraph.comap f H) v w → Adj (Subgraph.comap f H') v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
|
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
v w : V
⊢ SimpleGraph.Adj G v w → Adj H (f v) (f w) → Adj H' (f v) (f w)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
|
intro
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case right
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H H' : Subgraph G'
h : H ≤ H'
v w : V
a✝ : SimpleGraph.Adj G v w
⊢ Adj H (f v) (f w) → Adj H' (f v) (f w)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
|
apply h.2
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.686_0.BlhiAiIDADcXv8t
|
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
⊢ Subgraph.map f H ≤ H' ↔ H ≤ Subgraph.comap f H'
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
|
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_1
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : Subgraph.map f H ≤ H'
v : V
hv : v ∈ H.verts
⊢ v ∈ (Subgraph.comap f H').verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
·
|
simp only [comap_verts, Set.mem_preimage]
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_1
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : Subgraph.map f H ≤ H'
v : V
hv : v ∈ H.verts
⊢ f v ∈ H'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
|
exact h.1 ⟨v, hv, rfl⟩
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_2
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : Subgraph.map f H ≤ H'
v w : V
hvw : Adj H v w
⊢ Adj (Subgraph.comap f H') v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
·
|
simp only [H.adj_sub hvw, comap_adj, true_and_iff]
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_2
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : Subgraph.map f H ≤ H'
v w : V
hvw : Adj H v w
⊢ Adj H' (f v) (f w)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
|
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_3
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
v : W
⊢ v ∈ (Subgraph.map f H).verts → v ∈ H'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
·
|
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_3
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
v : W
⊢ ∀ x ∈ H.verts, f x = v → v ∈ H'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
rintro w hw rfl
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_3
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
w : V
hw : w ∈ H.verts
⊢ f w ∈ H'.verts
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
|
exact h.1 hw
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_4
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
v w : W
⊢ Adj (Subgraph.map f H) v w → Adj H' v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
·
|
simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
·
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_4
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
v w : W
⊢ ∀ (x x_1 : V), Adj H x x_1 → f x = v → f x_1 = w → Adj H' v w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
|
rintro u u' hu rfl rfl
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
case refine'_4
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : SimpleGraph W
f : G →g G'
H : Subgraph G
H' : Subgraph G'
h : H ≤ Subgraph.comap f H'
u u' : V
hu : Adj H u u'
⊢ Adj H' (f u) (f u')
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
|
exact (h.2 hu).2
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.698_0.BlhiAiIDADcXv8t
|
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
x y : Subgraph G
h : x ≤ y
⊢ Function.Injective ⇑(inclusion h)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
|
intro v w h
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.721_0.BlhiAiIDADcXv8t
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
x y : Subgraph G
h✝ : x ≤ y
v w : ↑x.verts
h : (inclusion h✝) v = (inclusion h✝) w
⊢ v = w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
|
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.721_0.BlhiAiIDADcXv8t
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
x y : Subgraph G
h✝ : x ≤ y
v w : ↑x.verts
h :
↑(RelHomClass.toFunLike.1
{ toFun := fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) },
map_rel' :=
(_ :
∀ {a b : ↑x.verts},
SimpleGraph.Adj (Subgraph.coe x) a b →
Adj y ↑((fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) }) a)
↑((fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) }) b)) }
v) =
↑(RelHomClass.toFunLike.1
{ toFun := fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) },
map_rel' :=
(_ :
∀ {a b : ↑x.verts},
SimpleGraph.Adj (Subgraph.coe x) a b →
Adj y ↑((fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) }) a)
↑((fun v => { val := ↑v, property := (_ : ↑v ∈ y.verts) }) b)) }
w)
⊢ v = w
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
|
exact Subtype.ext h
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.721_0.BlhiAiIDADcXv8t
|
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h)
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
inst✝¹ : Fintype V
G' : Subgraph G
inst✝ : Fintype ↑G'.verts
h : IsSpanning G'
⊢ Finset.card (Set.toFinset G'.verts) = Fintype.card V
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
|
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
|
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.786_0.BlhiAiIDADcXv8t
|
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
inst✝¹ : Fintype V
G' : Subgraph G
inst✝ : Fintype ↑G'.verts
h : IsSpanning G'
⊢ Finset.card Finset.univ = Fintype.card V
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
|
congr
|
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.786_0.BlhiAiIDADcXv8t
|
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
v : V
inst✝ : Fintype ↑(neighborSet G' v)
⊢ Finset.card (Set.toFinset (neighborSet G' v)) = degree G' v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
#align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ :=
Fintype.card (G'.neighborSet v)
#align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
|
rw [degree, Set.toFinset_card]
|
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.797_0.BlhiAiIDADcXv8t
|
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
v : V
inst✝¹ : Fintype ↑(neighborSet G' v)
inst✝ : Fintype ↑(SimpleGraph.neighborSet G v)
⊢ degree G' v ≤ SimpleGraph.degree G v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
#align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ :=
Fintype.card (G'.neighborSet v)
#align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
rw [degree, Set.toFinset_card]
#align simple_graph.subgraph.finset_card_neighbor_set_eq_degree SimpleGraph.Subgraph.finset_card_neighborSet_eq_degree
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
|
rw [← card_neighborSet_eq_degree]
|
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.802_0.BlhiAiIDADcXv8t
|
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
v : V
inst✝¹ : Fintype ↑(neighborSet G' v)
inst✝ : Fintype ↑(SimpleGraph.neighborSet G v)
⊢ degree G' v ≤ Fintype.card ↑(SimpleGraph.neighborSet G v)
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
#align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ :=
Fintype.card (G'.neighborSet v)
#align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
rw [degree, Set.toFinset_card]
#align simple_graph.subgraph.finset_card_neighbor_set_eq_degree SimpleGraph.Subgraph.finset_card_neighborSet_eq_degree
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
rw [← card_neighborSet_eq_degree]
|
exact Set.card_le_of_subset (G'.neighborSet_subset v)
|
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
rw [← card_neighborSet_eq_degree]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.802_0.BlhiAiIDADcXv8t
|
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
v : ↑G'.verts
inst✝¹ : Fintype ↑(SimpleGraph.neighborSet (Subgraph.coe G') v)
inst✝ : Fintype ↑(neighborSet G' ↑v)
⊢ SimpleGraph.degree (Subgraph.coe G') v = degree G' ↑v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
#align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ :=
Fintype.card (G'.neighborSet v)
#align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
rw [degree, Set.toFinset_card]
#align simple_graph.subgraph.finset_card_neighbor_set_eq_degree SimpleGraph.Subgraph.finset_card_neighborSet_eq_degree
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
rw [← card_neighborSet_eq_degree]
exact Set.card_le_of_subset (G'.neighborSet_subset v)
#align simple_graph.subgraph.degree_le SimpleGraph.Subgraph.degree_le
theorem degree_le' (G' G'' : Subgraph G) (h : G' ≤ G'') (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G''.neighborSet v)] : G'.degree v ≤ G''.degree v :=
Set.card_le_of_subset (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.degree_le' SimpleGraph.Subgraph.degree_le'
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by
|
rw [← card_neighborSet_eq_degree]
|
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.813_0.BlhiAiIDADcXv8t
|
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
ι : Sort u_1
V : Type u
W : Type v
G : SimpleGraph V
G₁ G₂ : Subgraph G
a b : V
G' : Subgraph G
v : ↑G'.verts
inst✝¹ : Fintype ↑(SimpleGraph.neighborSet (Subgraph.coe G') v)
inst✝ : Fintype ↑(neighborSet G' ↑v)
⊢ Fintype.card ↑(SimpleGraph.neighborSet (Subgraph.coe G') v) = degree G' ↑v
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
#align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
verts : Set V
Adj : V → V → Prop
adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w
edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
#align simple_graph.subgraph SimpleGraph.Subgraph
initialize_simps_projections SimpleGraph.Subgraph (Adj → adj)
variable {ι : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
#align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := ⟦(v, w)⟧ = ⟦(a, b)⟧
adj_sub h := by
rw [← G.mem_edgeSet, ← h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e ↦ a ∈ e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
#align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj
namespace Subgraph
variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h ↦ G.loopless v (G'.adj_sub h)
#align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v :=
⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩
#align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
#align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
#align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts :=
H.edge_vert h
#align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts :=
h.symm.fst_mem
#align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v :=
h.adj_sub.ne
#align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
#align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h
#align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
∀ v : V, v ∈ G'.verts
#align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
#align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
#align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
#align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe
theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by
simp [Subgraph.spanningCoe]
#align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe
where
toFun v := ⟨v, h v⟩
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w
#align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
#align simple_graph.subgraph.support SimpleGraph.Subgraph.support
theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support
theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts :=
fun _ ⟨_, h⟩ ↦ H.edge_vert h
#align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
#align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v :=
fun _ ↦ G'.adj_sub
#align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts :=
fun _ h ↦ G'.edge_vert (adj_symm G' h)
#align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v
where
toFun w := ⟨w, w.2⟩
invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
#align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet :=
Sym2.ind (fun _ _ ↦ G'.adj_sub)
#align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset
@[simp]
theorem mem_edgeSet {G' : Subgraph G} {v w : V} : ⟦(v, w)⟧ ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl
#align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet
theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet)
(hv : v ∈ e) : v ∈ G'.verts := by
revert hv
refine' Sym2.ind (fun v w he ↦ _) e he
intro hv
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
· exact G'.edge_vert he
· exact G'.edge_vert (G'.symm he)
#align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e}
#align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v ⊆ G.incidenceSet v :=
fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩
#align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet :=
fun _ h ↦ h.1
#align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩
#align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm ▸ G'.adj_sub
edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert
symm := hadj.symm ▸ G'.symm
#align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext _ _ hV hadj
#align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq
/-- The union of two subgraphs. -/
instance : Sup G.Subgraph where
sup G₁ G₂ :=
{ verts := G₁.verts ∪ G₂.verts
Adj := G₁.Adj ⊔ G₂.Adj
adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h
edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Inf G.Subgraph where
inf G₁ G₂ :=
{ verts := G₁.verts ∩ G₂.verts
Adj := G₁.Adj ⊓ G₂.Adj
adj_sub := fun hab => G₁.adj_sub hab.1
edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h
symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := ∅
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := ⋃ G' ∈ s, verts G'
Adj := fun a b => ∃ G' ∈ s, Adj G' a b
adj_sub := by
rintro a b ⟨G', -, hab⟩
exact G'.adj_sub hab
edge_vert := by
rintro a b ⟨G', hG', hab⟩
exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := ⋂ G' ∈ s, verts G'
Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj
@[simp]
theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj
@[simp]
theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj
@[simp]
theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b :=
not_false
#align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj
@[simp]
theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup
@[simp]
theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts :=
rfl
#align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf
@[simp]
theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ :=
rfl
#align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top
@[simp]
theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ :=
rfl
#align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b :=
Iff.rfl
#align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by
simp [iSup]
#align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by
simp [iInf]
#align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G', hG'⟩ := hs
exact fun h => G'.adj_sub (h _ hG')
#align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
#align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' :=
rfl
#align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf
@[simp]
theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup]
#align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup
@[simp]
theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf]
#align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro G₁ G₂ h
rw [Prod.ext_iff] at h
exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and
`∀ a b, G₁.adj a b → G₂.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := ⊤
bot := ⊥
le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩
bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩
-- Note that subgraphs do not form a Boolean algebra, because of `verts`.
instance : CompletelyDistribLattice G.Subgraph :=
{ Subgraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
top := ⊤
bot := ⊥
le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩
bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩
sSup := sSup
-- porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩
sSup_le := fun s G' hG' =>
⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by
rintro a b ⟨H, hH, hab⟩
exact (hG' _ hH).2 hab⟩
sInf := sInf
sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩
le_sInf := fun s G' hG' =>
⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab =>
⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩
iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩
#align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf
@[simp]
theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
#align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top
@[simp]
theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl
#align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by
ext
simp
#align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf
@[simp]
theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) :
(⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup]
#align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup
@[simp]
theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) :
(⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf]
#align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf
@[simp]
theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl
#align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top
@[simp]
theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot
@[simp]
theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf
@[simp]
theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet :=
Set.ext <| Sym2.ind (by simp)
#align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by
ext e
induction e using Sym2.ind
simp
#align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf
@[simp]
theorem edgeSet_iSup (f : ι → G.Subgraph) :
(⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup]
#align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup
@[simp]
theorem edgeSet_iInf (f : ι → G.Subgraph) :
(⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by
simp [iInf]
#align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf
@[simp]
theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl
#align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top
@[simp]
theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl
#align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
#align simple_graph.to_subgraph SimpleGraph.toSubgraph
theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support :=
Rel.dom_mono h.2
#align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
#align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe :=
h.2
#align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (⊤ : Subgraph G).coe ≃g G where
toFun v := ↑v
invFun v := ⟨v, trivial⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun ⟨_, h⟩ ↦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
#align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv
theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet :=
Sym2.ind h.2
#align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono
theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) :
Disjoint H₁.edgeSet H₂.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
#align disjoint.edge_set Disjoint.edgeSet
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ ⟨u, v, h, rfl, rfl⟩
exact ⟨v, u, H.symm h, rfl, rfl⟩
#align simple_graph.subgraph.map SimpleGraph.Subgraph.map
theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by
intro H H' h
constructor
· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact ⟨_, h.1 hv, rfl⟩
· rintro _ _ ⟨u, v, ha, rfl, rfl⟩
exact ⟨_, _, h.2 ha, rfl, rfl⟩
#align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone
theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} :
(H ⊔ H').map f = H.map f ⊔ H'.map f := by
ext1
· simp only [Set.image_union, map_verts, verts_sup]
· ext
simp only [Relation.Map, map_adj, sup_adj]
constructor
· rintro ⟨a, b, h | h, rfl, rfl⟩
· exact Or.inl ⟨_, _, h, rfl, rfl⟩
· exact Or.inr ⟨_, _, h, rfl, rfl⟩
· rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩)
· exact ⟨_, _, Or.inl h, rfl, rfl⟩
· exact ⟨_, _, Or.inr h, rfl, rfl⟩
#align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where
verts := f ⁻¹' H.verts
Adj u v := G.Adj u v ∧ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩
#align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
· intro v w
simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff]
intro
apply h.2
#align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f ≤ H' ↔ H ≤ H'.comap f := by
refine' ⟨fun h ↦ ⟨fun v hv ↦ _, fun v w hvw ↦ _⟩, fun h ↦ ⟨fun v ↦ _, fun v w ↦ _⟩⟩
· simp only [comap_verts, Set.mem_preimage]
exact h.1 ⟨v, hv, rfl⟩
· simp only [H.adj_sub hvw, comap_adj, true_and_iff]
exact h.2 ⟨v, w, hvw, rfl, rfl⟩
· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
#align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where
toFun v := ⟨↑v, And.left h v.property⟩
map_rel' hvw := h.2 hvw
#align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion
theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, FunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
#align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe →g G where
toFun v := v
map_rel' := x.adj_sub
#align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom.injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ ↦ Subtype.ext
#align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe →g G where
toFun := id
map_rel' := x.adj_sub
#align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom
theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ ↦ id
#align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) :
x.neighborSet v ⊆ y.neighborSet v :=
fun _ h' ↦ h.2 h'
#align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (· ∈ G'.neighborSet v) :=
h v
#align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
#align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
#align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
#align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ :=
Fintype.card (G'.neighborSet v)
#align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
rw [degree, Set.toFinset_card]
#align simple_graph.subgraph.finset_card_neighbor_set_eq_degree SimpleGraph.Subgraph.finset_card_neighborSet_eq_degree
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
rw [← card_neighborSet_eq_degree]
exact Set.card_le_of_subset (G'.neighborSet_subset v)
#align simple_graph.subgraph.degree_le SimpleGraph.Subgraph.degree_le
theorem degree_le' (G' G'' : Subgraph G) (h : G' ≤ G'') (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G''.neighborSet v)] : G'.degree v ≤ G''.degree v :=
Set.card_le_of_subset (neighborSet_subset_of_subgraph h v)
#align simple_graph.subgraph.degree_le' SimpleGraph.Subgraph.degree_le'
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by
rw [← card_neighborSet_eq_degree]
|
exact Fintype.card_congr (coeNeighborSetEquiv v)
|
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by
rw [← card_neighborSet_eq_degree]
|
Mathlib.Combinatorics.SimpleGraph.Subgraph.813_0.BlhiAiIDADcXv8t
|
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v
|
Mathlib_Combinatorics_SimpleGraph_Subgraph
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.