Skip to content

Commit e6247f6

Browse files
committed
chore(Combinatorics/SimpleGraph/Copy): migrate copyCount/unlabeledCopyCount to Nat.card
* `copyCount` and `unlabeledCopyCount` redefined via `Nat.card` instead of `Fintype.card`. * `Fintype` hypotheses weakened to `Finite` throughout (`copyCount_eq_zero`, `copyCount_pos`, `unlabeledCopyCount_eq_zero`, `unlabeledCopyCount_pos`, `unlabeledCopyCount_le_copyCount`, `uniqueUnlabeledCopyBot`, `unlabeledCopyCount_bot`, `unlabeledCopyCount_of_isEmpty`, `bot_isContained_iff_card_le`, `le_card_edgeFinset_killCopies`, `le_card_edgeFinset_killCopies_add_unlabeledCopyCount`). * `bot_isContained_iff_card_le`: `Fintype.card → Nat.card`. * New `Finite (G.Copy H)` instance (sibling to the existing `Fintype` instance). * New `Nonempty (Copy G H)` instance for `[IsEmpty V]`, used to give a one-line `copyCount_of_isEmpty` proof via `Nat.card_unique`. * New `copyCount_eq_nat_card` and `unlabeledCopyCount_eq_nat_card` bridge lemmas exposing the underlying `Nat.card`, intended as the public characterisation since the count bodies are deliberately not `@[expose]`d. * New private `Nonempty` / `Subsingleton` instances on `G.UnlabeledCopy H` for `[IsEmpty V]`, used to give a one-line `unlabeledCopyCount_of_isEmpty` proof via `Nat.card_unique`. * `le_card_edgeFinset_killCopies` proof simplified accordingly.
1 parent d1f889a commit e6247f6

1 file changed

Lines changed: 72 additions & 57 deletions

File tree

Mathlib/Combinatorics/SimpleGraph/Copy.lean

Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module
77

88
public import Mathlib.Algebra.Order.Group.Nat
99
public import Mathlib.Combinatorics.SimpleGraph.Subgraph
10+
public import Mathlib.Data.Finite.Card
1011

1112
/-!
1213
# Copies, containment, and counting of subgraphs
@@ -69,7 +70,6 @@ The following notation is declared in scope `SimpleGraph`:
6970
public section
7071

7172
open Finset Function
72-
open Fintype (card)
7373

