|
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*} |
@@ -206,6 +206,9 @@ instance [Fintype {f : G →g H // Injective f}] : Fintype (G.Copy H) := |
206 | 206 | invFun f := ⟨f.1, f.2⟩ |
207 | 207 | } |
208 | 208 |
|
| 209 | +instance [Finite V] [Finite W] : Finite (G.Copy H) := |
| 210 | + Finite.of_injective _ DFunLike.coe_injective |
| 211 | + |
209 | 212 | /-- A copy of `⊤` gives rise to an embedding of `⊤`. -/ |
210 | 213 | @[expose] def topEmbedding (f : Copy (⊤ : SimpleGraph V) H) : (⊤ : SimpleGraph V) ↪g H := |
211 | 214 | { f.toEmbedding with |
@@ -297,10 +300,11 @@ lemma IsContained.of_isEmpty [IsEmpty V] : G ⊑ H := |
297 | 300 | ⟨⟨isEmptyElim, fun {a} ↦ isEmptyElim a⟩, isEmptyElim⟩ |
298 | 301 |
|
299 | 302 | /-- `⊥` 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⟩⟩ |
304 | 308 |
|
305 | 309 | protected alias IsContained.bot := bot_isContained_iff_card_le |
306 | 310 |
|
@@ -473,89 +477,101 @@ For finite `G` and `H`, we count labeled and unlabeled copies of `G` in `H`. |
473 | 477 | -/ |
474 | 478 |
|
475 | 479 | section CopyCount |
476 | | -variable [Fintype V] [Fintype W] |
477 | 480 |
|
478 | 481 | /-- `H.copyCount G` is the number of labeled copies of `G` in `H`, i.e. the number of injective |
479 | 482 | graph homomorphisms from `G` to `H`. See `SimpleGraph.unlabeledCopyCount` for the number of |
480 | 483 | 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] |
483 | 489 |
|
484 | 490 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount := copyCount |
485 | 491 |
|
| 492 | +private instance [IsEmpty V] : Nonempty (Copy G H) := IsContained.of_isEmpty |
| 493 | + |
486 | 494 | @[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 |
490 | 496 |
|
491 | 497 | @[deprecated (since := "2026-04-30")] |
492 | 498 | alias labelledCopyCount_of_isEmpty := copyCount_of_isEmpty |
493 | 499 |
|
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] |
496 | 503 |
|
497 | 504 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount_eq_zero := copyCount_eq_zero |
498 | 505 |
|
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] |
501 | 508 |
|
502 | 509 | @[deprecated (since := "2026-04-30")] alias labelledCopyCount_pos := copyCount_pos |
503 | 510 |
|
504 | 511 | end CopyCount |
505 | 512 |
|
506 | 513 | section UnlabeledCopyCount |
507 | | -variable [Fintype W] |
508 | 514 |
|
509 | 515 | /-- `G.UnlabeledCopy H` is the type of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. The |
510 | 516 | corresponding count is `SimpleGraph.unlabeledCopyCount`. -/ |
511 | 517 | abbrev UnlabeledCopy (G : SimpleGraph V) (H : SimpleGraph W) : Type _ := |
512 | 518 | {H' : H.Subgraph // Nonempty (G ≃g H'.coe)} |
513 | 519 |
|
| 520 | +instance [Finite W] : Finite (G.UnlabeledCopy H) := Subtype.finite |
| 521 | + |
514 | 522 | /-- `H.unlabeledCopyCount G` is the number of `SimpleGraph.Subgraph`s of `H` isomorphic to `G`. See |
515 | 523 | `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) |
518 | 526 |
|
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] |
522 | 529 |
|
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] |
525 | 537 |
|
526 | 538 | /-- 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 |
529 | 541 | rw [unlabeledCopyCount, copyCount] |
530 | | - apply Fintype.card_le_of_surjective |
| 542 | + apply Nat.card_le_card_of_surjective |
531 | 543 | (fun c : Copy G H ↦ (⟨c.toSubgraph, ⟨c.isoToSubgraph⟩⟩ : G.UnlabeledCopy H)) |
532 | 544 | rintro ⟨H', hG'⟩ |
533 | 545 | obtain ⟨c, hc⟩ : ∃ c, Copy.toSubgraph c = H' := by |
534 | 546 | rwa [← Set.mem_range, Copy.range_toSubgraph] |
535 | 547 | exact ⟨c, Subtype.ext hc⟩ |
536 | 548 |
|
537 | | -instance uniqueUnlabeledCopyBot (H : SimpleGraph W) : |
| 549 | +instance uniqueUnlabeledCopyBot [Finite W] (H : SimpleGraph W) : |
538 | 550 | Unique ((⊥ : SimpleGraph W).UnlabeledCopy H) where |
539 | 551 | default := ⟨{ verts := .univ, Adj := ⊥, adj_sub := False.elim, edge_vert := False.elim }, |
540 | 552 | ⟨(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⟩ |
553 | 572 |
|
554 | 573 | @[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 |
559 | 575 |
|
560 | 576 | end UnlabeledCopyCount |
561 | 577 |
|
@@ -644,28 +660,27 @@ noncomputable instance killCopies.edgeSet.instFintype : Fintype (H.killCopies G) |
644 | 660 |
|
645 | 661 | /-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges |
646 | 662 | 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] : |
648 | 664 | #H.edgeFinset - H.unlabeledCopyCount G ≤ #(H.killCopies G).edgeFinset := by |
649 | 665 | classical |
650 | 666 | obtain rfl | hG := eq_or_ne G ⊥ |
651 | 667 | · simp [← card_edgeSet] |
| 668 | + cases nonempty_fintype (G.UnlabeledCopy H) |
652 | 669 | 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] |
665 | 680 |
|
666 | 681 | /-- Removing an edge from `H` for each subgraph isomorphic to `G` means that the number of edges |
667 | 682 | 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] : |
669 | 684 | #H.edgeFinset ≤ #(H.killCopies G).edgeFinset + H.unlabeledCopyCount G := |
670 | 685 | tsub_le_iff_right.1 le_card_edgeFinset_killCopies |
671 | 686 |
|
|
0 commit comments