AFTD Auto-Formalizing Theoretical Domains

size_priority_matching_spec

theoremverified

For every edge set E of the bipartite graph on Fin n + Fin n and all real costs w, size_priority_matching n E w is size-priority optimal: a maximum-cardinality matching of E of minimum total cost among those.

Statement

theorem size_priority_matching_spec (n : ℕ) (E : Finset (Fin n × Fin n)) (w : Fin n × Fin n → ℝ) :
    is_size_priority_optimal n E w (size_priority_matching n E w)
Source
Sanity lemma for size_priority_matching (OP-1789).
Verified
17 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 3
  • size_priority_matchingA chosen size-priority optimal matching of the bipartite graph on Fin n + Fin n with edge set E under costs w (Hilbert's epsilon of…
  • bipartite_matchingsFor a bipartite graph with left vertices Fin n and right vertices Fin n whose edge set is E (a finite set of pairs (left, right)), the…
  • is_size_priority_optimalGiven the bipartite graph on Fin n + Fin n with edge set E and real edge costs w, a set M of pairs is size-priority optimal when it is a…
Used by 1
  • size_priority_matching_card_leFor every n, every edge set E ⊆ Fin n × Fin n, and every real cost function w, the size-priority optimal matching size_priority_matching n…

The proof, explained

To show that the chosen matching is size-priority optimal, it suffices to prove that at least one such optimal matching exists, since `size_priority_matching` is defined via Hilbert's epsilon choice operator. The finite set of all bipartite matchings in E is nonempty because it contains the empty matching, so there is a maximum matching cardinality k. The finite collection S of matchings of size k is therefore nonempty and contains an element M that minimizes total edge weight, which is size-priority optimal by construction.

  1. Let k be the maximum cardinality of a bipartite matching in E, and let S be the collection of matchings of size k.

    We work classically to establish that a size-priority optimal matching exists (`hex`). Since the empty set ∅ contains no edges, it vacuously satisfies the matching condition, showing that the finite set of bipartite matchings in E is nonempty (`hne`). Hence, the set of cardinalities of all matchings is a nonempty finite set of natural numbers and has a well-defined maximum k (`hk`). We define S to be the subcollection of matchings of cardinality k.

    lines 3–7

      classical
      have hex : ∃ M, is_size_priority_optimal n E w M := by
        have hne : (bipartite_matchings n E).Nonempty := ⟨∅, by simp [bipartite_matchings]⟩
        obtain ⟨k, hk⟩ : ∃ k, k = ((bipartite_matchings n E).image Finset.card).max' (hne.image _) := ⟨_, rfl⟩
        set S := (bipartite_matchings n E).filter (fun M => M.card = k)
  2. The set S of maximum-cardinality matchings is nonempty.

    By `Finset.max'_mem`, the maximum cardinality k belongs to the set of cardinalities of matchings. Therefore, there exists at least one bipartite matching M with |M| = k. This matching M satisfies the defining condition of S, showing that S is nonempty (`hSne`).

    lines 8–12

    uses Finset.max'_mem

        have hSne : S.Nonempty := by
          have := Finset.max'_mem ((bipartite_matchings n E).image Finset.card) (hne.image _)
          rw [← hk] at this
          obtain ⟨M, hM, hMk⟩ := Finset.mem_image.1 this
          exact ⟨M, Finset.mem_filter.2 ⟨hM, hMk⟩⟩
  3. There is a matching M ∈ S of minimal total edge weight among all matchings of size k.

    Because S is a nonempty finite set, the total weight function M ↦ ∑ e ∈ M, w e attains a minimum on S. We obtain a matching M ∈ S achieving this minimum (`hMmin`), which means M is a bipartite matching (`hM`) with |M| = k (`hMk`).

    lines 13–14

        obtain ⟨M, hMS, hMmin⟩ := S.exists_min_image (fun M => ∑ e ∈ M, w e) hSne
        obtain ⟨hM, hMk⟩ := Finset.mem_filter.1 hMS
  4. The matching M is size-priority optimal, completing the existence proof.

    We show that M satisfies all conditions of `is_size_priority_optimal`: it is a matching; any other matching M' satisfies |M'| ≤ |M| because |M'| ≤ k by `Finset.le_max'` since |M'| is in the image of matchings under cardinality (`Finset.mem_image_of_mem`) and |M| = k; and any matching M' of the same cardinality |M'| = |M| = k belongs to S and thus has total weight at least that of M by the minimality of M in S (`hMmin`).

    lines 15–17

    uses Finset.le_max', Finset.mem_image_of_mem

        refine ⟨M, hM, fun M' hM' => ?_, fun M' hM' hcard => hMmin M' (Finset.mem_filter.2 ⟨hM', hcard.trans hMk⟩)⟩
        rw [hMk, hk]
        exact Finset.le_max' _ _ (Finset.mem_image_of_mem _ hM')
  5. The matching selected by size_priority_matching is size-priority optimal.

    Since `size_priority_matching n E w` is defined via Hilbert's choice operator (`Classical.epsilon`) on the predicate `is_size_priority_optimal n E w`, `Classical.epsilon_spec` applied to the existence result `hex` ensures that the chosen matching is indeed size-priority optimal.

    line 18

    uses Classical.epsilon_spec

      exact Classical.epsilon_spec hex
Finset.max'_mem
The maximum element of a nonempty finite set belongs to that set.
Finset.le_max'
Every element of a nonempty finite set with a linear order is less than or equal to the maximum of the set.
Finset.mem_image_of_mem
If an element belongs to a finite set, its image under a function belongs to the image of the set under that function.
Classical.epsilon_spec
If there exists an element satisfying a predicate, Hilbert's epsilon choice operator produces an element satisfying that predicate.

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 size_priority_matching_spec (n : ℕ) (E : Finset (Fin n × Fin n)) (w : Fin n × Fin n → ℝ) :    is_size_priority_optimal n E w (size_priority_matching n E w) := by  classical  have hex : ∃ M, is_size_priority_optimal n E w M := by    have hne : (bipartite_matchings n E).Nonempty := ⟨∅, by simp [bipartite_matchings]⟩    obtain ⟨k, hk⟩ : ∃ k, k = ((bipartite_matchings n E).image Finset.card).max' (hne.image _) := ⟨_, rfl⟩    set S := (bipartite_matchings n E).filter (fun M => M.card = k)    have hSne : S.Nonempty := by      have := Finset.max'_mem ((bipartite_matchings n E).image Finset.card) (hne.image _)      rw [← hk] at this      obtain ⟨M, hM, hMk⟩ := Finset.mem_image.1 this      exact ⟨M, Finset.mem_filter.2 ⟨hM, hMk⟩⟩    obtain ⟨M, hMS, hMmin⟩ := S.exists_min_image (fun M => ∑ e ∈ M, w e) hSne    obtain ⟨hM, hMk⟩ := Finset.mem_filter.1 hMS    refine ⟨M, hM, fun M' hM' => ?_, fun M' hM' hcard => hMmin M' (Finset.mem_filter.2 ⟨hM', hcard.trans hMk⟩)⟩    rw [hMk, hk]    exact Finset.le_max' _ _ (Finset.mem_image_of_mem _ hM')  exact Classical.epsilon_spec hex
See it in the graphDiscuss this resultChallenge it