AFTD Auto-Formalizing Theoretical Domains

size_priority_matching_card_le

theoremverified

For 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 E w has cardinality at most n.

Statement

theorem size_priority_matching_card_le (n : ℕ) (E : Finset (Fin n × Fin n))
    (w : Fin n × Fin n → ℝ) :
    (size_priority_matching n E w).card ≤ n
Source
arXiv:2601.20502, Optimal matching under size priority
Verified
18 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
  • size_priority_matching_specFor 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:…
  • 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…
  • 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…
  • 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…
Used by 1

Read back from the Lean

For every natural number $n$, every finite set of directed edges $E \subseteq \mathrm{Fin}(n) \times \mathrm{Fin}(n)$, and every edge-weight function $w : \mathrm{Fin}(n) \times \mathrm{Fin}(n) \to \mathbb{R}$, the cardinality of size_priority_matching n E w is at most $n$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The size-priority optimal matching M is, by definition, an element of the collection of bipartite matchings on Fin n × Fin n, meaning no two distinct edges in M share an endpoint. Consequently, the projection map (u, v) ↦ u to the first coordinate is injective when restricted to M. The cardinality of M therefore equals the cardinality of its image under this projection, which is a subset of Fin n and thus has size at most n.

  1. The chosen matching M satisfies the bipartite matching property: no two edges share a left or right endpoint.

    By size_priority_matching_spec, the matching M = size_priority_matching n E w is optimal, so it belongs to bipartite_matchings n E. Unfolding the definition of bipartite matchings as a filtered powerset using Finset.mem_filter extracts the condition that any two edges in M that share either a first or second coordinate must be identical.

    lines 5–9

    uses size_priority_matching_spec, Finset.mem_filter

      have h_opt := size_priority_matching_spec n E w
      have h_m : size_priority_matching n E w ∈ bipartite_matchings n E := h_opt.1
      rw [bipartite_matchings, Finset.mem_filter] at h_m
      obtain ⟨_, h_inj⟩ := h_m
      set M := size_priority_matching n E w
  2. The projection onto the first coordinate is injective when restricted to M.

    Suppose two edges e, f ∈ M have the same first coordinate (e.1 = f.1). Using Or.inl, this establishes the disjunction e.1 = f.1 ∨ e.2 = f.2, which by the matching condition implies e = f.

    lines 10–12

    uses Or.inl

      have h_fst_inj : ∀ e ∈ M, ∀ f ∈ M, e.1 = f.1 → e = f := by
        intro e he f hf h1
        exact h_inj e he f hf (Or.inl h1)
  3. The cardinality of M equals the cardinality of its projection onto the first coordinate.

    Because the first-coordinate projection Prod.fst is injective on M, Finset.card_image_of_injOn guarantees that the image of M under Prod.fst has the exact same number of elements as M.

    lines 13–14

    uses Finset.card_image_of_injOn

      have h_card : M.card = (M.image Prod.fst).card := by
        exact (Finset.card_image_of_injOn fun e he f hf h => h_fst_inj e he f hf h).symm
  4. The cardinality of M is at most n.

    The size of M is rewritten as the size of its projection to the first coordinate. Since this image is a subset of the n-element type Fin n, Finset.card_le_univ bounds its cardinality by Fintype.card (Fin n), which simplifies to n by Fintype.card_fin.

    lines 15–18

    uses Finset.card_le_univ, Fintype.card_fin

      rw [h_card]
      have h_le : (M.image Prod.fst).card ≤ Fintype.card (Fin n) := Finset.card_le_univ (M.image Prod.fst)
      simp only [Fintype.card_fin] at h_le
      exact h_le
size_priority_matching_spec
The matching produced by size_priority_matching is size-priority optimal, which in particular implies it is a bipartite matching.
Finset.mem_filter
An element belongs to the filter of a finite set by a predicate if and only if it belongs to the set and satisfies the predicate.
Or.inl
From a proof of P, one can deduce the disjunction P ∨ Q.
Finset.card_image_of_injOn
The image of a finite set under a function has the same cardinality as the set, provided the function is injective on that set.
Finset.card_le_univ
The cardinality of any finite subset of a finite type is at most the cardinality of the entire type.
Fintype.card_fin
The standard finite set Fin n of natural numbers strictly less than n has cardinality n.

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

/-- Every size-priority optimal matching on Fin n + Fin n has cardinality at most n. -/theorem size_priority_matching_card_le (n : ℕ) (E : Finset (Fin n × Fin n))    (w : Fin n × Fin n → ℝ) :    (size_priority_matching n E w).card ≤ n := by  have h_opt := size_priority_matching_spec n E w  have h_m : size_priority_matching n E w ∈ bipartite_matchings n E := h_opt.1  rw [bipartite_matchings, Finset.mem_filter] at h_m  obtain ⟨_, h_inj⟩ := h_m  set M := size_priority_matching n E w  have h_fst_inj : ∀ e ∈ M, ∀ f ∈ M, e.1 = f.1 → e = f := by    intro e he f hf h1    exact h_inj e he f hf (Or.inl h1)  have h_card : M.card = (M.image Prod.fst).card := by    exact (Finset.card_image_of_injOn fun e he f hf h => h_fst_inj e he f hf h).symm  rw [h_card]  have h_le : (M.image Prod.fst).card ≤ Fintype.card (Fin n) := Finset.card_le_univ (M.image Prod.fst)  simp only [Fintype.card_fin] at h_le  exact h_le
See it in the graphDiscuss this resultChallenge it