7474
namespace SimpleGraph
7575
variable {V V' W W' X : Type*}
@@ -206,6 +206,9 @@ instance [Fintype {f : G →g H // Injective f}] : Fintype (G.Copy H) :=
206206
invFun f := ⟨f.1, f.2
207207
}
208208

209+
instance [Finite V] [Finite W] : Finite (G.Copy H) :=
210+
Finite.of_injective _ DFunLike.coe_injective
211+
209212
/-- A copy of `⊤` gives rise to an embedding of `⊤`. -/
210213
@[expose] def topEmbedding (f : Copy (⊤ : SimpleGraph V) H) : (⊤ : SimpleGraph V) ↪g H :=
211214
{ f.toEmbedding with
@@ -297,10 +300,11 @@ lemma IsContained.of_isEmpty [IsEmpty V] : G ⊑ H :=
297300
⟨⟨isEmptyElim, fun {a} ↦ isEmptyElim a⟩, isEmptyElim⟩
298301

299302
/-- `⊥` is contained in any simple graph having sufficiently many vertices. -/
300-
lemma bot_isContained_iff_card_le [Fintype V] [Fintype W] :
301-
(⊥ : SimpleGraph V) ⊑ H ↔ Fintype.card V ≤ Fintype.card W :=
302-
fun ⟨f⟩ ↦ Fintype.card_le_of_embedding f.toEmbedding,
303-
fun h ↦ ⟨Copy.bot (Function.Embedding.nonempty_of_card_le h).some⟩⟩
303+
lemma bot_isContained_iff_card_le [Finite V] [Finite W] :
304+
(⊥ : SimpleGraph V) ⊑ H ↔ Nat.card V ≤ Nat.card W :=
305+
fun ⟨f⟩ ↦ Finite.card_le_of_embedding f.toEmbedding,
306+
fun h ↦ ⟨Copy.bot (Cardinal.lift_mk_le'.mp (by
307+
simp only [← Nat.cast_card, Cardinal.lift_natCast]; exact_mod_cast h)).some⟩⟩
304308

305309
protected alias IsContained.bot := bot_isContained_iff_card_le
306310

@@ -473,89 +477,101 @@ For finite `G` and `H`, we count labeled and unlabeled copies of `G` in `H`.
473477
-/
474478

475479
section CopyCount
476-
variable [Fintype V] [Fintype W]
477480

478481
/-- `H.copyCount G` is the number of labeled copies of `G` in `H`, i.e. the number of injective
479482
graph homomorphisms from `G` to `H`. See `SimpleGraph.unlabeledCopyCount` for the number of
480483
unlabeled copies. -/
481-
noncomputable def copyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ := by
482-
classical exact Fintype.card (Copy G H)
484+
noncomputable def copyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ :=
485+
Nat.card (Copy G H)
486+
487+
lemma copyCount_eq_nat_card (H : SimpleGraph W) (G : SimpleGraph V) :
488+
H.copyCount G = Nat.card (Copy G H) := by rw [copyCount]
483489

484490
@[deprecated (since := "2026-04-30")] alias labelledCopyCount := copyCount
485491

492+
private instance [IsEmpty V] : Nonempty (Copy G H) := IsContained.of_isEmpty
493+
486494
@[simp] lemma copyCount_of_isEmpty [IsEmpty V] (H : SimpleGraph W) (G : SimpleGraph V) :
487-
H.copyCount G = 1 := by
488-
convert! Fintype.card_unique
489-
exact { default := ⟨default, isEmptyElim⟩, uniq := fun _ ↦ Subsingleton.elim _ _ }
495+
H.copyCount G = 1 := Nat.card_unique
490496

491497
@[deprecated (since := "2026-04-30")]
492498
alias labelledCopyCount_of_isEmpty := copyCount_of_isEmpty
493499

494-
@[simp] lemma copyCount_eq_zero : H.copyCount G = 0 ↔ G.Free H := by
495-
simp [copyCount, Fintype.card_eq_zero_iff]
500+
@[simp] lemma copyCount_eq_zero [Finite V] [Finite W] : H.copyCount G = 0 ↔ G.Free H := by
501+
rw [copyCount, Nat.card_eq_zero, or_iff_left (Finite.not_infinite inferInstance)]
502+
simp [Free, IsContained]
496503

497504
@[deprecated (since := "2026-04-30")] alias labelledCopyCount_eq_zero := copyCount_eq_zero
498505

499-
@[simp] lemma copyCount_pos : 0 < H.copyCount G ↔ G ⊑ H := by
500-
simp [copyCount, IsContained, Fintype.card_pos_iff]
506+
@[simp] lemma copyCount_pos [Finite V] [Finite W] : 0 < H.copyCount G ↔ G ⊑ H := by
507+
simp [Nat.pos_iff_ne_zero, copyCount_eq_zero]
501508

502509
@[deprecated (since := "2026-04-30")] alias labelledCopyCount_pos := copyCount_pos
503510

504511
end CopyCount
505512

506513
section UnlabeledCopyCount
507-
variable [Fintype W]
508514

509515
/-- `G.UnlabeledCopy H` is the type of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. The
510516
corresponding count is `SimpleGraph.unlabeledCopyCount`. -/
511517
abbrev UnlabeledCopy (G : SimpleGraph V) (H : SimpleGraph W) : Type _ :=
512518
{H' : H.Subgraph // Nonempty (G ≃g H'.coe)}
513519

520+
instance [Finite W] : Finite (G.UnlabeledCopy H) := Subtype.finite
521+
514522
/-- `H.unlabeledCopyCount G` is the number of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. See
515523
`SimpleGraph.copyCount` for the number of labeled copies. -/
516-
noncomputable def unlabeledCopyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ := by
517-
classical exact Fintype.card (G.UnlabeledCopy H)
524+
noncomputable def unlabeledCopyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ :=
525+
Nat.card (G.UnlabeledCopy H)
518526

519-
@[simp] lemma unlabeledCopyCount_eq_zero : H.unlabeledCopyCount G = 0 ↔ G.Free H := by
520-
simp [unlabeledCopyCount, Free, -nonempty_subtype, isContained_iff_exists_iso_subgraph,
521-
Fintype.card_eq_zero_iff, isEmpty_subtype, not_nonempty_iff]
527+
lemma unlabeledCopyCount_eq_nat_card (H : SimpleGraph W) (G : SimpleGraph V) :
528+
H.unlabeledCopyCount G = Nat.card (G.UnlabeledCopy H) := by rw [unlabeledCopyCount]
522529

