AFTD Auto-Formalizing Theoretical Domains

finite_matching_has_submatching_of_each_smaller_size

theoremverified

Every finite matching with at least k edges contains a submatching with exactly k edges.

Statement

theorem finite_matching_has_submatching_of_each_smaller_size
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (M : G.Subgraph) (hM : M.IsMatching) (k : ℕ) (hk : k ≤ M.edgeSet.ncard) :
    ∃ N : G.Subgraph, N.IsMatching ∧ N ≤ M ∧ N.edgeSet.ncard = k
Source
OP-1957; restricting a finite matching to a specified number of its edges.
Verified
26 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
  • is_k_extendableFor a finite vertex type V (with [Fintype V]), a simple graph G : SimpleGraph V and k : ℕ, is_k_extendable G k is the Prop that is the…
Used by 8

The proof, explained

To construct a submatching of size k from a matching M with at least k edges, we select a subset E of k edges from M. We define a subgraph N having edge set E and whose vertices are the endpoints of these edges. Because N inherits its edges from M, every vertex in N has at most its degree in M (which is 1), so N is a matching. Since N has exactly k edges and is a subgraph of M by construction, it is the desired submatching.

  1. There exists a subset E of k edges from the edge set of M.

    Because the vertex set V is finite, the edge set of M can be regarded as a finite set F whose cardinality equals the set cardinality of M's edge set. Since this cardinality is at least k, Finset.exists_subset_card_eq produces a sub-finset E ⊆ F containing exactly k edges.

    lines 5–12

    uses Set.ncard_eq_toFinset_card', Finset.exists_subset_card_eq

      set_option maxHeartbeats 4000000 in
        classical
        let F : Finset (Sym2 V) := M.edgeSet.toFinset
        have hF : k ≤ F.card := by
          dsimp [F]
          rw [← Set.ncard_eq_toFinset_card']
          exact hk
        obtain ⟨E,hEF,hEcard⟩ := Finset.exists_subset_card_eq hF
  2. Every edge in E is an edge of M.

    Since E is a subset of F, any edge s(u, v) ∈ E belongs to M.edgeSet.toFinset, and therefore to M.edgeSet, meaning u and v are adjacent in M.

    lines 13–17

    uses SimpleGraph.Subgraph.mem_edgeSet.mp, Set.mem_toFinset.mp

        have hEM : ∀ u v, s(u,v) ∈ E → M.Adj u v := by
          intro u v h
          have hh := hEF h
          change s(u,v) ∈ M.edgeSet.toFinset at hh
          exact SimpleGraph.Subgraph.mem_edgeSet.mp (Set.mem_toFinset.mp hh)
  3. The edges in E and their incident vertices form a valid subgraph N of G.

    We define N to have adjacency relation s(u, v) ∈ E and vertex set consisting of all endpoints of edges in E. Every edge in E is an edge in M (and thus in G), the endpoints of any edge in E belong to the vertex set by construction, and the adjacency relation is symmetric because unordered pairs satisfy s(u, v) = s(v, u).

    lines 18–23

    uses Sym2.eq_swap

        let N : G.Subgraph := {
          verts := {v | ∃ w, s(v,w) ∈ E}
          Adj := fun u v => s(u,v) ∈ E
          adj_sub := by intro u v h; exact M.adj_sub (hEM u v h)
          edge_vert := by intro u v h; exact ⟨v,h⟩
          symm := ⟨by intro u v h; simpa [Sym2.eq_swap] using h⟩ }
  4. N is a matching.

    Every vertex v of N is incident to at least one edge s(v, w) ∈ E by definition of N's vertex set. Because this edge is also in M and M is a matching, v has a unique neighbor in M. Since any neighbor z of v in N is also a neighbor in M, uniqueness forces z = w, meaning v has degree exactly 1 in N.

    lines 24–30

        have hN : N.IsMatching := by
          intro v hv
          obtain ⟨w,hw⟩ := hv
          have hMv := hEM v w hw
          refine ⟨w,hw,?_⟩
          intro z hz
          exact (hM (M.edge_vert hMv)).unique (hEM v z hz) hMv
  5. N is a subgraph of M.

    Every vertex in N is incident to an edge in E ⊆ E(M), so it is a vertex of M. Moreover, every adjacency in N is in E, hence is an adjacency in M.

    lines 31–37

        have hNM : N ≤ M := by
          constructor
          · intro v hv
            obtain ⟨w,hw⟩ := hv
            exact M.edge_vert (hEM v w hw)
          · intro u v huv
            exact hEM u v huv
  6. N has exactly k edges, completing the proof.

    By induction on unordered pairs, an edge belongs to N.edgeSet if and only if it belongs to E, so N.edgeSet is definitionally equal to E as a set. Its cardinality is therefore |E| = k. Together with the facts that N is a matching and N ≤ M, N provides the required witness.

    lines 38–44

    uses Sym2.inductionOn, Set.ncard_coe_finset

        have hcard : N.edgeSet.ncard = k := by
          have heq : N.edgeSet = (E : Set (Sym2 V)) := by
            ext e
            induction e using Sym2.inductionOn with
            | _ u v => rfl
          rw [heq,Set.ncard_coe_finset,hEcard]
        exact ⟨N,hN,hNM,hcard⟩
Set.ncard_eq_toFinset_card'
For a set s with finite coercion, the set cardinality s.ncard equals the cardinality of the associated finset s.toFinset.
Finset.exists_subset_card_eq
Any finite set of cardinality at least n contains a subset of cardinality exactly n.
SimpleGraph.Subgraph.mem_edgeSet.mp
If an unordered pair s(u, v) is in the edge set of a subgraph, then u and v are adjacent in that subgraph.
Set.mem_toFinset.mp
If an element belongs to s.toFinset, then it belongs to the set s.
Sym2.eq_swap
The unordered pair s(a, b) equals the unordered pair s(b, a).
Sym2.inductionOn
To prove a property for all unordered pairs, it suffices to prove it for pairs of the form s(x, y).
Set.ncard_coe_finset
The set cardinality of a coerced finset equals the finset's cardinality.

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 finite_matching_has_submatching_of_each_smaller_size    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (M : G.Subgraph) (hM : M.IsMatching) (k : ℕ) (hk : k ≤ M.edgeSet.ncard) :    ∃ N : G.Subgraph, N.IsMatching ∧ N ≤ M ∧ N.edgeSet.ncard = k := by  set_option maxHeartbeats 4000000 in    classical    let F : Finset (Sym2 V) := M.edgeSet.toFinset    have hF : k ≤ F.card := by      dsimp [F]      rw [← Set.ncard_eq_toFinset_card']      exact hk    obtain ⟨E,hEF,hEcard⟩ := Finset.exists_subset_card_eq hF    have hEM : ∀ u v, s(u,v) ∈ E → M.Adj u v := by      intro u v h      have hh := hEF h      change s(u,v) ∈ M.edgeSet.toFinset at hh      exact SimpleGraph.Subgraph.mem_edgeSet.mp (Set.mem_toFinset.mp hh)    let N : G.Subgraph := {      verts := {v | ∃ w, s(v,w) ∈ E}      Adj := fun u v => s(u,v) ∈ E      adj_sub := by intro u v h; exact M.adj_sub (hEM u v h)      edge_vert := by intro u v h; exact ⟨v,h⟩      symm := ⟨by intro u v h; simpa [Sym2.eq_swap] using h⟩ }    have hN : N.IsMatching := by      intro v hv      obtain ⟨w,hw⟩ := hv      have hMv := hEM v w hw      refine ⟨w,hw,?_⟩      intro z hz      exact (hM (M.edge_vert hMv)).unique (hEM v z hz) hMv    have hNM : N ≤ M := by      constructor      · intro v hv        obtain ⟨w,hw⟩ := hv        exact M.edge_vert (hEM v w hw)      · intro u v huv        exact hEM u v huv    have hcard : N.edgeSet.ncard = k := by      have heq : N.edgeSet = (E : Set (Sym2 V)) := by        ext e        induction e using Sym2.inductionOn with        | _ u v => rfl      rw [heq,Set.ncard_coe_finset,hEcard]    exact ⟨N,hN,hNM,hcard⟩
See it in the graphDiscuss this resultChallenge it