AFTD Auto-Formalizing Theoretical Domains

simple_graph_active_edge_matching_le_two_mul_triangle_packing

theoremverified

In any finite simple graph, every vertex-disjoint matching of edges that each lie in a triangle has at most twice the triangle packing number.

Statement

theorem simple_graph_active_edge_matching_le_two_mul_triangle_packing (n : ℕ) (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (M : Finset (Sym2 (Fin n))) (hactive : ∀ e ∈ M, e ∈ G.edgeSet ∧ ∃ t : Finset (Fin n), G.IsNClique 3 t ∧ e ∈ finite_vertex_set_edge_encoding t) (hmatching : (M : Set (Sym2 (Fin n))).Pairwise (fun e f => Disjoint e.toFinset f.toFinset)) : M.card ≤ 2 * simple_graph_triangle_packing_number G
Source
Matching-witness reduction for the sunflower-packing branch; no novelty claim.
Verified
25 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 3

The proof, explained

To bound the size of an active edge matching M, each edge e ∈ M is assigned a triangle t(e) containing it. We choose a maximum-cardinality subset S ⊆ M whose triangles pairwise share at most one vertex, so that {t(e) : e ∈ S} forms an edge-disjoint triangle packing and therefore |S| ≤ ν(G). By maximality, every remaining edge f ∈ M \ S has t(f) sharing two vertices with t(e) for some e ∈ S. The key geometric lemma shows that if two triangles from the matching share two vertices, the third vertex of each lies in the edge of the other, which prevents any t(e) from sharing two vertices with two different triangles; this yields an injective map from M \ S into S, so |M| = |S| + |M \ S| ≤ 2|S| ≤ 2 ν(G).

  1. For any vertex z in Te \ e, the triangle Te equals e ∪ {z}.

    We choose an arbitrary z ∈ Te \ e. Since z ∉ e and e ⊆ Te, the set e ∪ {z} is contained in Te. Since |e| = 2 and z ∉ e, |e ∪ {z}| = 3 = |Te|, so Te = e ∪ {z}.

    lines 8–18

    uses Finset.mem_sdiff, Finset.eq_of_subset_of_card_le, Finset.card_insert_of_notMem

      intro z hz
      rw [Finset.mem_sdiff] at hz
      obtain ⟨hzTe, hze⟩ := hz
      have hTe : Te = insert z e := by
        symm
        apply Finset.eq_of_subset_of_card_le
        · intro x hx
          rcases Finset.mem_insert.1 hx with rfl | hx
          · exact hzTe
          · exact heTe hx
        · rw [Finset.card_insert_of_notMem hze, hec, hTc]
  2. The vertex z must belong to Tf.

    Suppose for contradiction that z ∉ Tf. Since Te = e ∪ {z}, every vertex in Te ∩ Tf other than z must belong to e, so Te ∩ Tf ⊆ e. Because |Te ∩ Tf| = 2 = |e|, this implies Te ∩ Tf = e, and therefore e ⊆ Tf. But then the union e ∪ f is contained in Tf. Since e and f are disjoint 2-element sets, |e ∪ f| = 4, yet |Tf| = 3, which is impossible.

    lines 19–41

    uses Finset.eq_of_subset_of_card_le, Finset.card_le_card, Finset.card_union_of_disjoint

      have hzTf : z ∈ Tf := by
        by_contra hzTf
        have hsub : Te ∩ Tf ⊆ e := by
          intro x hx
          rw [Finset.mem_inter] at hx
          rw [hTe] at hx
          rcases Finset.mem_insert.1 hx.1 with rfl | hx1
          · exact absurd hx.2 hzTf
          · exact hx1
        have heq : Te ∩ Tf = e := by
          apply Finset.eq_of_subset_of_card_le hsub
          rw [hec, hint]
        have heTf : e ⊆ Tf := by
          intro x hx
          have : x ∈ Te ∩ Tf := by rw [heq]; exact hx
          exact (Finset.mem_inter.1 this).2
        have hunion : e ∪ f ⊆ Tf := fun x hx => by
          rcases Finset.mem_union.1 hx with hx | hx
          · exact heTf hx
          · exact hfTf hx
        have hle := Finset.card_le_card hunion
        rw [Finset.card_union_of_disjoint hdis, hec, hfc, hTfc] at hle
        omega
  3. If z ∉ f, then Tf equals f ∪ {z}.

    Assuming z ∉ f for contradiction, the set f ∪ {z} is a subset of Tf of cardinality |f| + 1 = 3. Since |Tf| = 3, we have Tf = f ∪ {z}.

    lines 42–50

    uses Finset.eq_of_subset_of_card_le, Finset.card_insert_of_notMem

      by_contra hzf
      have hTf : Tf = insert z f := by
        symm
        apply Finset.eq_of_subset_of_card_le
        · intro x hx
          rcases Finset.mem_insert.1 hx with rfl | hx
          · exact hzTf
          · exact hfTf hx
        · rw [Finset.card_insert_of_notMem hzf, hfc, hTfc]
  4. The assumption z ∉ f implies Te ∩ Tf ⊆ {z}, contradicting |Te ∩ Tf| = 2, so z ∈ f.

    Any element x ∈ Te ∩ Tf distinct from z must belong to e (since Te = e ∪ {z}) and to f (since Tf = f ∪ {z}). But e and f are disjoint, so no such x can exist. Hence Te ∩ Tf ⊆ {z}, giving |Te ∩ Tf| ≤ 1, which contradicts |Te ∩ Tf| = 2. Thus z ∈ f, establishing Te \ e ⊆ f.

    lines 51–68

    uses Finset.mem_singleton, Finset.card_le_card, Finset.card_singleton

      have hsub : Te ∩ Tf ⊆ {z} := by
        intro x hx
        rw [Finset.mem_inter] at hx
        rw [Finset.mem_singleton]
        by_contra hxz
        rw [hTe, hTf] at hx
        have hxe : x ∈ e := by
          rcases Finset.mem_insert.1 hx.1 with h | h
          · exact absurd h hxz
          · exact h
        have hxf : x ∈ f := by
          rcases Finset.mem_insert.1 hx.2 with h | h
          · exact absurd h hxz
          · exact h
        exact Finset.disjoint_left.1 hdis hxe hxf
      have hle := Finset.card_le_card hsub
      rw [Finset.card_singleton, hint] at hle
      omega
  5. Any family T of triangles that pairwise share at most one vertex satisfies |T| ≤ ν(G).

    By definition, the triangle packing number ν(G) is the supremum of cardinalities of families of triangles pairwise sharing at most one vertex. The collection of all such cardinalities is bounded above by the total number of vertex subsets, so the supremum exists and bounds |T| from above.

    lines 78–84

    uses Finset.card_le_univ, le_csSup

      unfold simple_graph_triangle_packing_number
      have hbdd : BddAbove {n | ∃ T' : Finset (Finset V), (∀ t ∈ T', G.IsNClique 3 t) ∧
          (T' : Set (Finset V)).Pairwise (fun s t => (s ∩ t).card ≤ 1) ∧ T'.card = n} := by
        refine ⟨(Finset.univ : Finset (Finset V)).card, ?_⟩
        rintro n ⟨T', -, -, rfl⟩
        exact Finset.card_le_univ T'
      exact le_csSup hbdd ⟨T, hcl, hp, rfl⟩
  6. For each edge e ∈ M, there is a triangle t(e) containing e.

    By the active edge hypothesis, each edge e ∈ M lies in at least one 3-clique. Using the axiom of choice, we define a function t choosing one such triangle t(e) for each e ∈ M.

    lines 87–97

    uses dif_pos, Classical.choose_spec

      set_option maxHeartbeats 1000000 in
      classical
      have hex : ∀ e ∈ M, ∃ t : Finset (Fin n), G.IsNClique 3 t ∧
          e ∈ finite_vertex_set_edge_encoding t := fun e he => (hactive e he).2
      let t : Sym2 (Fin n) → Finset (Fin n) :=
        fun e => if h : e ∈ M then Classical.choose (hex e h) else ∅
      have ht : ∀ (e : Sym2 (Fin n)) (he : e ∈ M), G.IsNClique 3 (t e) ∧
          e ∈ finite_vertex_set_edge_encoding (t e) := by
        intro e he
        simp only [t, dif_pos he]
        exact Classical.choose_spec (hex e he)
  7. Each t(e) has 3 vertices, each edge e ∈ M consists of 2 vertices contained in t(e), and distinct edges in M are vertex-disjoint.

    Because each t(e) is a 3-clique, |t(e)| = 3. Since edges in the graph have no self-loops, each edge e ∈ M has 2 distinct endpoints which lie in t(e). Furthermore, the matching hypothesis directly provides that distinct edges in M are disjoint.

    lines 98–115

    uses Sym2.card_toFinset, if_neg

      have htcl : ∀ e ∈ M, G.IsNClique 3 (t e) := fun e he => (ht e he).1
      have htcard : ∀ e ∈ M, (t e).card = 3 := fun e he => (htcl e he).card_eq
      have htmem : ∀ e ∈ M, e ∈ (t e).sym2 := fun e he => by
        have h3 := (ht e he).2
        rw [finite_vertex_set_edge_encoding, Finset.mem_filter] at h3
        exact h3.1
      have htndiag : ∀ e ∈ M, ¬ e.IsDiag := fun e he => by
        have h3 := (ht e he).2
        rw [finite_vertex_set_edge_encoding, Finset.mem_filter] at h3
        exact h3.2
      have htsub : ∀ e ∈ M, e.toFinset ⊆ t e := by
        intro e he x hx
        exact Finset.mem_sym2_iff.1 (htmem e he) x (Sym2.mem_toFinset.1 hx)
      have hcard2 : ∀ e ∈ M, e.toFinset.card = 2 := by
        intro e he
        rw [Sym2.card_toFinset, if_neg (htndiag e he)]
      have hdis : ∀ e ∈ M, ∀ f ∈ M, e ≠ f → Disjoint e.toFinset f.toFinset :=
        fun e he f hf hne => hmatching he hf hne
  8. The assignment e ↦ t(e) is injective on M.

    If two distinct edges e, f ∈ M had t(e) = t(f), then both of their disjoint 2-element vertex sets would be contained in t(f), forcing |e ∪ f| = 4 ≤ |t(f)| = 3, a contradiction.

    lines 116–127

    uses Finset.card_le_card, Finset.card_union_of_disjoint

      have hinj : ∀ e ∈ M, ∀ f ∈ M, t e = t f → e = f := by
        intro e he f hf hEq
        by_contra hne
        have hsub : e.toFinset ∪ f.toFinset ⊆ t f := by
          intro x hx
          rcases Finset.mem_union.1 hx with hx | hx
          · rw [← hEq]; exact htsub e he hx
          · exact htsub f hf hx
        have hle := Finset.card_le_card hsub
        rw [Finset.card_union_of_disjoint (hdis e he f hf hne), hcard2 e he, hcard2 f hf,
          htcard f hf] at hle
        omega
  9. For any two distinct edges e, f ∈ M, their triangles share at most 2 vertices.

    The intersection t(e) ∩ t(f) has size at most 3 since |t(e)| = 3. If it had size 3, then t(e) = t(f), which would contradict the injectivity of the assignment t on M.

    lines 128–141

    uses Finset.inter_subset_left, Finset.inter_subset_right, Finset.eq_of_subset_of_card_le

      have hint2 : ∀ e ∈ M, ∀ f ∈ M, e ≠ f → (t e ∩ t f).card ≤ 2 := by
        intro e he f hf hne
        have hle : (t e ∩ t f).card ≤ 3 := by
          have h := Finset.card_le_card (Finset.inter_subset_left : t e ∩ t f ⊆ t e)
          rwa [htcard e he] at h
        have hne3 : (t e ∩ t f).card ≠ 3 := by
          intro h3
          have heq : t e ∩ t f = t e := by
            apply Finset.eq_of_subset_of_card_le Finset.inter_subset_left
            rw [h3, htcard e he]
          have hsub : t e ⊆ t f := by rw [← heq]; exact Finset.inter_subset_right
          have hcard : (t f).card ≤ (t e).card := by rw [htcard e he, htcard f hf]
          exact hne (hinj e he f hf (Finset.eq_of_subset_of_card_le hsub hcard))
        omega
  10. A triangle t(e) cannot share 2 vertices with both t(f) and t(g) for distinct f, g ∈ M.

    The set t(e) \ e contains exactly one vertex z. By the third-vertex auxiliary lemma, |t(e) ∩ t(f)| = 2 implies z ∈ f, and |t(e) ∩ t(g)| = 2 implies z ∈ g. But distinct edges f and g in the matching M are disjoint, which is a contradiction.

    lines 142–159

    uses Finset.card_sdiff, one_pos, simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex

      have hkey : ∀ e ∈ M, ∀ f ∈ M, ∀ g ∈ M, e ≠ f → e ≠ g → f ≠ g →
          ¬ ((t e ∩ t f).card = 2 ∧ (t e ∩ t g).card = 2) := by
        intro e he f hf g hg hef heg hfg hcon
        obtain ⟨h1, h2⟩ := hcon
        have hsingle : (t e \ e.toFinset).card = 1 := by
          rw [Finset.card_sdiff]
          have h1' : e.toFinset ∩ t e = e.toFinset := Finset.inter_eq_left.2 (htsub e he)
          rw [h1', hcard2 e he, htcard e he]
        obtain ⟨z, hz⟩ := Finset.card_pos.1 (by rw [hsingle]; exact one_pos)
        have hzf : z ∈ f.toFinset :=
          (simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex
            (htsub e he) (hcard2 e he) (htcard e he) (htsub f hf) (hcard2 f hf)
            (htcard f hf) (hdis e he f hf hef) h1) hz
        have hzg : z ∈ g.toFinset :=
          (simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex
            (htsub e he) (hcard2 e he) (htcard e he) (htsub g hg) (hcard2 g hg)
            (htcard g hg) (hdis e he g hg heg) h2) hz
        exact Finset.disjoint_left.1 (hdis f hf g hg hfg) hzf hzg
  11. There is a maximum-cardinality subset S ⊆ M whose triangles pairwise share at most 1 vertex.

    The set of sizes of subsets S' ⊆ M whose triangles pairwise share at most 1 vertex is non-empty (containing 0 for the empty set) and bounded above by |M|. The supremum of this set of natural numbers is achieved by some subset S.

    lines 160–178

    uses Finset.empty_subset, Finset.card_le_card, Nat.sSup_mem, le_csSup

      have hexmax : ∃ S : Finset (Sym2 (Fin n)),
          S ⊆ M ∧ (∀ e ∈ S, ∀ f ∈ S, e ≠ f → (t e ∩ t f).card ≤ 1) ∧
          ∀ S' : Finset (Sym2 (Fin n)), S' ⊆ M →
            (∀ e ∈ S', ∀ f ∈ S', e ≠ f → (t e ∩ t f).card ≤ 1) → S'.card ≤ S.card := by
        let A : Set ℕ := {k | ∃ S : Finset (Sym2 (Fin n)), S ⊆ M ∧
          (∀ e ∈ S, ∀ f ∈ S, e ≠ f → (t e ∩ t f).card ≤ 1) ∧ S.card = k}
        have hne : A.Nonempty := ⟨0, ∅, Finset.empty_subset _, by simp, rfl⟩
        have hbdd : BddAbove A := by
          refine ⟨M.card, ?_⟩
          rintro k ⟨S, hSM, -, rfl⟩
          exact Finset.card_le_card hSM
        have hsSup := Nat.sSup_mem hne hbdd
        obtain ⟨S, hSM, hSgood, hkS⟩ := hsSup
        refine ⟨S, hSM, hSgood, ?_⟩
        intro S' hS'M hS'good
        have hmem : S'.card ∈ A := ⟨S', hS'M, hS'good, rfl⟩
        rw [hkS]
        exact le_csSup hbdd hmem
      obtain ⟨S, hSM, hSgood, hSmax⟩ := hexmax
  12. Every edge f ∈ M \ S has its triangle share exactly 2 vertices with t(e) for some e ∈ S.

    By maximality of S, adding f to S must violate the condition that triangles pairwise share at most 1 vertex. Thus there exists e ∈ S such that |t(e) ∩ t(f)| ≥ 2. Since f ∉ S, e ≠ f, so the intersection cannot have size 3; hence |t(e) ∩ t(f)| = 2.

    lines 179–208

    uses Finset.inter_comm, Finset.card_insert_of_notMem, le_antisymm

      have hcover : ∀ f ∈ M, f ∉ S → ∃ e ∈ S, (t e ∩ t f).card = 2 := by
        intro f hfM hfS
        have hex' : ∃ e ∈ S, 2 ≤ (t e ∩ t f).card := by
          by_contra hno
          push Not at hno
          have hinsM : insert f S ⊆ M := by
            intro x hx
            rcases Finset.mem_insert.1 hx with rfl | hx
            · exact hfM
            · exact hSM hx
          have hinsgood : ∀ e ∈ insert f S, ∀ g ∈ insert f S, e ≠ g → (t e ∩ t g).card ≤ 1 := by
            intro e he g hg hne
            rcases Finset.mem_insert.1 he with rfl | heS'
            · rcases Finset.mem_insert.1 hg with hgf | hgS'
              · exact absurd hgf.symm hne
              · rw [Finset.inter_comm]
                have hlt := hno g hgS'
                omega
            · rcases Finset.mem_insert.1 hg with hgf | hgS'
              · subst hgf
                have hlt := hno e heS'
                omega
              · exact hSgood e heS' g hgS' hne
          have hres := hSmax (insert f S) hinsM hinsgood
          rw [Finset.card_insert_of_notMem hfS] at hres
          omega
        obtain ⟨e, heS, h2⟩ := hex'
        refine ⟨e, heS, le_antisymm (hint2 e (hSM heS) f hfM ?_) h2⟩
        intro h
        exact hfS (h ▸ heS)
  13. The map φ : M \ S → S assigning to each f an edge e ∈ S with |t(e) ∩ t(f)| = 2 is injective.

    If φ(f) = φ(g) = e for distinct f, g ∈ M \ S, then t(e) would share 2 vertices with both t(f) and t(g), which was shown to be impossible.

    lines 209–234

    uses dif_pos, Classical.choose_spec

      set R : Finset (Sym2 (Fin n)) := M \ S with hR
      have hRsub : R ⊆ M := fun x hx => (Finset.mem_sdiff.1 hx).1
      have hRnot : ∀ f ∈ R, f ∉ S := fun f hf => (Finset.mem_sdiff.1 hf).2
      have hexφ : ∀ f ∈ R, ∃ e, e ∈ S ∧ (t e ∩ t f).card = 2 :=
        fun f hf => hcover f (hRsub hf) (hRnot f hf)
      let φ : Sym2 (Fin n) → Sym2 (Fin n) :=
        fun f => if h : f ∈ R then Classical.choose (hexφ f h) else f
      have hφprop : ∀ (f : Sym2 (Fin n)) (hf : f ∈ R), φ f ∈ S ∧ (t (φ f) ∩ t f).card = 2 := by
        intro f hf
        simp only [φ, dif_pos hf]
        exact Classical.choose_spec (hexφ f hf)
      have hinjφ : ∀ f ∈ R, ∀ g ∈ R, φ f = φ g → f = g := by
        intro f hf g hg hEq
        by_contra hne
        have hfM := hRsub hf
        have hfS := hRnot f hf
        have hgM := hRsub hg
        have hgS := hRnot g hg
        have heS : φ f ∈ S := (hφprop f hf).1
        have heM : φ f ∈ M := hSM heS
        have hef : φ f ≠ f := fun h => hfS (h ▸ heS)
        have heg : φ f ≠ g := fun h => hgS (h ▸ heS)
        have h1 : (t (φ f) ∩ t f).card = 2 := (hφprop f hf).2
        have h2 : (t (φ g) ∩ t g).card = 2 := (hφprop g hg).2
        rw [← hEq] at h2
        exact hkey (φ f) heM f hfM g hgM hef heg hne ⟨h1, h2⟩
  14. The cardinality of M \ S is at most |S|.

    The injective map φ from R = M \ S into S implies |R| ≤ |S|.

    lines 235–240

    uses Finset.card_le_card_of_injOn

      have hRcard : R.card ≤ S.card := by
        refine Finset.card_le_card_of_injOn φ ?_ ?_
        · intro f hf
          exact (hφprop f hf).1
        · intro f hf g hg h
          exact hinjφ f hf g hg h
  15. The subset S satisfies |S| ≤ ν(G).

    The image family of triangles {t(e) : e ∈ S} has cardinality |S| by injectivity of t, and its members pairwise share at most 1 vertex. By the packing cardinality lemma, any such family has size at most the triangle packing number ν(G).

    lines 241–256

    uses Finset.card_image_of_injOn, simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_packing_card

      have hSle : S.card ≤ simple_graph_triangle_packing_number G := by
        have hcl : ∀ x ∈ S.image t, G.IsNClique 3 x := by
          intro x hx
          obtain ⟨e, he, rfl⟩ := Finset.mem_image.1 hx
          exact htcl e (hSM he)
        have hp : ((S.image t : Finset (Finset (Fin n))) : Set (Finset (Fin n))).Pairwise
            (fun s x => (s ∩ x).card ≤ 1) := by
          intro x hx y hy hne
          obtain ⟨e, he, rfl⟩ := Finset.mem_image.1 hx
          obtain ⟨f, hf, rfl⟩ := Finset.mem_image.1 hy
          exact hSgood e he f hf (fun h => hne (by rw [h]))
        have hcard : (S.image t).card = S.card :=
          Finset.card_image_of_injOn (fun e he f hf h => hinj e (hSM he) f (hSM hf) h)
        rw [← hcard]
        exact simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_packing_card
          G (S.image t) hcl hp
  16. The total size |M| is at most 2 * ν(G).

    Decomposing M into S and R = M \ S gives |M| = |S| + |R| ≤ |S| + |S| = 2|S| ≤ 2 ν(G).

    lines 257–264

    uses Finset.card_sdiff_add_card_eq_card

      have hMcard : M.card = S.card + R.card := by
        have h := Finset.card_sdiff_add_card_eq_card hSM
        rw [← hR] at h
        omega
      calc M.card = S.card + R.card := hMcard
        _ ≤ S.card + S.card := by omega
        _ = 2 * S.card := by ring
        _ ≤ 2 * simple_graph_triangle_packing_number G := by omega
Finset.mem_sdiff
An element belongs to the set difference s \ t if and only if it belongs to s and not to t.
Finset.eq_of_subset_of_card_le
If a finite set s is a subset of t and |t| ≤ |s|, then s = t.
Finset.card_insert_of_notMem
Inserting an element not already in a finite set increases its cardinality by 1.
Finset.card_le_card
If s ⊆ t for finite sets, then |s| ≤ |t|.
Finset.card_union_of_disjoint
The cardinality of the union of two disjoint finite sets is the sum of their cardinalities.
Finset.mem_singleton
An element belongs to a singleton set {a} if and only if it equals a.
Finset.card_singleton
Any singleton finite set has cardinality 1.
Finset.card_le_univ
Any finite subset of a finite type has cardinality at most the cardinality of the whole type.
le_csSup
Any element of a set of numbers bounded above is at most the supremum of that set.
dif_pos
A dependent if-then-else evaluates to the `then` branch when the condition is true.
Classical.choose_spec
The witness selected by `Classical.choose` satisfies the existential property.
Sym2.card_toFinset
The vertex set of an unordered pair has cardinality 1 if it is a diagonal (self-loop) and 2 otherwise.
if_neg
An if-then-else evaluates to the `else` branch when the condition is false.
Finset.inter_subset_left
The intersection of two sets is a subset of the first set.
Finset.inter_subset_right
The intersection of two sets is a subset of the second set.
Finset.card_sdiff
The cardinality of the set difference t \ s is |t| - |s ∩ t|.
one_pos
Zero is strictly less than one.
simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex
If two triangles each containing an edge from a matching share two vertices, the third vertex of the first triangle must belong to the edge of the second.
Finset.empty_subset
The empty set is a subset of every set.
Nat.sSup_mem
A non-empty set of natural numbers bounded above contains its supremum (its maximum).
Finset.inter_comm
Intersection of finite sets is commutative.
le_antisymm
In a partial order, if a ≤ b and b ≤ a, then a = b.
Finset.card_le_card_of_injOn
If a function maps a finite set s into a finite set t injectively, then |s| ≤ |t|.
Finset.card_image_of_injOn
The image of a finite set under an injective map has the same cardinality as the original set.
simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_packing_card
Any family of triangles that pairwise share at most one vertex has cardinality at most the triangle packing number of the graph.
Finset.card_sdiff_add_card_eq_card
If s ⊆ t, then |t \ s| + |s| = |t|.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

set_option maxHeartbeats 1000000 in/-- If a triangle `Te` contains a two-element set `e` and another triangle `Tf` contains a two-element set `f` disjoint from `e`, and the two triangles share exactly two vertices, then the third vertex of `Te` lies in `f`. -/private lemma simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex    {α : Type*} [DecidableEq α]    {e Te f Tf : Finset α} (heTe : e ⊆ Te) (hec : e.card = 2) (hTc : Te.card = 3)    (hfTf : f ⊆ Tf) (hfc : f.card = 2) (hTfc : Tf.card = 3) (hdis : Disjoint e f)    (hint : (Te ∩ Tf).card = 2) : Te \ e ⊆ f := by  intro z hz  rw [Finset.mem_sdiff] at hz  obtain ⟨hzTe, hze⟩ := hz  have hTe : Te = insert z e := by    symm    apply Finset.eq_of_subset_of_card_le    · intro x hx      rcases Finset.mem_insert.1 hx with rfl | hx      · exact hzTe      · exact heTe hx    · rw [Finset.card_insert_of_notMem hze, hec, hTc]  have hzTf : z ∈ Tf := by    by_contra hzTf    have hsub : Te ∩ Tf ⊆ e := by      intro x hx      rw [Finset.mem_inter] at hx      rw [hTe] at hx      rcases Finset.mem_insert.1 hx.1 with rfl | hx1      · exact absurd hx.2 hzTf      · exact hx1    have heq : Te ∩ Tf = e := by      apply Finset.eq_of_subset_of_card_le hsub      rw [hec, hint]    have heTf : e ⊆ Tf := by      intro x hx      have : x ∈ Te ∩ Tf := by rw [heq]; exact hx      exact (Finset.mem_inter.1 this).2    have hunion : e ∪ f ⊆ Tf := fun x hx => by      rcases Finset.mem_union.1 hx with hx | hx      · exact heTf hx      · exact hfTf hx    have hle := Finset.card_le_card hunion    rw [Finset.card_union_of_disjoint hdis, hec, hfc, hTfc] at hle    omega  by_contra hzf  have hTf : Tf = insert z f := by    symm    apply Finset.eq_of_subset_of_card_le    · intro x hx      rcases Finset.mem_insert.1 hx with rfl | hx      · exact hzTf      · exact hfTf hx    · rw [Finset.card_insert_of_notMem hzf, hfc, hTfc]  have hsub : Te ∩ Tf ⊆ {z} := by    intro x hx    rw [Finset.mem_inter] at hx    rw [Finset.mem_singleton]    by_contra hxz    rw [hTe, hTf] at hx    have hxe : x ∈ e := by      rcases Finset.mem_insert.1 hx.1 with h | h      · exact absurd h hxz      · exact h    have hxf : x ∈ f := by      rcases Finset.mem_insert.1 hx.2 with h | h      · exact absurd h hxz      · exact h    exact Finset.disjoint_left.1 hdis hxe hxf  have hle := Finset.card_le_card hsub  rw [Finset.card_singleton, hint] at hle  omegaset_option maxHeartbeats 1000000 in/-- Any family of triangles that pairwise share at most one vertex has at most `ν(G)` members. -/private lemma simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_packing_card    {V : Type*} [Fintype V] [DecidableEq V]    (G : SimpleGraph V) (T : Finset (Finset V))    (hcl : ∀ t ∈ T, G.IsNClique 3 t)    (hp : (T : Set (Finset V)).Pairwise (fun s t => (s ∩ t).card ≤ 1)) :    T.card ≤ simple_graph_triangle_packing_number G := by  unfold simple_graph_triangle_packing_number  have hbdd : BddAbove {n | ∃ T' : Finset (Finset V), (∀ t ∈ T', G.IsNClique 3 t) ∧      (T' : Set (Finset V)).Pairwise (fun s t => (s ∩ t).card ≤ 1) ∧ T'.card = n} := by    refine ⟨(Finset.univ : Finset (Finset V)).card, ?_⟩    rintro n ⟨T', -, -, rfl⟩    exact Finset.card_le_univ T'  exact le_csSup hbdd ⟨T, hcl, hp, rfl⟩theorem simple_graph_active_edge_matching_le_two_mul_triangle_packing (n : ℕ) (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (M : Finset (Sym2 (Fin n))) (hactive : ∀ e ∈ M, e ∈ G.edgeSet ∧ ∃ t : Finset (Fin n), G.IsNClique 3 t ∧ e ∈ finite_vertex_set_edge_encoding t) (hmatching : (M : Set (Sym2 (Fin n))).Pairwise (fun e f => Disjoint e.toFinset f.toFinset)) : M.card ≤ 2 * simple_graph_triangle_packing_number G := by  set_option maxHeartbeats 1000000 in  classical  have hex : ∀ e ∈ M, ∃ t : Finset (Fin n), G.IsNClique 3 t ∧      e ∈ finite_vertex_set_edge_encoding t := fun e he => (hactive e he).2  let t : Sym2 (Fin n) → Finset (Fin n) :=    fun e => if h : e ∈ M then Classical.choose (hex e h) else ∅  have ht : ∀ (e : Sym2 (Fin n)) (he : e ∈ M), G.IsNClique 3 (t e) ∧      e ∈ finite_vertex_set_edge_encoding (t e) := by    intro e he    simp only [t, dif_pos he]    exact Classical.choose_spec (hex e he)  have htcl : ∀ e ∈ M, G.IsNClique 3 (t e) := fun e he => (ht e he).1  have htcard : ∀ e ∈ M, (t e).card = 3 := fun e he => (htcl e he).card_eq  have htmem : ∀ e ∈ M, e ∈ (t e).sym2 := fun e he => by    have h3 := (ht e he).2    rw [finite_vertex_set_edge_encoding, Finset.mem_filter] at h3    exact h3.1  have htndiag : ∀ e ∈ M, ¬ e.IsDiag := fun e he => by    have h3 := (ht e he).2    rw [finite_vertex_set_edge_encoding, Finset.mem_filter] at h3    exact h3.2  have htsub : ∀ e ∈ M, e.toFinset ⊆ t e := by    intro e he x hx    exact Finset.mem_sym2_iff.1 (htmem e he) x (Sym2.mem_toFinset.1 hx)  have hcard2 : ∀ e ∈ M, e.toFinset.card = 2 := by    intro e he    rw [Sym2.card_toFinset, if_neg (htndiag e he)]  have hdis : ∀ e ∈ M, ∀ f ∈ M, e ≠ f → Disjoint e.toFinset f.toFinset :=    fun e he f hf hne => hmatching he hf hne  have hinj : ∀ e ∈ M, ∀ f ∈ M, t e = t f → e = f := by    intro e he f hf hEq    by_contra hne    have hsub : e.toFinset ∪ f.toFinset ⊆ t f := by      intro x hx      rcases Finset.mem_union.1 hx with hx | hx      · rw [← hEq]; exact htsub e he hx      · exact htsub f hf hx    have hle := Finset.card_le_card hsub    rw [Finset.card_union_of_disjoint (hdis e he f hf hne), hcard2 e he, hcard2 f hf,      htcard f hf] at hle    omega  have hint2 : ∀ e ∈ M, ∀ f ∈ M, e ≠ f → (t e ∩ t f).card ≤ 2 := by    intro e he f hf hne    have hle : (t e ∩ t f).card ≤ 3 := by      have h := Finset.card_le_card (Finset.inter_subset_left : t e ∩ t f ⊆ t e)      rwa [htcard e he] at h    have hne3 : (t e ∩ t f).card ≠ 3 := by      intro h3      have heq : t e ∩ t f = t e := by        apply Finset.eq_of_subset_of_card_le Finset.inter_subset_left        rw [h3, htcard e he]      have hsub : t e ⊆ t f := by rw [← heq]; exact Finset.inter_subset_right      have hcard : (t f).card ≤ (t e).card := by rw [htcard e he, htcard f hf]      exact hne (hinj e he f hf (Finset.eq_of_subset_of_card_le hsub hcard))    omega  have hkey : ∀ e ∈ M, ∀ f ∈ M, ∀ g ∈ M, e ≠ f → e ≠ g → f ≠ g →      ¬ ((t e ∩ t f).card = 2 ∧ (t e ∩ t g).card = 2) := by    intro e he f hf g hg hef heg hfg hcon    obtain ⟨h1, h2⟩ := hcon    have hsingle : (t e \ e.toFinset).card = 1 := by      rw [Finset.card_sdiff]      have h1' : e.toFinset ∩ t e = e.toFinset := Finset.inter_eq_left.2 (htsub e he)      rw [h1', hcard2 e he, htcard e he]    obtain ⟨z, hz⟩ := Finset.card_pos.1 (by rw [hsingle]; exact one_pos)    have hzf : z ∈ f.toFinset :=      (simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex        (htsub e he) (hcard2 e he) (htcard e he) (htsub f hf) (hcard2 f hf)        (htcard f hf) (hdis e he f hf hef) h1) hz    have hzg : z ∈ g.toFinset :=      (simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_third_vertex        (htsub e he) (hcard2 e he) (htcard e he) (htsub g hg) (hcard2 g hg)        (htcard g hg) (hdis e he g hg heg) h2) hz    exact Finset.disjoint_left.1 (hdis f hf g hg hfg) hzf hzg  have hexmax : ∃ S : Finset (Sym2 (Fin n)),      S ⊆ M ∧ (∀ e ∈ S, ∀ f ∈ S, e ≠ f → (t e ∩ t f).card ≤ 1) ∧      ∀ S' : Finset (Sym2 (Fin n)), S' ⊆ M →        (∀ e ∈ S', ∀ f ∈ S', e ≠ f → (t e ∩ t f).card ≤ 1) → S'.card ≤ S.card := by    let A : Set ℕ := {k | ∃ S : Finset (Sym2 (Fin n)), S ⊆ M ∧      (∀ e ∈ S, ∀ f ∈ S, e ≠ f → (t e ∩ t f).card ≤ 1) ∧ S.card = k}    have hne : A.Nonempty := ⟨0, ∅, Finset.empty_subset _, by simp, rfl⟩    have hbdd : BddAbove A := by      refine ⟨M.card, ?_⟩      rintro k ⟨S, hSM, -, rfl⟩      exact Finset.card_le_card hSM    have hsSup := Nat.sSup_mem hne hbdd    obtain ⟨S, hSM, hSgood, hkS⟩ := hsSup    refine ⟨S, hSM, hSgood, ?_⟩    intro S' hS'M hS'good    have hmem : S'.card ∈ A := ⟨S', hS'M, hS'good, rfl⟩    rw [hkS]    exact le_csSup hbdd hmem  obtain ⟨S, hSM, hSgood, hSmax⟩ := hexmax  have hcover : ∀ f ∈ M, f ∉ S → ∃ e ∈ S, (t e ∩ t f).card = 2 := by    intro f hfM hfS    have hex' : ∃ e ∈ S, 2 ≤ (t e ∩ t f).card := by      by_contra hno      push Not at hno      have hinsM : insert f S ⊆ M := by        intro x hx        rcases Finset.mem_insert.1 hx with rfl | hx        · exact hfM        · exact hSM hx      have hinsgood : ∀ e ∈ insert f S, ∀ g ∈ insert f S, e ≠ g → (t e ∩ t g).card ≤ 1 := by        intro e he g hg hne        rcases Finset.mem_insert.1 he with rfl | heS'        · rcases Finset.mem_insert.1 hg with hgf | hgS'          · exact absurd hgf.symm hne          · rw [Finset.inter_comm]            have hlt := hno g hgS'            omega        · rcases Finset.mem_insert.1 hg with hgf | hgS'          · subst hgf            have hlt := hno e heS'            omega          · exact hSgood e heS' g hgS' hne      have hres := hSmax (insert f S) hinsM hinsgood      rw [Finset.card_insert_of_notMem hfS] at hres      omega    obtain ⟨e, heS, h2⟩ := hex'    refine ⟨e, heS, le_antisymm (hint2 e (hSM heS) f hfM ?_) h2⟩    intro h    exact hfS (h ▸ heS)  set R : Finset (Sym2 (Fin n)) := M \ S with hR  have hRsub : R ⊆ M := fun x hx => (Finset.mem_sdiff.1 hx).1  have hRnot : ∀ f ∈ R, f ∉ S := fun f hf => (Finset.mem_sdiff.1 hf).2  have hexφ : ∀ f ∈ R, ∃ e, e ∈ S ∧ (t e ∩ t f).card = 2 :=    fun f hf => hcover f (hRsub hf) (hRnot f hf)  let φ : Sym2 (Fin n) → Sym2 (Fin n) :=    fun f => if h : f ∈ R then Classical.choose (hexφ f h) else f  have hφprop : ∀ (f : Sym2 (Fin n)) (hf : f ∈ R), φ f ∈ S ∧ (t (φ f) ∩ t f).card = 2 := by    intro f hf    simp only [φ, dif_pos hf]    exact Classical.choose_spec (hexφ f hf)  have hinjφ : ∀ f ∈ R, ∀ g ∈ R, φ f = φ g → f = g := by    intro f hf g hg hEq    by_contra hne    have hfM := hRsub hf    have hfS := hRnot f hf    have hgM := hRsub hg    have hgS := hRnot g hg    have heS : φ f ∈ S := (hφprop f hf).1    have heM : φ f ∈ M := hSM heS    have hef : φ f ≠ f := fun h => hfS (h ▸ heS)    have heg : φ f ≠ g := fun h => hgS (h ▸ heS)    have h1 : (t (φ f) ∩ t f).card = 2 := (hφprop f hf).2    have h2 : (t (φ g) ∩ t g).card = 2 := (hφprop g hg).2    rw [← hEq] at h2    exact hkey (φ f) heM f hfM g hgM hef heg hne ⟨h1, h2⟩  have hRcard : R.card ≤ S.card := by    refine Finset.card_le_card_of_injOn φ ?_ ?_    · intro f hf      exact (hφprop f hf).1    · intro f hf g hg h      exact hinjφ f hf g hg h  have hSle : S.card ≤ simple_graph_triangle_packing_number G := by    have hcl : ∀ x ∈ S.image t, G.IsNClique 3 x := by      intro x hx      obtain ⟨e, he, rfl⟩ := Finset.mem_image.1 hx      exact htcl e (hSM he)    have hp : ((S.image t : Finset (Finset (Fin n))) : Set (Finset (Fin n))).Pairwise        (fun s x => (s ∩ x).card ≤ 1) := by      intro x hx y hy hne      obtain ⟨e, he, rfl⟩ := Finset.mem_image.1 hx      obtain ⟨f, hf, rfl⟩ := Finset.mem_image.1 hy      exact hSgood e he f hf (fun h => hne (by rw [h]))    have hcard : (S.image t).card = S.card :=      Finset.card_image_of_injOn (fun e he f hf h => hinj e (hSM he) f (hSM hf) h)    rw [← hcard]    exact simple_graph_active_edge_matching_le_two_mul_triangle_packing_aux_packing_card      G (S.image t) hcl hp  have hMcard : M.card = S.card + R.card := by    have h := Finset.card_sdiff_add_card_eq_card hSM    rw [← hR] at h    omega  calc M.card = S.card + R.card := hMcard    _ ≤ S.card + S.card := by omega    _ = 2 * S.card := by ring    _ ≤ 2 * simple_graph_triangle_packing_number G := by omega
See it in the graphDiscuss this resultChallenge it