Skip to content

Commit 204bcdc

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 74127bc commit 204bcdc

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*}
@@ -207,6 +207,9 @@ instance [Fintype {f : G →g H // Injective f}] : Fintype (G.Copy H) :=
207207
invFun f := ⟨f.1, f.2
208208
}
209209

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

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

306310
protected alias IsContained.bot := bot_isContained_iff_card_le
307311

@@ -482,89 +486,101 @@ For finite `G` and `H`, we count labeled and unlabeled copies of `G` in `H`.
482486
-/
483487

484488
section CopyCount
485-
variable [Fintype V] [Fintype W]
486489

487490
/-- `H.copyCount G` is the number of labeled copies of `G` in `H`, i.e. the number of injective
488491
graph homomorphisms from `G` to `H`. See `SimpleGraph.unlabeledCopyCount` for the number of
489492
unlabeled copies. -/
490-
noncomputable def copyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ := by
491-
classical exact Fintype.card (Copy G H)
493+
noncomputable def copyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ :=
494+
Nat.card (Copy G H)
495+
496+
lemma copyCount_eq_nat_card (H : SimpleGraph W) (G : SimpleGraph V) :
497+
H.copyCount G = Nat.card (Copy G H) := by rw [copyCount]
492498

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

501+
private instance [IsEmpty V] : Nonempty (Copy G H) := IsContained.of_isEmpty
502+
495503
@[simp] lemma copyCount_of_isEmpty [IsEmpty V] (H : SimpleGraph W) (G : SimpleGraph V) :
496-
H.copyCount G = 1 := by
497-
convert! Fintype.card_unique
498-
exact { default := ⟨default, isEmptyElim⟩, uniq := fun _ ↦ Subsingleton.elim _ _ }
504+
H.copyCount G = 1 := Nat.card_unique
499505

500506
@[deprecated (since := "2026-04-30")]
501507
alias labelledCopyCount_of_isEmpty := copyCount_of_isEmpty
502508

503-
@[simp] lemma copyCount_eq_zero : H.copyCount G = 0 ↔ G.Free H := by
504-
simp [copyCount, Fintype.card_eq_zero_iff]
509+
@[simp] lemma copyCount_eq_zero [Finite V] [Finite W] : H.copyCount G = 0 ↔ G.Free H := by
510+
rw [copyCount, Nat.card_eq_zero, or_iff_left (Finite.not_infinite inferInstance)]
511+
simp [Free, IsContained]
505512

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

508-
@[simp] lemma copyCount_pos : 0 < H.copyCount G ↔ G ⊑ H := by
509-
simp [copyCount, IsContained, Fintype.card_pos_iff]
515+
@[simp] lemma copyCount_pos [Finite V] [Finite W] : 0 < H.copyCount G ↔ G ⊑ H := by
516+
simp [Nat.pos_iff_ne_zero, copyCount_eq_zero]
510517

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

513520
end CopyCount
514521

515522
section UnlabeledCopyCount
516-
variable [Fintype W]
517523

518524
/-- `G.UnlabeledCopy H` is the type of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. The
519525
corresponding count is `SimpleGraph.unlabeledCopyCount`. -/
520526
abbrev UnlabeledCopy (G : SimpleGraph V) (H : SimpleGraph W) : Type _ :=
521527
{H' : H.Subgraph // Nonempty (G ≃g H'.coe)}
522528

529+
instance [Finite W] : Finite (G.UnlabeledCopy H) := Subtype.finite
530+
523531
/-- `H.unlabeledCopyCount G` is the number of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. See
524532
`SimpleGraph.copyCount` for the number of labeled copies. -/
525-
noncomputable def unlabeledCopyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ := by
526-
classical exact Fintype.card (G.UnlabeledCopy H)
533+
noncomputable def unlabeledCopyCount (H : SimpleGraph W) (G : SimpleGraph V) : ℕ :=
534+
Nat.card (G.UnlabeledCopy H)
527535

528-
@[simp] lemma unlabeledCopyCount_eq_zero : H.unlabeledCopyCount G = 0 ↔ G.Free H := by
529-
simp [unlabeledCopyCount, Free, -nonempty_subtype, isContained_iff_exists_iso_subgraph,
530-
Fintype.card_eq_zero_iff, isEmpty_subtype, not_nonempty_iff]
536+
lemma unlabeledCopyCount_eq_nat_card (H : SimpleGraph W) (G : SimpleGraph V) :
537+
H.unlabeledCopyCount G = Nat.card (G.UnlabeledCopy H) := by rw [unlabeledCopyCount]
531538

532-
@[simp] lemma unlabeledCopyCount_pos : 0 < H.unlabeledCopyCount G ↔ G ⊑ H := by
533-
rw [Nat.pos_iff_ne_zero, ne_eq, unlabeledCopyCount_eq_zero, Free, not_not]
539+
@[simp] lemma unlabeledCopyCount_eq_zero [Finite W] : H.unlabeledCopyCount G = 0 ↔ G.Free H := by
540+
rw [unlabeledCopyCount, Nat.card_eq_zero,
541+
or_iff_left (Finite.not_infinite inferInstance), isEmpty_subtype]
542+
simp [Free, isContained_iff_exists_iso_subgraph]
543+
544+
@[simp] lemma unlabeledCopyCount_pos [Finite W] : 0 < H.unlabeledCopyCount G ↔ G ⊑ H := by
545+
simp [Nat.pos_iff_ne_zero, unlabeledCopyCount_eq_zero]
534546

