AFTD Auto-Formalizing Theoretical Domains

near_perfect_matching_independent_anticomplete_count

theoremverified

If a matching misses at most two vertices of R, an independent subset U and a disjoint anticomplete subset W obey 2|U|+|W|≤|R|+2.

Statement

theorem near_perfect_matching_independent_anticomplete_count
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (R U W : Finset V) (M : G.Subgraph) (hM : M.IsMatching)
    (hMR : M.verts ⊆ (R : Set V)) (hnear : R.card ≤ 2*M.edgeSet.ncard+2)
    (hUR : U ⊆ R) (hWR : W ⊆ R) (hdis : Disjoint U W)
    (hUind : ∀ u ∈ U, ∀ v ∈ U, ¬ G.Adj u v)
    (hanti : ∀ u ∈ U, ∀ w ∈ W, ¬ G.Adj u w) :
    2*U.card+W.card ≤ R.card+2
Source
Positive-separator transfer for OP-1957; https://arxiv.org/abs/2611.22690.
Verified
27 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2

The proof, explained

We partition the vertices of R around the matching M. The matched vertices in U, denoted Q = U ∩ D, inject into the unchosen vertices Z = R \ (U ∪ W) because each matched partner of a vertex in Q must lie in R but cannot belong to U (by independence) or W (by anticompleteness), giving |Q| ≤ |Z|. Since M misses at most two vertices of R, the unmatched vertices in U satisfy |U \ D| ≤ |R \ D| ≤ 2, which implies |U| ≤ |Q| + 2 ≤ |Z| + 2. Combining this with the partition |R| = |Z| + |U| + |W| yields the desired bound 2|U| + |W| ≤ |R| + 2.

  1. Define D = V(M), Q = U ∩ D, and Z = R \ (U ∪ W), and show D ⊆ R with |D| = 2|E(M)|.

    We define D to be the vertex set of the matching M, Q to be the vertices of U matched by M, and Z to be the remaining vertices of R outside U ∪ W. Since all vertices of M lie in R by hypothesis, D ⊆ R. Because M is a matching, every edge has two distinct endpoints and edges share no vertices; hence |D| = 2|E(M)| (`in1076_matching_twice_card`, converted from `Set.ncard` to `Finset.card` via `Set.ncard_eq_toFinset_card'`).

    lines 9–18

    uses Set.ncard_eq_toFinset_card', in1076_matching_twice_card

      set_option maxHeartbeats 4000000 in
        classical
        let D : Finset V := M.verts.toFinset
        let Q : Finset V := U ∩ D
        let Z : Finset V := R \ (U ∪ W)
        have hDR : D ⊆ R := by intro x hx; exact hMR (by simpa [D] using hx)
        have hDcard : D.card = 2*M.edgeSet.ncard := by
          dsimp [D]
          rw [← Set.ncard_eq_toFinset_card']
          exact (in1076_matching_twice_card hM).symm
  2. |Q| ≤ |Z|

    We construct an injection f : Q → Z. For each x ∈ Q = U ∩ D, since x ∈ D = V(M), it has a matched neighbor y in M, obtained using `Classical.choose` and `Classical.choose_spec`. The partner y lies in R since V(M) ⊆ R. Moreover, y ∉ U because x ∈ U, y is adjacent to x in G, and U is independent (`hUind`); and y ∉ W because U and W are anticomplete (`hanti`). Hence y ∈ Z = R \ (U ∪ W) (`Finset.mem_sdiff.mpr`, `Finset.mem_union.mp`). If f(a) = f(b) = y, then y is matched to both a and b in M, so a = b by uniqueness of the matching partner at y (`Subtype.ext`). The injection implies |Q| ≤ |Z| (`Fintype.card_le_of_injective`).

    lines 19–52

    uses Finset.mem_inter.mp, Classical.choose, Classical.choose_spec, Finset.mem_sdiff.mpr, Finset.mem_union.mp, congrArg, Subtype.ext, Fintype.card_le_of_injective

        have hQZ : Q.card ≤ Z.card := by
          let f : {x // x ∈ Q} → {y // y ∈ Z} := fun x =>
            let hxU : x.val ∈ U := (Finset.mem_inter.mp x.property).1
            let hxM : x.val ∈ M.verts := by
              have hxD := (Finset.mem_inter.mp x.property).2
              simpa [D] using hxD
            let y := Classical.choose (hM hxM)
            let hxy := (Classical.choose_spec (hM hxM)).1
            ⟨y,Finset.mem_sdiff.mpr ⟨hMR (M.edge_vert hxy.symm),by
              intro hy
              rcases Finset.mem_union.mp hy with hyU | hyW
              · exact hUind x.val hxU y hyU (M.adj_sub hxy)
              · exact hanti x.val hxU y hyW (M.adj_sub hxy)⟩⟩
          have hinj : Function.Injective f := by
            intro a b hab
            let haM : a.val ∈ M.verts := by
              have ha := (Finset.mem_inter.mp a.property).2
              simpa [D] using ha
            let hbM : b.val ∈ M.verts := by
              have hb := (Finset.mem_inter.mp b.property).2
              simpa [D] using hb
            let ya := Classical.choose (hM haM)
            let yb := Classical.choose (hM hbM)
            have he : ya=yb := by
              have hh := congrArg Subtype.val hab
              change ya = yb at hh
              exact hh
            have hay : M.Adj ya a.val := (Classical.choose_spec (hM haM)).1.symm
            have hby : M.Adj ya b.val := by rw [he]; exact (Classical.choose_spec (hM hbM)).1.symm
            have hya : ya ∈ M.verts := M.edge_vert hay
            apply Subtype.ext
            exact (hM hya).unique hay hby
          have hh := Fintype.card_le_of_injective f hinj
          simpa using hh
  3. |U| ≤ |Q| + 2

    The unmatched vertices in U satisfy U \ D ⊆ R \ D (`Finset.mem_sdiff.mp`, `Finset.mem_sdiff.mpr`), so |U \ D| ≤ |R \ D| (`Finset.card_le_card`). Decomposing U gives |U| = |U \ D| + |Q| (`Finset.card_sdiff_add_card_inter`), and similarly |R \ D| = |R| - |D| (`Finset.card_sdiff_add_card_eq_card`). Since M misses at most two vertices of R, |R| ≤ |D| + 2, so |R \ D| ≤ 2. Linear arithmetic (`omega`) combines these bounds to deduce |U| ≤ |Q| + 2.

    lines 53–61

    uses Finset.mem_sdiff.mpr, Finset.mem_sdiff.mp, Finset.card_le_card, Finset.card_sdiff_add_card_eq_card, Finset.card_sdiff_add_card_inter

        have hUQ : U.card ≤ Q.card+2 := by
          have hsub : U \ D ⊆ R \ D := by
            intro x hx
            exact Finset.mem_sdiff.mpr ⟨hUR (Finset.mem_sdiff.mp hx).1,(Finset.mem_sdiff.mp hx).2⟩
          have hc := Finset.card_le_card hsub
          have hRD := Finset.card_sdiff_add_card_eq_card hDR
          have hUD := Finset.card_sdiff_add_card_inter U D
          dsimp [Q] at hQZ ⊢
          omega
  4. |Z| + |U| + |W| = |R|

    Since U ⊆ R and W ⊆ R, their union satisfies U ∪ W ⊆ R (`Finset.union_subset`). Because U and W are disjoint, |U ∪ W| = |U| + |W| (`Finset.card_union_of_disjoint`). By definition, Z = R \ (U ∪ W), so |Z| + |U ∪ W| = |R| (`Finset.card_sdiff_add_card_eq_card`), which simplifies via `omega` to |Z| + |U| + |W| = |R|.

    lines 62–67

    uses Finset.union_subset, Finset.card_sdiff_add_card_eq_card, Finset.card_union_of_disjoint

        have hUW : U ∪ W ⊆ R := Finset.union_subset hUR hWR
        have hZcard : Z.card+U.card+W.card=R.card := by
          have hh := Finset.card_sdiff_add_card_eq_card hUW
          have hc := Finset.card_union_of_disjoint hdis
          dsimp [Z]
          omega
  5. 2|U| + |W| ≤ |R| + 2

    Combining |U| ≤ |Q| + 2 and |Q| ≤ |Z| gives |U| ≤ |Z| + 2. Adding |U| + |W| to both sides gives 2|U| + |W| ≤ |Z| + |U| + |W| + 2. Substituting |Z| + |U| + |W| = |R| gives 2|U| + |W| ≤ |R| + 2. The linear arithmetic tactic `omega` closes the goal.

    line 68

        omega
Set.ncard_eq_toFinset_card'
The cardinality of a finite set as a natural number (`ncard`) equals the cardinality of its representation as a `Finset`.
in1076_matching_twice_card
In any matching subgraph, the number of vertices is twice the number of edges.
Classical.choose
Given an existential assertion, returns a witness satisfying the predicate.
Classical.choose_spec
The witness chosen by `Classical.choose` satisfies the given predicate.
Finset.mem_inter.mp
An element belongs to an intersection of two finsets if and only if it belongs to both.
Finset.mem_sdiff.mpr
An element belongs to the difference of two finsets if it belongs to the first and not the second.
Finset.mem_union.mp
An element belongs to the union of two finsets if and only if it belongs to at least one of them.
congrArg
Functions preserve equality: if a = b, then f(a) = f(b).
Subtype.ext
Two subtype elements are equal if their underlying values are equal.
Fintype.card_le_of_injective
An injection between finite types implies the cardinality of the domain is at most that of the codomain.
Finset.card_le_card
If one finset is a subset of another, its cardinality is less than or equal to that of the other.
Finset.card_sdiff_add_card_eq_card
For a subset s ⊆ t of finsets, |t \ s| + |s| = |t|.
Finset.card_sdiff_add_card_inter
For any two finsets s and t, |s \ t| + |s ∩ t| = |s|.
Finset.mem_sdiff.mp
If an element belongs to s \ t, then it belongs to s and does not belong to t.
Finset.union_subset
If two finsets are subsets of a third, their union is also a subset of that third finset.
Finset.card_union_of_disjoint
The cardinality of the union of two disjoint finsets is the sum of their cardinalities.

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

theorem near_perfect_matching_independent_anticomplete_count    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (R U W : Finset V) (M : G.Subgraph) (hM : M.IsMatching)    (hMR : M.verts ⊆ (R : Set V)) (hnear : R.card ≤ 2*M.edgeSet.ncard+2)    (hUR : U ⊆ R) (hWR : W ⊆ R) (hdis : Disjoint U W)    (hUind : ∀ u ∈ U, ∀ v ∈ U, ¬ G.Adj u v)    (hanti : ∀ u ∈ U, ∀ w ∈ W, ¬ G.Adj u w) :    2*U.card+W.card ≤ R.card+2 := by  set_option maxHeartbeats 4000000 in    classical    let D : Finset V := M.verts.toFinset    let Q : Finset V := U ∩ D    let Z : Finset V := R \ (U ∪ W)    have hDR : D ⊆ R := by intro x hx; exact hMR (by simpa [D] using hx)    have hDcard : D.card = 2*M.edgeSet.ncard := by      dsimp [D]      rw [← Set.ncard_eq_toFinset_card']      exact (in1076_matching_twice_card hM).symm    have hQZ : Q.card ≤ Z.card := by      let f : {x // x ∈ Q} → {y // y ∈ Z} := fun x =>        let hxU : x.val ∈ U := (Finset.mem_inter.mp x.property).1        let hxM : x.val ∈ M.verts := by          have hxD := (Finset.mem_inter.mp x.property).2          simpa [D] using hxD        let y := Classical.choose (hM hxM)        let hxy := (Classical.choose_spec (hM hxM)).1        ⟨y,Finset.mem_sdiff.mpr ⟨hMR (M.edge_vert hxy.symm),by          intro hy          rcases Finset.mem_union.mp hy with hyU | hyW          · exact hUind x.val hxU y hyU (M.adj_sub hxy)          · exact hanti x.val hxU y hyW (M.adj_sub hxy)⟩⟩      have hinj : Function.Injective f := by        intro a b hab        let haM : a.val ∈ M.verts := by          have ha := (Finset.mem_inter.mp a.property).2          simpa [D] using ha        let hbM : b.val ∈ M.verts := by          have hb := (Finset.mem_inter.mp b.property).2          simpa [D] using hb        let ya := Classical.choose (hM haM)        let yb := Classical.choose (hM hbM)        have he : ya=yb := by          have hh := congrArg Subtype.val hab          change ya = yb at hh          exact hh        have hay : M.Adj ya a.val := (Classical.choose_spec (hM haM)).1.symm        have hby : M.Adj ya b.val := by rw [he]; exact (Classical.choose_spec (hM hbM)).1.symm        have hya : ya ∈ M.verts := M.edge_vert hay        apply Subtype.ext        exact (hM hya).unique hay hby      have hh := Fintype.card_le_of_injective f hinj      simpa using hh    have hUQ : U.card ≤ Q.card+2 := by      have hsub : U \ D ⊆ R \ D := by        intro x hx        exact Finset.mem_sdiff.mpr ⟨hUR (Finset.mem_sdiff.mp hx).1,(Finset.mem_sdiff.mp hx).2⟩      have hc := Finset.card_le_card hsub      have hRD := Finset.card_sdiff_add_card_eq_card hDR      have hUD := Finset.card_sdiff_add_card_inter U D      dsimp [Q] at hQZ ⊢      omega    have hUW : U ∪ W ⊆ R := Finset.union_subset hUR hWR    have hZcard : Z.card+U.card+W.card=R.card := by      have hh := Finset.card_sdiff_add_card_eq_card hUW      have hc := Finset.card_union_of_disjoint hdis      dsimp [Z]      omega    omega
See it in the graphDiscuss this resultChallenge it