523-
@[simp] lemma unlabeledCopyCount_pos : 0 < H.unlabeledCopyCount G ↔ G ⊑ H := by
524-
rw [Nat.pos_iff_ne_zero, ne_eq, unlabeledCopyCount_eq_zero, Free, not_not]
530+
@[simp] lemma unlabeledCopyCount_eq_zero [Finite W] : H.unlabeledCopyCount G = 0 ↔ G.Free H := by
531+
rw [unlabeledCopyCount, Nat.card_eq_zero,
532+
or_iff_left (Finite.not_infinite inferInstance), isEmpty_subtype]
533+
simp [Free, isContained_iff_exists_iso_subgraph]
534+
535+
@[simp] lemma unlabeledCopyCount_pos [Finite W] : 0 < H.unlabeledCopyCount G ↔ G ⊑ H := by
536+
simp [Nat.pos_iff_ne_zero, unlabeledCopyCount_eq_zero]
525537

526538
/-- There are at least as many labeled copies of `G` in `H` as there are unlabeled ones. -/
527-
lemma unlabeledCopyCount_le_copyCount [Fintype V] : H.unlabeledCopyCount G ≤ H.copyCount G := by
528-
classical
539+
lemma unlabeledCopyCount_le_copyCount [Finite V] [Finite W] :
540+
H.unlabeledCopyCount G ≤ H.copyCount G := by
529541
rw [unlabeledCopyCount, copyCount]
530-
apply Fintype.card_le_of_surjective
542+
apply Nat.card_le_card_of_surjective
531543
(fun c : Copy G H ↦ (⟨c.toSubgraph, ⟨c.isoToSubgraph⟩⟩ : G.UnlabeledCopy H))
532544
rintro ⟨H', hG'⟩
533545
obtain ⟨c, hc⟩ : ∃ c, Copy.toSubgraph c = H' := by
534546
rwa [← Set.mem_range, Copy.range_toSubgraph]
535547
exact ⟨c, Subtype.ext hc⟩
536548

