|
7 | 7 |
|
8 | 8 | public import Mathlib.Algebra.Order.Group.Nat |
9 | 9 | public import Mathlib.Combinatorics.SimpleGraph.Subgraph |
| 10 | +public import Mathlib.Data.Finite.Card |
10 | 11 |
|
11 | 12 | /-! |
12 | 13 | # Copies, containment, and counting of subgraphs |
@@ -69,7 +70,6 @@ The following notation is declared in scope `SimpleGraph`: |
69 | 70 | public section |
70 | 71 |
|
71 | 72 | open Finset Function |
72 | | -open Fintype (card) |
73 | 73 |
|
74 | 74 | namespace SimpleGraph |
75 | 75 | variable {V V' W W' X : Type*} |
@@ -207,6 +207,9 @@ instance [Fintype {f : G →g H // Injective f}] : Fintype (G.Copy H) := |
207 | 207 | invFun f := ⟨f.1, f.2⟩ |
208 | 208 | } |
209 | 209 |
|
| 210 | +instance [Finite V] [Finite W] : Finite (G.Copy H) := |
| 211 | + Finite.of_injective _ DFunLike.coe_injective |
| 212 | + |
210 | 213 | /-- A copy of `⊤` gives rise to an embedding of `⊤`. -/ |
211 | 214 | @[expose] def topEmbedding (f : Copy (⊤ : SimpleGraph V) H) : (⊤ : SimpleGraph V) ↪g H := |
212 | 215 | { f.toEmbedding with |
@@ -298,10 +301,11 @@ lemma IsContained.of_isEmpty [IsEmpty V] : G ⊑ H := |
298 | 301 | ⟨⟨isEmptyElim, fun {a} ↦ isEmptyElim a⟩, isEmptyElim⟩ |
299 | 302 |
|
300 | 303 | /-- `⊥` 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⟩⟩ |
305 | 309 |
|
306 | 310 | protected alias IsContained.bot := bot_isContained_iff_card_le |
307 | 311 |
|
@@ -482,89 +486,101 @@ For finite `G` and `H`, we count labeled and unlabeled copies of `G` in `H`. |
482 | 486 | -/ |
483 | 487 |
|
484 | 488 | section CopyCount |
485 | | -variable [Fintype V] [Fintype W] |
486 | 489 |
|
487 | 490 | /-- `H.copyCount G` is the number of labeled copies of `G` in `H`, i.e. the number of injective |
488 | 491 | graph homomorphisms from `G` to `H`. See `SimpleGraph.unlabeledCopyCount` for the number of |
489 | 492 | 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] |
492 | 498 |
|
493 | 499 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount := copyCount |
494 | 500 |
|
| 501 | +private instance [IsEmpty V] : Nonempty (Copy G H) := IsContained.of_isEmpty |
| 502 | + |
495 | 503 | @[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 |
499 | 505 |
|
500 | 506 | @[deprecated (since := "2026-04-30")] |
501 | 507 | alias labelledCopyCount_of_isEmpty := copyCount_of_isEmpty |
502 | 508 |
|
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] |
505 | 512 |
|
506 | 513 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount_eq_zero := copyCount_eq_zero |
507 | 514 |
|
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] |
510 | 517 |
|
511 | 518 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount_pos := copyCount_pos |
512 | 519 |
|
513 | 520 | end CopyCount |
514 | 521 |
|
515 | 522 | section UnlabeledCopyCount |
516 | | -variable [Fintype W] |
517 | 523 |
|
518 | 524 | /-- `G.UnlabeledCopy H` is the type of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. The |
519 | 525 | corresponding count is `SimpleGraph.unlabeledCopyCount`. -/ |
520 | 526 | abbrev UnlabeledCopy (G : SimpleGraph V) (H : SimpleGraph W) : Type _ := |
521 | 527 | {H' : H.Subgraph // Nonempty (G ≃g H'.coe)} |
522 | 528 |
|
| 529 | +instance [Finite W] : Finite (G.UnlabeledCopy H) := Subtype.finite |
| 530 | + |
523 | 531 | /-- `H.unlabeledCopyCount G` is the number of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. See |
524 | 532 | `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) |
527 | 535 |
|
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] |
531 | 538 |
|
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] |
534 | 546 |
|
535 | 547 | /-- 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 |
538 | 550 | rw [unlabeledCopyCount, copyCount] |
539 | | - apply Fintype.card_le_of_surjective |
| 551 | + apply Nat.card_le_card_of_surjective |
540 | 552 | (fun c : Copy G H ↦ (⟨c.toSubgraph, ⟨c.isoToSubgraph⟩⟩ : G.UnlabeledCopy H)) |
541 | 553 | rintro ⟨H', hG'⟩ |
542 | 554 | obtain ⟨c, hc⟩ : ∃ c, Copy.toSubgraph c = H' := by |
543 | 555 | rwa [← Set.mem_range, Copy.range_toSubgraph] |
544 | 556 | exact ⟨c, Subtype.ext hc⟩ |
545 | 557 |
|
546 | | -instance uniqueUnlabeledCopyBot (H : SimpleGraph W) : |
| 558 | +instance uniqueUnlabeledCopyBot [Finite W] (H : SimpleGraph W) : |
547 | 559 | Unique ((⊥ : SimpleGraph W).UnlabeledCopy H) where |
548 | 560 | default := ⟨{ verts := .univ, Adj := ⊥, adj_sub := False.elim, edge_vert := False.elim }, |
549 | 561 | ⟨(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⟩ |
562 | 581 |
|
563 | 582 | @[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 |
568 | 584 |
|
569 | 585 | end UnlabeledCopyCount |
570 | 586 |
|
@@ -653,28 +669,27 @@ noncomputable instance killCopies.edgeSet.instFintype : Fintype (H.killCopies G) |
653 | 669 |
|
654 | 670 | /-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges |
655 | 671 | 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] : |
657 | 673 | #H.edgeFinset - H.unlabeledCopyCount G ≤ #(H.killCopies G).edgeFinset := by |
658 | 674 | classical |
659 | 675 | obtain rfl | hG := eq_or_ne G ⊥ |
660 | 676 | · simp [← card_edgeSet] |
| 677 | + cases nonempty_fintype (G.UnlabeledCopy H) |
661 | 678 | 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] |
674 | 689 |
|
675 | 690 | /-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges |
676 | 691 | 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] : |
678 | 693 | #H.edgeFinset ≤ #(H.killCopies G).edgeFinset + H.unlabeledCopyCount G := |
679 | 694 | tsub_le_iff_right.1 le_card_edgeFinset_killCopies |
680 | 695 |
|
|
0 commit comments