|
|
|
|
Quelle Copy.lean
Sprache: Lean
|
|
/-
Copyright (c) 2023 Yaël Dillies, Mitchell Horner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Mitchell Horner
-/
module
public import Mathlib.Combinatorics.SimpleGraph.Subgraph
/-!
# Containment of graphs
This file introduces the concept of one simple graph containing a copy of another.
For two simple graphs `G` and `H`, a *copy* of `G` in `H` is a (not necessarily induced) subgraph of
`H` isomorphic to `G`.
If there exists a copy of `G` in `H`, we say that `H` *contains* `G`. This is equivalent to saying
that there is an injective graph homomorphism `G → H` between them (this is **not** the same as a
graph embedding, as we do not require the subgraph to be induced).
If there exists an induced copy of `G` in `H`, we say that `H` *inducingly contains* `G`. This is
equivalent to saying that there is a graph embedding `G ↪ H`.
## Main declarations
Containment:
* `SimpleGraph.Copy G H` is the type of copies of `G` in `H`, implemented as the subtype of
*injective* homomorphisms.
* `SimpleGraph.IsContained G H`, `G ⊑ H` is the relation that `H` contains a copy of `G`, that
is, the type of copies of `G` in `H` is nonempty. This is equivalent to the existence of an
isomorphism from `G` to a subgraph of `H`.
This is similar to `SimpleGraph.IsSubgraph` except that the simple graphs here need not have the
same underlying vertex type.
* `SimpleGraph.Free` is the predicate that `H` is `G`-free, that is, `H` does not contain a copy of
`G`. This is the negation of `SimpleGraph.IsContained` implemented for convenience.
* `SimpleGraph.killCopies G H`: Subgraph of `G` that does not contain `H`. Obtained by arbitrarily
removing an edge from each copy of `H` in `G`.
* `SimpleGraph.copyCount G H`: Number of copies of `H` in `G`, i.e. number of subgraphs of `G`
isomorphic to `H`.
* `SimpleGraph.labelledCopyCount G H`: Number of labelled copies of `H` in `G`, i.e. number of
graph embeddings from `H` to `G`.
Induced containment:
* Induced copies of `G` inside `H` are already defined as `G ↪g H`.
* `SimpleGraph.IsIndContained G H` : `G` is contained as an induced subgraph in `H`.
## Notation
The following notation is declared in scope `SimpleGraph`:
* `G ⊑ H` for `SimpleGraph.IsContained G H`.
* `G ⊴ H` for `SimpleGraph.IsIndContained G H`.
## TODO
* Relate `⊥ ⊴ H` to there being an independent set in `H`.
* Count induced copies of a graph inside another.
* Make `copyCount`/`labelledCopyCount` computable (not necessarily efficiently).
-/
@[expose] public section
open Finset Function
open Fintype (card)
namespace SimpleGraph
variable {V W X : Type*} {G G₁ G₂ G₃ : SimpleGraph V} {H : SimpleGraph W} {I : SimpleGraph X}
/-!
### Copies
#### Not necessarily induced copies
A copy of a subgraph `G` inside a subgraph `H` is an embedding of the vertices of `G` into the
vertices of `H`, such that adjacency in `G` implies adjacency in `H`.
We capture this concept by injective graph homomorphisms.
-/
section Copy
/-- The type of copies as a subtype of *injective* homomorphisms. -/
structure Copy (H : SimpleGraph W) (G : SimpleGraph V) where
/-- A copy gives rise to a homomorphism. -/
toHom : H →g G
injective' : Injective toHom
/-- An injective homomorphism gives rise to a copy. -/
abbrev Hom.toCopy (f : H →g G) (h : Injective f) : Copy H G := .mk f h
/-- An embedding gives rise to a copy. -/
abbrev Embedding.toCopy (f : H ↪g G) : Copy H G := f.toHom.toCopy f.injective
/-- An isomorphism gives rise to a copy. -/
abbrev Iso.toCopy (f : H ≃g G) : Copy H G := f.toEmbedding.toCopy
namespace Copy
@[macro_inline]
instance : FunLike (Copy H G) W V where
coe f := DFunLike.coe f.toHom
coe_injective f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; congr!
lemma injective (f : Copy H G) : Injective f.toHom := f.injective'
@[ext] lemma ext {f g : Copy H G} : (∀ a, f a = g a) → f = g := DFunLike.ext _ _
@[simp] lemma coe_toHom (f : Copy H G) : ⇑f.toHom = f := rfl
@[simp] lemma toHom_apply (f : Copy H G) (a : W) : ⇑f.toHom a = f a := rfl
@[simp] lemma coe_mk (f : H →g G) (hf) : ⇑(.mk f hf : Copy H G) = f := rfl
/-- A copy induces an embedding of edge sets. -/
def mapEdgeSet (f : Copy H G) : H.edgeSet ↪ G.edgeSet where
toFun := f.toHom.mapEdgeSet
inj' := Hom.mapEdgeSet.injective f.toHom f.injective
/-- A copy induces an embedding of neighbor sets. -/
def mapNeighborSet (f : Copy H G) (a : W) :
H.neighborSet a ↪ G.neighborSet (f a) where
toFun v := ⟨f v, f.toHom.apply_mem_neighborSet v.prop⟩
inj' _ _ h := by
rw [Subtype.mk_eq_mk] at h ⊢
exact f.injective h
/-- A copy gives rise to an embedding of vertex types. -/
def toEmbedding (f : Copy H G) : W ↪ V := ⟨f, f.injective⟩
/-- The identity copy from a simple graph to itself. -/
@[refl] def id (G : SimpleGraph V) : Copy G G := ⟨Hom.id, Function.injective_id⟩
@[simp, norm_cast] lemma coe_id : ⇑(id G) = _root_.id := rfl
/-- The composition of copies is a copy. -/
def comp (g : Copy G I) (f : Copy H G) : Copy H I := by
use g.toHom.comp f.toHom
rw [Hom.coe_comp]
exact g.injective.comp f.injective
@[simp]
theorem comp_apply (g : Copy G I) (f : Copy H G) (a : W) : g.comp f a = g (f a) :=
RelHom.comp_apply g.toHom f.toHom a
/-- The copy from a subgraph to the supergraph. -/
def ofLE (G₁ G₂ : SimpleGraph V) (h : G₁ ≤ G₂) : Copy G₁ G₂ := ⟨Hom.ofLE h, Function.injective_id⟩
@[simp, norm_cast]
theorem coe_comp (g : Copy G I) (f : Copy H G) : ⇑(g.comp f) = g ∘ f := by ext; simp
@[simp, norm_cast] lemma coe_ofLE (h : G₁ ≤ G₂) : ⇑(ofLE G₁ G₂ h) = _root_.id := rfl
@[simp] theorem ofLE_refl : ofLE G G le_rfl = id G := by ext; simp
@[simp]
theorem ofLE_comp (h₁₂ : G₁ ≤ G₂) (h₂₃ : G₂ ≤ G₃) :
(ofLE _ _ h₂₃).comp (ofLE _ _ h₁₂) = ofLE _ _ (h₁₂.trans h₂₃) := by ext; simp
/-- The copy from an induced subgraph to the initial simple graph. -/
def induce (G : SimpleGraph V) (s : Set V) : Copy (G.induce s) G := (Embedding.induce s).toCopy
/-- The copy of `⊥` in any simple graph that can embed its vertices. -/
protected def bot (f : W ↪ V) : Copy (⊥ : SimpleGraph W) G := ⟨⟨f, False.elim⟩, f.injective⟩
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The isomorphism from a subgraph of `H` to its map under a copy `f : Copy H G`. -/
noncomputable def isoSubgraphMap (f : Copy H G) (A' : H.Subgraph) :
A'.coe ≃g (A'.map f.toHom).coe := by
use Equiv.Set.image f.toHom _ f.injective
simp_rw [Subgraph.map_verts, Equiv.Set.image_apply, Subgraph.coe_adj, Subgraph.map_adj,
Relation.map_apply, f.injective.eq_iff, exists_eq_right_right, exists_eq_right, forall_true_iff]
/-- The subgraph of `G` corresponding to a copy of `H` inside `G`. -/
abbrev toSubgraph (f : Copy H G) : G.Subgraph := .map f.toHom ⊤
/-- The isomorphism from `H` to its copy under `f : Copy H G`. -/
noncomputable def isoToSubgraph (f : Copy H G) : H ≃g f.toSubgraph.coe :=
(f.isoSubgraphMap ⊤).comp Subgraph.topIso.symm
@[simp] lemma range_toSubgraph :
.range (toSubgraph (H := H)) = {G' : G.Subgraph | Nonempty (H ≃g G'.coe)} := by
ext H'
constructor
· rintro ⟨f, hf, rfl⟩
simpa [toSubgraph] using ⟨f.isoToSubgraph⟩
· rintro ⟨e⟩
refine ⟨⟨H'.hom.comp e.toHom, Subgraph.hom_injective.comp e.injective⟩, ?_⟩
simp [toSubgraph, Subgraph.map_comp]
lemma toSubgraph_surjOn :
Set.SurjOn (toSubgraph (H := H)) .univ {G' : G.Subgraph | Nonempty (H ≃g G'.coe)} :=
fun H' hH' ↦ by simpa
instance [Subsingleton (V → W)] : Subsingleton (G.Copy H) := DFunLike.coe_injective.subsingleton
instance [Fintype {f : G →g H // Injective f}] : Fintype (G.Copy H) :=
.ofEquiv {f : G →g H // Injective f} {
toFun f := ⟨f.1, f.2⟩
invFun f := ⟨f.1, f.2⟩
}
/-- A copy of `⊤` gives rise to an embedding of `⊤`. -/
@[simps!]
def topEmbedding (f : Copy (⊤ : SimpleGraph W) G) : (⊤ : SimpleGraph W) ↪g G :=
{ f.toEmbedding with
map_rel_iff' := fun {v w} ↦ ⟨fun h ↦ by simpa using h.ne, f.toHom.map_adj⟩}
end Copy
/-- A `Subgraph G` gives rise to a copy from the coercion to `G`. -/
def Subgraph.coeCopy (G' : G.Subgraph) : Copy G'.coe G := G'.hom.toCopy hom_injective
end Copy
/-!
#### Induced copies
An induced copy of a graph `G` inside a graph `H` is an embedding from the vertices of
`G` into the vertices of `H` which preserves the adjacency relation.
This is already captured by the notion of graph embeddings, defined as `G ↪g H`.
### Containment
#### Not necessarily induced containment
A graph `H` *contains* a graph `G` if there is some copy `f : Copy G H` of `G` inside `H`. This
amounts to `H` having a subgraph isomorphic to `G`.
We denote "`G` is contained in `H`" by `G ⊑ H` (`\squb`).
-/
section IsContained
/-- The relation `IsContained H G`, `H ⊑ G` says that `G` contains a copy of `H`.
This is equivalent to the existence of an isomorphism from `H` to a subgraph of `G`. -/
abbrev IsContained (H : SimpleGraph W) (G : SimpleGraph V) := Nonempty (Copy H G)
@[inherit_doc] scoped infixl:50 " ⊑ " => SimpleGraph.IsContained
/-- A simple graph contains itself. -/
@[refl] protected theorem IsContained.refl (G : SimpleGraph V) : G ⊑ G := ⟨.id G⟩
protected theorem IsContained.rfl : G ⊑ G := IsContained.refl G
/-- A simple graph contains its subgraphs. -/
theorem IsContained.of_le (h : G₁ ≤ G₂) : G₁ ⊑ G₂ := ⟨.ofLE G₁ G₂ h⟩
/-- If `G` contains `H` and `I` contains `G`, then `I` contains `H`. -/
theorem IsContained.trans : H ⊑ G → G ⊑ I → H ⊑ I := fun ⟨f⟩ ⟨g⟩ ↦ ⟨g.comp f⟩
/-- If `I` contains `G` and `G` contains `H`, then `I` contains `H`. -/
theorem IsContained.trans' : G ⊑ I → H ⊑ G → H ⊑ I := flip IsContained.trans
@[gcongr]
lemma IsContained.mono_right {G' : SimpleGraph V} (h_isub : H ⊑ G) (h_sub : G ≤ G') : H ⊑ G' :=
h_isub.trans <| IsContained.of_le h_sub
alias IsContained.trans_le := IsContained.mono_right
@[gcongr]
lemma IsContained.mono_left {H' : SimpleGraph W} (h_sub : H ≤ H') (h_isub : H' ⊑ G) : H ⊑ G :=
(IsContained.of_le h_sub).trans h_isub
alias IsContained.trans_le' := IsContained.mono_left
/-- If `H ≃g H'` and `G ≃g G'` then `H` is contained in `G` if and only if `H'` is contained
in `G'`. -/
theorem isContained_congr {V' W' : Type*} {G' : SimpleGraph V'} {H' : SimpleGraph W'}
(e₁ : H ≃g H') (e₂ : G ≃g G') : H ⊑ G ↔ H' ⊑ G' :=
⟨.trans' ⟨e₂.toCopy⟩ ∘ .trans ⟨e₁.symm.toCopy⟩, .trans' ⟨e₂.symm.toCopy⟩ ∘ .trans ⟨e₁.toCopy⟩⟩
lemma isContained_congr_left (e₁ : H ≃g G) : H ⊑ I ↔ G ⊑ I := isContained_congr e₁ .refl
alias ⟨_, IsContained.congr_left⟩ := isContained_congr_left
lemma isContained_congr_right (e₂ : G ≃g I) : H ⊑ G ↔ H ⊑ I := isContained_congr .refl e₂
alias ⟨_, IsContained.congr_right⟩ := isContained_congr_right
instance : IsPreorder (SimpleGraph W) IsContained where
refl := .refl
trans _ _ _ := .trans
instance :
Trans (α := SimpleGraph W) (β := SimpleGraph V) (γ := SimpleGraph X)
IsContained IsContained IsContained where
trans := .trans
/-- A simple graph having no vertices is contained in any simple graph. -/
@[simp] lemma IsContained.of_isEmpty [IsEmpty W] : H ⊑ G :=
⟨⟨isEmptyElim, fun {a} ↦ isEmptyElim a⟩, isEmptyElim⟩
/-- `⊥` is contained in any simple graph having sufficiently many vertices. -/
lemma bot_isContained_iff_card_le [Fintype W] [Fintype V] :
(⊥ : SimpleGraph W) ⊑ G ↔ Fintype.card W ≤ Fintype.card V :=
⟨fun ⟨f⟩ ↦ Fintype.card_le_of_embedding f.toEmbedding,
fun h ↦ ⟨Copy.bot (Function.Embedding.nonempty_of_card_le h).some⟩⟩
protected alias IsContained.bot := bot_isContained_iff_card_le
/-- A simple graph `G` contains all `Subgraph G` coercions. -/
lemma Subgraph.coe_isContained (G' : G.Subgraph) : G'.coe ⊑ G := ⟨G'.coeCopy⟩
/-- `G` contains `H` if and only if `G` has a subgraph `G'` and `G'` is isomorphic to `H`. -/
theorem isContained_iff_exists_iso_subgraph :
H ⊑ G ↔ ∃ G' : G.Subgraph, Nonempty (H ≃g G'.coe) where
mp := fun ⟨f⟩ ↦ ⟨.map f.toHom ⊤, ⟨f.isoToSubgraph⟩⟩
mpr := fun ⟨G', ⟨e⟩⟩ ↦ G'.coe_isContained.trans' ⟨e.toCopy⟩
alias ⟨IsContained.exists_iso_subgraph, IsContained.of_exists_iso_subgraph⟩ :=
isContained_iff_exists_iso_subgraph
theorem Copy.degree_le (f : Copy G H) (v : V) [Fintype <| G.neighborSet v]
[Fintype <| H.neighborSet (f v)] : G.degree v ≤ H.degree (f v) := by
simpa [card_neighborSet_eq_degree] using
Fintype.card_le_of_injective _ (f.mapNeighborSet v).injective
theorem Copy.maxDegree_mono [Fintype V] [Fintype W] [DecidableRel G.Adj] [DecidableRel H.Adj]
(f : Copy G H) : G.maxDegree ≤ H.maxDegree := by
cases isEmpty_or_nonempty V
· simp
obtain ⟨v, h⟩ := exists_maximal_degree_vertex G
grind [degree_le_maxDegree H (f v), f.degree_le v]
@[deprecated (since := "2026-05-20")] alias Copy.max_degree_le := Copy.maxDegree_mono
theorem IsContained.maxDegree_mono [Fintype V] [Fintype W] [DecidableRel G.Adj] [DecidableRel H.Adj]
(h : G ⊑ H) : G.maxDegree ≤ H.maxDegree := by
have ⟨f⟩ := h
exact f.maxDegree_mono
@[deprecated (since := "2026-05-20")] alias IsContained.max_degree_le := IsContained.maxDegree_mono
@[gcongr]
lemma maxDegree_mono {H : SimpleGraph V} [Fintype V] [DecidableRel G.Adj] [DecidableRel H.Adj]
(hle : G ≤ H) : G.maxDegree ≤ H.maxDegree :=
IsContained.of_le hle |>.maxDegree_mono
theorem Copy.minDegree_mono [Fintype V] [Fintype W] [DecidableRel G.Adj] [DecidableRel H.Adj]
{f : Copy G H} (hf : Function.Surjective f) : G.minDegree ≤ H.minDegree := by
cases isEmpty_or_nonempty W
· simp [Function.isEmpty f |>.subsingleton]
refine H.le_minDegree_of_forall_le_degree _ fun w ↦ ?_
obtain ⟨v, rfl⟩ := hf w
grw [← f.degree_le, ← minDegree_le_degree]
@[deprecated (since := "2026-05-20")] alias Copy.minDegree_le := Copy.minDegree_mono
theorem Hom.minDegree_mono [Fintype V] [Fintype W] [DecidableRel G.Adj] [DecidableRel H.Adj]
{f : G →g H} (hf : Function.Bijective f) : G.minDegree ≤ H.minDegree :=
Copy.minDegree_mono (f := ⟨f, hf.injective⟩) hf.surjective
@[deprecated (since := "2026-05-20")] alias Hom.minDegree_le := Hom.minDegree_mono
theorem maxDegree_induce_of_support_subset [Fintype V] [DecidableRel G.Adj] {s : Set V}
[DecidablePred (· ∈ s)] (h : G.support ⊆ s) : (G.induce s).maxDegree = G.maxDegree := by
apply le_antisymm <| Copy.maxDegree_mono <| Embedding.induce s |>.toCopy
refine G.maxDegree_le_of_forall_degree_le _ fun v ↦ ?_
by_cases hv : G.IsIsolated v
· simp [hv]
grw [← degree_le_maxDegree _ ⟨v, h <| G.mem_support_iff_not_isIsolated.mpr hv⟩,
degree_induce_of_neighborSet_subset <| G.neighborSet_subset_support v |>.trans h]
end IsContained
section Free
/-- `H.Free G` means that `G` does not contain a copy of `H`. -/
abbrev Free (H : SimpleGraph W) (G : SimpleGraph V) := ¬H ⊑ G
lemma not_free : ¬H.Free G ↔ H ⊑ G := not_not
/-- If `H ≃g H'` and `G ≃g G'` then `G` is `H`-free if and only if `G'` is `H'`-free. -/
theorem free_congr {V' W' : Type*} {G' : SimpleGraph V'} {H' : SimpleGraph W'}
(e₁ : H ≃g H') (e₂ : G ≃g G') : H.Free G ↔ H'.Free G' :=
(isContained_congr e₁ e₂).not
lemma free_congr_left (e₁ : H ≃g G) : H.Free I ↔ G.Free I := free_congr e₁ .refl
alias ⟨_, Free.congr_left⟩ := free_congr_left
lemma free_congr_right (e₂ : G ≃g I) : H.Free G ↔ H.Free I := free_congr .refl e₂
alias ⟨_, Free.congr_right⟩ := free_congr_right
lemma free_bot (h : H ≠ ⊥) : H.Free (⊥ : SimpleGraph V) := by
rw [← edgeSet_nonempty] at h
intro ⟨f, hf⟩
absurd f.map_mem_edgeSet h.choose_spec
rw [edgeSet_bot]
exact Set.notMem_empty (h.choose.map f)
end Free
/-!
#### Induced containment
A graph `H` *inducingly contains* a graph `G` if there is some graph embedding `G ↪ H`. This amounts
to `H` having an induced subgraph isomorphic to `G`.
We denote "`G` is inducingly contained in `H`" by `G ⊴ H` (`\trianglelefteq`).
-/
/-- A simple graph `G` is inducingly contained in a simple graph `H` if there exists an induced
subgraph of `H` isomorphic to `G`. This is denoted by `G ⊴ H`. -/
def IsIndContained (G : SimpleGraph V) (H : SimpleGraph W) : Prop := Nonempty (G ↪g H)
@[inherit_doc] scoped infixl:50 " ⊴ " => SimpleGraph.IsIndContained
protected lemma Copy.isContained (f : Copy G H) : G ⊑ H := ⟨f⟩
protected lemma Embedding.isIndContained (f : G ↪g H) : G ⊴ H := ⟨f⟩
protected lemma Embedding.isContained (f : G ↪g H) : G ⊑ H := f.toCopy.isContained
protected lemma IsIndContained.isContained : G ⊴ H → G ⊑ H := fun ⟨f⟩ ↦ f.isContained
/-- If `G` is isomorphic to `H`, then `G` is contained in `H`. -/
protected lemma Iso.isContained (e : G ≃g H) : G ⊑ H := e.toCopy.isContained
/-- If `G` is isomorphic to `H`, then `H` is contained in `G`. -/
protected lemma Iso.isContained' (e : G ≃g H) : H ⊑ G := e.symm.isContained
/-- If `G` is isomorphic to `H`, then `G` is inducingly contained in `H`. -/
protected lemma Iso.isIndContained (e : G ≃g H) : G ⊴ H := e.toEmbedding.isIndContained
/-- If `G` is isomorphic to `H`, then `H` is inducingly contained in `G`. -/
protected lemma Iso.isIndContained' (e : G ≃g H) : H ⊴ G := e.symm.isIndContained
protected lemma Subgraph.IsInduced.isIndContained {G' : G.Subgraph} (hG' : G'.IsInduced) :
G'.coe ⊴ G := Embedding.ofIsInduced _ hG' |>.isIndContained
@[refl] lemma IsIndContained.refl (G : SimpleGraph V) : G ⊴ G := ⟨Embedding.refl⟩
lemma IsIndContained.rfl : G ⊴ G := .refl _
@[trans] lemma IsIndContained.trans : G ⊴ H → H ⊴ I → G ⊴ I := fun ⟨f⟩ ⟨g⟩ ↦ ⟨g.comp f⟩
instance : IsPreorder (SimpleGraph W) IsIndContained where
refl := .refl
trans _ _ _ := .trans
instance :
Trans (α := SimpleGraph W) (β := SimpleGraph V) (γ := SimpleGraph X)
IsIndContained IsIndContained IsIndContained where
trans := .trans
lemma IsIndContained.of_isEmpty [IsEmpty V] : G ⊴ H :=
⟨{ toFun := isEmptyElim
inj' := isEmptyElim
map_rel_iff' := fun {a} ↦ isEmptyElim a }⟩
lemma isIndContained_iff_exists_iso_subgraph :
G ⊴ H ↔ ∃ (H' : H.Subgraph) (_e : G ≃g H'.coe), H'.IsInduced := by
constructor
· rintro ⟨f⟩
refine ⟨f.toCopy.toSubgraph, f.toCopy.isoToSubgraph, ?_⟩
simp [Subgraph.IsInduced, Relation.map_apply_apply, f.injective]
· rintro ⟨H', e, hH'⟩
exact e.isIndContained.trans hH'.isIndContained
alias ⟨IsIndContained.exists_iso_subgraph, IsIndContained.of_exists_iso_subgraph⟩ :=
isIndContained_iff_exists_iso_subgraph
theorem isIndContained_iff_exists_iso_induce : G ⊴ H ↔ ∃ s, Nonempty (G ≃g H.induce s) :=
⟨fun ⟨f⟩ ↦ ⟨Set.range f, ⟨f.isoInduceRange⟩⟩, fun ⟨s, ⟨f⟩⟩ ↦ ⟨.comp (.induce s) f⟩⟩
@[simp] lemma top_isIndContained_iff_top_isContained :
(⊤ : SimpleGraph V) ⊴ H ↔ (⊤ : SimpleGraph V) ⊑ H :=
⟨IsIndContained.isContained, fun ⟨f⟩ ↦ ⟨f.topEmbedding⟩⟩
theorem isContained_top_iff {G : SimpleGraph V} : G ⊑ completeGraph W ↔ Nonempty (V ↪ W) :=
⟨(⟨·.some.toEmbedding⟩), (.trans (.of_le le_top) ⟨Embedding.completeGraph ·.some |>.toCopy⟩)⟩
theorem top_isIndContained_top_iff : completeGraph V ⊴ completeGraph W ↔ Nonempty (V ↪ W) :=
⟨(⟨·.some.toEmbedding⟩), (⟨.completeGraph ·.some⟩)⟩
theorem eq_top_of_isIndContained_top (h : G ⊴ completeGraph W) : G = ⊤ :=
h.some.comap_eq ▸ comap_top h.some.injective
@[simp] lemma compl_isIndContained_compl : Gᶜ ⊴ Hᶜ ↔ G ⊴ H :=
Embedding.complEquiv.symm.nonempty_congr
protected alias ⟨IsIndContained.of_compl, IsIndContained.compl⟩ := compl_isIndContained_compl
theorem isContained_iff_exists_le_comap : H ⊑ G ↔ ∃ (f : W ↪ V), H ≤ G.comap f :=
⟨fun ⟨f⟩ ↦ ⟨f.toEmbedding, f.toHom.le_comap⟩, fun ⟨f, h⟩ ↦ ⟨⟨f, (h ·)⟩, f.injective⟩⟩
theorem isIndContained_iff_exists_comap_eq : H ⊴ G ↔ ∃ (f : W ↪ V), G.comap f = H :=
⟨fun ⟨f⟩ ↦ ⟨f.toEmbedding, f.comap_eq⟩, fun ⟨f, h⟩ ↦ ⟨f, h ▸ .rfl⟩⟩
/-!
### Counting the copies
If `G` and `H` are finite graphs, we can count the number of unlabelled and labelled copies of `G`
in `H`.
#### Not necessarily induced copies
-/
section LabelledCopyCount
variable [Fintype V] [Fintype W]
/-- `G.labelledCopyCount H` is the number of labelled copies of `H` in `G`, i.e. the number of graph
embeddings from `H` to `G`. See `SimpleGraph.copyCount` for the number of unlabelled copies. -/
noncomputable def labelledCopyCount (G : SimpleGraph V) (H : SimpleGraph W) : ℕ := by
classical exact Fintype.card (Copy H G)
@[simp] lemma labelledCopyCount_of_isEmpty [IsEmpty W] (G : SimpleGraph V) (H : SimpleGraph W) :
G.labelledCopyCount H = 1 := by
convert! Fintype.card_unique
exact { default := ⟨default, isEmptyElim⟩, uniq := fun _ ↦ Subsingleton.elim _ _ }
@[simp] lemma labelledCopyCount_eq_zero : G.labelledCopyCount H = 0 ↔ H.Free G := by
simp [labelledCopyCount, Fintype.card_eq_zero_iff]
@[simp] lemma labelledCopyCount_pos : 0 < G.labelledCopyCount H ↔ H ⊑ G := by
simp [labelledCopyCount, IsContained, Fintype.card_pos_iff]
end LabelledCopyCount
section CopyCount
variable [Fintype V]
/-- `G.copyCount H` is the number of unlabelled copies of `H` in `G`, i.e. the number of subgraphs
of `G` isomorphic to `H`. See `SimpleGraph.labelledCopyCount` for the number of labelled copies. -/
noncomputable def copyCount (G : SimpleGraph V) (H : SimpleGraph W) : ℕ := by
classical exact #{G' : G.Subgraph | Nonempty (H ≃g G'.coe)}
lemma copyCount_eq_card_image_copyToSubgraph [Fintype {f : H →g G // Injective f}]
[DecidableEq G.Subgraph] :
copyCount G H = #((Finset.univ : Finset (H.Copy G)).image Copy.toSubgraph) := by
rw [copyCount]
congr
refine Finset.coe_injective ?_
simpa [-Copy.range_toSubgraph] using Copy.range_toSubgraph.symm
@[simp] lemma copyCount_eq_zero : G.copyCount H = 0 ↔ H.Free G := by
simp [copyCount, Free, -nonempty_subtype, isContained_iff_exists_iso_subgraph,
filter_eq_empty_iff]
@[simp] lemma copyCount_pos : 0 < G.copyCount H ↔ H ⊑ G := by
simp [copyCount, -nonempty_subtype, isContained_iff_exists_iso_subgraph, card_pos,
filter_nonempty_iff]
/-- There's at least as many labelled copies of `H` in `G` than unlabelled ones. -/
lemma copyCount_le_labelledCopyCount [Fintype W] : G.copyCount H ≤ G.labelledCopyCount H := by
classical rw [copyCount_eq_card_image_copyToSubgraph]; exact card_image_le
@[simp] lemma copyCount_bot (G : SimpleGraph V) : copyCount G (⊥ : SimpleGraph V) = 1 := by
classical
rw [copyCount]
convert
card_singleton (α := G.Subgraph)
{ verts := .univ
Adj := ⊥
adj_sub := False.elim
edge_vert := False.elim }
simp only [eq_singleton_iff_unique_mem, mem_filter_univ, Nonempty.forall]
refine ⟨⟨⟨(Equiv.Set.univ _).symm, by simp⟩⟩, fun H' e ↦
Subgraph.ext ((set_fintype_card_eq_univ_iff _).1 <| Fintype.card_congr e.toEquiv.symm) ?_⟩
ext a b
simp only [Prop.bot_eq_false, Pi.bot_apply, iff_false]
exact fun hab ↦ e.symm.map_rel_iff.2 hab.coe
@[simp] lemma copyCount_of_isEmpty [IsEmpty W] (G : SimpleGraph V) (H : SimpleGraph W) :
G.copyCount H = 1 := by
cases nonempty_fintype W
exact (copyCount_le_labelledCopyCount.trans_eq <| labelledCopyCount_of_isEmpty ..).antisymm <|
copyCount_pos.2 .of_isEmpty
end CopyCount
/-!
#### Induced copies
TODO
### Killing a subgraph
An important aspect of graph containment is that we can remove not too many edges from a graph `H`
to get a graph `H'` that doesn't contain `G`.
#### Killing not necessarily induced copies
`SimpleGraph.killCopies G H` is a subgraph of `G` where an edge was removed from each copy of `H` in
`G`. By construction, it doesn't contain `H` and has at most the number of copies of `H` edges less
than `G`.
-/
set_option backward.privateInPublic true in
private lemma aux (hH : H ≠ ⊥) {G' : G.Subgraph} :
Nonempty (H ≃g G'.coe) → G'.edgeSet.Nonempty := by
obtain ⟨e, he⟩ := edgeSet_nonempty.2 hH
rw [← Subgraph.image_coe_edgeSet_coe]
exact fun ⟨f⟩ ↦ Set.Nonempty.image _ ⟨_, f.map_mem_edgeSet_iff.2 he⟩
set_option backward.privateInPublic true in
set_option backward.privateInPublic.warn false in
/-- `G.killCopies H` is a subgraph of `G` where an *arbitrary* edge was removed from each copy of
`H` in `G`. By construction, it doesn't contain `H` (unless `H` had no edges) and has at most the
number of copies of `H` edges less than `G`. See `free_killCopies` and
`le_card_edgeFinset_killCopies` for these two properties. -/
@[no_expose]
noncomputable def killCopies (G : SimpleGraph V) (H : SimpleGraph W) : SimpleGraph V := by
classical exact
if hH : H = ⊥ then G
else G.deleteEdges <| ⋃ (G' : G.Subgraph) (hG' : Nonempty (H ≃g G'.coe)), {(aux hH hG').some}
/-- Removing an edge from `G` for each subgraph isomorphic to `H` results in a subgraph of `G`. -/
lemma killCopies_le_left : G.killCopies H ≤ G := by
rw [killCopies]; split_ifs; exacts [le_rfl, deleteEdges_le _]
@[simp] lemma killCopies_bot (G : SimpleGraph V) : G.killCopies (⊥ : SimpleGraph W) = G := by
rw [killCopies]; exact dite_eq_left rfl
private lemma killCopies_of_ne_bot (hH : H ≠ ⊥) (G : SimpleGraph V) :
G.killCopies H =
G.deleteEdges (⋃ (G' : G.Subgraph) (hG' : Nonempty (H ≃g G'.coe)), {(aux hH hG').some}) := by
rw [killCopies]; exact dite_eq_right hH
/-- `G.killCopies H` has no effect on `G` if and only if `G` already contained no copies of `H`. See
`Free.killCopies_eq_left` for the reverse implication with no assumption on `H`. -/
lemma killCopies_eq_left (hH : H ≠ ⊥) : G.killCopies H = G ↔ H.Free G := by
simp only [killCopies_of_ne_bot hH, Set.disjoint_left, isContained_iff_exists_iso_subgraph,
@forall_comm _ G.Subgraph, deleteEdges_eq_self, Set.mem_iUnion,
not_exists, not_nonempty_iff, Nonempty.forall, Free]
exact forall_congr' fun G' ↦ ⟨fun h ↦ ⟨fun f ↦ h _
(Subgraph.edgeSet_subset _ (aux hH ⟨f⟩).choose_spec) f rfl⟩, fun h _ _ ↦ h.elim⟩
protected lemma Free.killCopies_eq_left (hHG : H.Free G) : G.killCopies H = G := by
obtain rfl | hH := eq_or_ne H ⊥
· exact killCopies_bot _
· exact (killCopies_eq_left hH).2 hHG
set_option backward.isDefEq.respectTransparency false in
/-- Removing an edge from `G` for each subgraph isomorphic to `H` results in a graph that doesn't
contain `H`. -/
lemma free_killCopies (hH : H ≠ ⊥) : H.Free (G.killCopies H) := by
rw [killCopies_of_ne_bot hH, deleteEdges, Free, isContained_iff_exists_iso_subgraph]
rintro ⟨G', hHG'⟩
have hG' : (G'.map <| .ofLE (sdiff_le : G \ _ ≤ G)).edgeSet.Nonempty := by
rw [Subgraph.edgeSet_map]
exact (aux hH hHG').image _
set e := hG'.some with he
have : e ∈ _ := hG'.some_mem
clear_value e
rw [← Subgraph.image_coe_edgeSet_coe] at this
subst he
obtain ⟨e, he₀, he₁⟩ := this
let e' : Sym2 G'.verts := Sym2.map (Copy.isoSubgraphMap (.ofLE _ _ _) _).symm e
have he' : e' ∈ G'.coe.edgeSet := (Iso.map_mem_edgeSet_iff _).2 he₀
rw [Subgraph.edgeSet_coe] at he'
have := Subgraph.edgeSet_subset _ he'
simp only [edgeSet_sdiff, edgeSet_fromEdgeSet, edgeSet_sdiff_sdiff_isDiag, Set.mem_sdiff,
Set.mem_iUnion, not_exists] at this
refine this.2 (G'.map <| .ofLE sdiff_le) ⟨((Copy.ofLE _ _ _).isoSubgraphMap _).comp hHG'.some⟩ ?_
rw [Sym2.map_map, Set.mem_singleton_iff, ← he₁]
congr 1 with x
exact congr_arg _ (Equiv.Set.image_symm_apply _ _ injective_id _ _)
variable [Fintype G.edgeSet]
noncomputable instance killCopies.edgeSet.instFintype : Fintype (G.killCopies H).edgeSet :=
.ofInjective (Set.inclusion <| edgeSet_mono killCopies_le_left) <| Set.inclusion_injective _
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
we've removed is at most the number of copies of `G` in `H`. -/
lemma le_card_edgeFinset_killCopies [Fintype V] :
#G.edgeFinset - G.copyCount H ≤ #(G.killCopies H).edgeFinset := by
classical
obtain rfl | hH := eq_or_ne H ⊥
· simp [← card_edgeSet]
let f (G' : {G' : G.Subgraph // Nonempty (H ≃g G'.coe)}) := (aux hH G'.2).some
calc
_ = #G.edgeFinset - card {G' : G.Subgraph // Nonempty (H ≃g G'.coe)} := ?_
_ ≤ #G.edgeFinset - #(univ.image f) := Nat.sub_le_sub_left card_image_le _
_ = #G.edgeFinset - #(Set.range f).toFinset := by rw [Set.toFinset_range]
_ ≤ #(G.edgeFinset \ (Set.range f).toFinset) := le_card_sdiff ..
_ = #(G.killCopies H).edgeFinset := ?_
· simp only [edgeFinset, Set.toFinset_card]
rw [← Set.toFinset_card, ← edgeFinset, copyCount, ← card_subtype, subtype_univ, card_univ]
congr 1
ext e
induction e using Sym2.inductionOn with | hf v w
simp [mem_edgeSet, killCopies_of_ne_bot hH, f, eq_comm]
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
we've removed is at most the number of copies of `G` in `H`. -/
lemma le_card_edgeFinset_killCopies_add_copyCount [Fintype V] :
#G.edgeFinset ≤ #(G.killCopies H).edgeFinset + G.copyCount H :=
tsub_le_iff_right.1 le_card_edgeFinset_killCopies
/-!
#### Killing induced copies
TODO
-/
end SimpleGraph
¤ Dauer der Verarbeitung: 0.28 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|