537-
instance uniqueUnlabeledCopyBot (H : SimpleGraph W) :
549+
instance uniqueUnlabeledCopyBot [Finite W] (H : SimpleGraph W) :
538550
Unique ((⊥ : SimpleGraph W).UnlabeledCopy H) where
539551
default := ⟨{ verts := .univ, Adj := ⊥, adj_sub := False.elim, edge_vert := False.elim },
540552
⟨(Equiv.Set.univ _).symm, by simp⟩⟩
541-
uniq := fun ⟨G', ⟨e⟩⟩ ↦ Subtype.ext <| Subgraph.ext
542-
(by classical exact (set_fintype_card_eq_univ_iff _).1 <| Fintype.card_congr e.toEquiv.symm)
543-
(by ext a b
544-
simp only [Prop.bot_eq_false, Pi.bot_apply, iff_false]
545-
exact fun hab ↦ e.symm.map_rel_iff.2 hab.coe)
546-
547-
@[simp] lemma unlabeledCopyCount_bot (H : SimpleGraph W) :
548-
H.unlabeledCopyCount (⊥ : SimpleGraph W) = 1 := by
549-
classical
550-
rw [unlabeledCopyCount]
551-
convert Fintype.card_unique
552-
exact uniqueUnlabeledCopyBot H
553+
uniq := fun ⟨H', ⟨e⟩⟩ ↦ Subtype.ext <| Subgraph.ext
554+
(Set.eq_univ_of_forall fun v ↦ by
555+
obtain ⟨w, hw⟩ := (Finite.injective_iff_surjective.mp
556+
(Subtype.val_injective.comp e.toEquiv.injective)) v
557+
exact hw ▸ (e.toEquiv w).prop)
558+
(funext₂ fun a b ↦ eq_false fun hadj ↦ absurd (e.symm.map_rel_iff.mpr hadj.coe) (by simp))
559+
560+
@[simp] lemma unlabeledCopyCount_bot [Finite W] (H : SimpleGraph W) :
561+
H.unlabeledCopyCount (⊥ : SimpleGraph W) = 1 :=
562+
Nat.card_unique
563+
564+
private instance [IsEmpty V] : Nonempty (G.UnlabeledCopy H) :=
565+
let ⟨H', ⟨e⟩⟩ := (IsContained.of_isEmpty (G := G) (H := H)).exists_iso_subgraph
566+
⟨⟨H', ⟨e⟩⟩⟩
567+
568+
private instance [IsEmpty V] : Subsingleton (G.UnlabeledCopy H) :=
569+
fun ⟨H', ⟨e⟩⟩ ⟨H'', ⟨e'⟩⟩ ↦ Subtype.ext <|
570+
(H'.eq_bot_iff_verts_eq_empty.mpr (Set.isEmpty_coe_sort.mp e.toEquiv.symm.isEmpty)).trans
571+
(H''.eq_bot_iff_verts_eq_empty.mpr (Set.isEmpty_coe_sort.mp e'.toEquiv.symm.isEmpty)).symm⟩
553572

554573
@[simp] lemma unlabeledCopyCount_of_isEmpty [IsEmpty V] (H : SimpleGraph W) (G : SimpleGraph V) :
555-
H.unlabeledCopyCount G = 1 := by
556-
cases nonempty_fintype V
557-
exact (unlabeledCopyCount_le_copyCount.trans_eq <| copyCount_of_isEmpty ..).antisymm <|
558-
unlabeledCopyCount_pos.2 <| .of_isEmpty
574+
H.unlabeledCopyCount G = 1 := Nat.card_unique
559575

560576
end UnlabeledCopyCount
561577

@@ -644,28 +660,27 @@ noncomputable instance killCopies.edgeSet.instFintype : Fintype (H.killCopies G)
644660

645661
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
646662
we've removed is at most the number of copies of `G` in `H`. -/
647-
lemma le_card_edgeFinset_killCopies [Fintype W] :
663+
lemma le_card_edgeFinset_killCopies [Finite W] :
648664
#H.edgeFinset - H.unlabeledCopyCount G ≤ #(H.killCopies G).edgeFinset := by
649665
classical
650666
obtain rfl | hG := eq_or_ne G ⊥
651667
· simp [← card_edgeSet]
668+
cases nonempty_fintype (G.UnlabeledCopy H)
652669
let f (H' : G.UnlabeledCopy H) := (aux hG H'.2).some
653-
calc
654-
_ = #H.edgeFinset - Fintype.card (G.UnlabeledCopy H) := ?_
655-
_ ≤ #H.edgeFinset - #(univ.image f) := Nat.sub_le_sub_left card_image_le _
656-
_ = #H.edgeFinset - #(Set.range f).toFinset := by rw [Set.toFinset_range]
657-
_ ≤ #(H.edgeFinset \ (Set.range f).toFinset) := le_card_sdiff ..
658-
_ = #(H.killCopies G).edgeFinset := ?_
659-
· simp only [edgeFinset, Set.toFinset_card]
660-
rw [← Set.toFinset_card, ← edgeFinset, unlabeledCopyCount]
661-
congr 1
662-
ext e
663-
induction e using Sym2.inductionOn with | hf v w
664-
simp [mem_edgeSet, killCopies_of_ne_bot hG, f, eq_comm]
670+
calc #H.edgeFinset - H.unlabeledCopyCount G
671+
= #H.edgeFinset - Fintype.card (G.UnlabeledCopy H) := by
672+
rw [unlabeledCopyCount, Nat.card_eq_fintype_card]
673+
_ ≤ #H.edgeFinset - #(Finset.univ.image f) := Nat.sub_le_sub_left Finset.card_image_le _
674+
_ ≤ #(H.edgeFinset \ Finset.univ.image f) := le_card_sdiff ..
675+
_ = #(H.killCopies G).edgeFinset := by
676+
congr 1
677+
ext e
678+
induction e using Sym2.inductionOn with | hf v w
679+
simp [mem_edgeSet, killCopies_of_ne_bot hG, f, eq_comm]
665680

666681
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
667682
we've removed is at most the number of copies of `G` in `H`. -/
668-
lemma le_card_edgeFinset_killCopies_add_unlabeledCopyCount [Fintype W] :
683+
lemma le_card_edgeFinset_killCopies_add_unlabeledCopyCount [Finite W] :
669684
#H.edgeFinset ≤ #(H.killCopies G).edgeFinset + H.unlabeledCopyCount G :=
670685
tsub_le_iff_right.1 le_card_edgeFinset_killCopies
671686

0 commit comments

Comments
 (0)