535547
/-- There are at least as many labeled copies of `G` in `H` as there are unlabeled ones. -/
536-
lemma unlabeledCopyCount_le_copyCount [Fintype V] : H.unlabeledCopyCount G ≤ H.copyCount G := by
537-
classical
548+
lemma unlabeledCopyCount_le_copyCount [Finite V] [Finite W] :
549+
H.unlabeledCopyCount G ≤ H.copyCount G := by
538550
rw [unlabeledCopyCount, copyCount]
539-
apply Fintype.card_le_of_surjective
551+
apply Nat.card_le_card_of_surjective
540552
(fun c : Copy G H ↦ (⟨c.toSubgraph, ⟨c.isoToSubgraph⟩⟩ : G.UnlabeledCopy H))
541553
rintro ⟨H', hG'⟩
542554
obtain ⟨c, hc⟩ : ∃ c, Copy.toSubgraph c = H' := by
543555
rwa [← Set.mem_range, Copy.range_toSubgraph]
544556
exact ⟨c, Subtype.ext hc⟩
545557

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

563582
@[simp] lemma unlabeledCopyCount_of_isEmpty [IsEmpty V] (H : SimpleGraph W) (G : SimpleGraph V) :
564-
H.unlabeledCopyCount G = 1 := by
565-
cases nonempty_fintype V
566-
exact (unlabeledCopyCount_le_copyCount.trans_eq <| copyCount_of_isEmpty ..).antisymm <|
567-
unlabeledCopyCount_pos.2 <| .of_isEmpty
583+
H.unlabeledCopyCount G = 1 := Nat.card_unique
568584

569585
end UnlabeledCopyCount
570586

@@ -653,28 +669,27 @@ noncomputable instance killCopies.edgeSet.instFintype : Fintype (H.killCopies G)
653669

654670
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
655671
we've removed is at most the number of copies of `G` in `H`. -/
656-
lemma le_card_edgeFinset_killCopies [Fintype W] :
672+
lemma le_card_edgeFinset_killCopies [Finite W] :
657673
#H.edgeFinset - H.unlabeledCopyCount G ≤ #(H.killCopies G).edgeFinset := by
658674
classical
659675
obtain rfl | hG := eq_or_ne G ⊥
660676
· simp [← card_edgeSet]
677+
cases nonempty_fintype (G.UnlabeledCopy H)
661678
let f (H' : G.UnlabeledCopy H) := (aux hG H'.2).some
662-
calc
663-
_ = #H.edgeFinset - Fintype.card (G.UnlabeledCopy H) := ?_
664-
_ ≤ #H.edgeFinset - #(univ.image f) := Nat.sub_le_sub_left card_image_le _
665-
_ = #H.edgeFinset - #(Set.range f).toFinset := by rw [Set.toFinset_range]
666-
_ ≤ #(H.edgeFinset \ (Set.range f).toFinset) := le_card_sdiff ..
667-
_ = #(H.killCopies G).edgeFinset := ?_
668-
· simp only [edgeFinset, Set.toFinset_card]
669-
rw [← Set.toFinset_card, ← edgeFinset, unlabeledCopyCount]
670-
congr 1
671-
ext e
672-
induction e using Sym2.inductionOn with | hf v w
673-
simp [mem_edgeSet, killCopies_of_ne_bot hG, f, eq_comm]
679+
calc #H.edgeFinset - H.unlabeledCopyCount G
680+
= #H.edgeFinset - Fintype.card (G.UnlabeledCopy H) := by
681+
rw [unlabeledCopyCount, Nat.card_eq_fintype_card]
682+
_ ≤ #H.edgeFinset - #(Finset.univ.image f) := Nat.sub_le_sub_left Finset.card_image_le _
683+
_ ≤ #(H.edgeFinset \ Finset.univ.image f) := le_card_sdiff ..
684+
_ = #(H.killCopies G).edgeFinset := by
685+
congr 1
686+
ext e
687+
induction e using Sym2.inductionOn with | hf v w
688+
simp [mem_edgeSet, killCopies_of_ne_bot hG, f, eq_comm]
674689

675690
/-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges
676691
we've removed is at most the number of copies of `G` in `H`. -/
677-
lemma le_card_edgeFinset_killCopies_add_unlabeledCopyCount [Fintype W] :
692+
lemma le_card_edgeFinset_killCopies_add_unlabeledCopyCount [Finite W] :
678693
#H.edgeFinset ≤ #(H.killCopies G).edgeFinset + H.unlabeledCopyCount G :=
679694
tsub_le_iff_right.1 le_card_edgeFinset_killCopies
680695

0 commit comments

Comments
 (0)