While this submission is a draft, it cannot be used by other submissions.

Kuhn's Algorithm Computes a Maximum Matching

Lax117284.BipartiteKuhnCorrect · concepts/Lax117284/BipartiteKuhnCorrect.lean · lax-117284

proven

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Theorem

    The matching Kuhn's algorithm returns is a matching of the graph, and no matching of the graph has more edges. In particular it saturates the left side exactly when some matching does, and its size is the matching number of the bipartite graph.

    Concept map
    5 concepts
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A
    Evidence

    This concept declares 4 statements. Each proof establishes one of them relative to its assumptions.

    Lean source view on GitHub

    1import Lax117284.BipartiteKuhn
    2import Lax117284.BipartiteMatching
    3import Lax117284.BipartiteGraph
    4
    5/-!
    6---
    7title: Kuhn's Algorithm Computes a Maximum Matching
    8type: theorem
    9---
    10The matching Kuhn's algorithm returns is a matching of the graph, and no matching of the graph
    11has more edges. In particular it saturates the left side exactly when some matching does, and
    12its size is the matching number of the bipartite graph.
    13
    14# Formalization Notes
    15
    16The first two statements are about the relation the algorithm works on; the third is about the
    17graph, in Mathlib's terms: for a graph on `Fin V` split at `n`, the relation between `Fin n`
    18and `Fin (V - n)` is adjacency across the split, and a matching of the graph is the same thing
    19as an injective assignment of left neighbours to right vertices, edge for edge.
    20
    21The proof does not use Berge's lemma. A search from `l₀` fails only when every right vertex
    22reachable from `l₀` by alternating exploration is already matched, and the left vertices so
    23reached then outnumber the right vertices so reached by exactly one. This state is stable: a
    24later augmentation from another free vertex keeps the reached left vertices matched, hence into
    25the same set of right neighbours, which it therefore saturates again, so that `l₀` reaches
    26nothing new and stays failed. At the end the failed left vertices `F` and the set `S` of all
    27left vertices reachable from them have `|N(S)| = |S| - |F|`, and any matching matches at most
    28`|N(S)|` vertices of `S`, so it has at most `|L| - |F|` edges — which is the size of the
    29matching returned, since every left vertex outside `F` is matched.
    30-/
    31
    32namespace Lax117284.BipartiteKuhnCorrect
    33
    34open Lax117284.BipartiteKuhn Lax117284.BipartiteMatching Lax117284.BipartiteGraph
    35
    36variable {L R : Type*} [Fintype L] [DecidableEq L] [Fintype R] [DecidableEq R]
    37 (adj : L → R → Prop) [DecidableRel adj]
    38
    39/-- **The result is a matching of the graph.** -/
    40axiom kuhn_isMatching : Respects adj (kuhn adj) ∧ InjOnSupport (kuhn adj)
    41
    42/-- **No matching is larger.** -/
    43axiom kuhn_maximum (μ : R → Option L) (hres : Respects adj μ) (hinj : InjOnSupport μ) :
    44 size μ ≤ size (kuhn adj)
    45
    46/-- **A matching saturating the left side exists exactly when the result is one.** -/
    47axiom kuhn_saturates_iff :
    48 (∀ l, Matched (kuhn adj) l) ↔ ∃ f : L → R, Function.Injective f ∧ ∀ l, adj l (f l)
    49
    50/-- The adjacency across the split of a graph on `Fin V` split at `n`, as a relation between
    51the left vertices `Fin n` and the right vertices `Fin (V - n)`. -/
    52def leftRel {V : ℕ} (G : SimpleGraph (Fin V)) (n : ℕ) (hn : n ≤ V) :
    53 Fin n → Fin (V - n) → Prop :=
    54 fun i j => G.Adj ⟨i, by omega⟩ ⟨n + j, by omega⟩
    55
    56open scoped Classical in
    57/-- **The size of the result is the matching number of the graph.** -/
    58axiom kuhn_matchingNumber {V : ℕ} (G : SimpleGraph (Fin V)) (n : ℕ) (hn : n ≤ V)
    59 (hs : SplitAt G n) : size (kuhn (leftRel G n hn)) = matchingNumber G
    60
    61end Lax117284.BipartiteKuhnCorrect
    62
    Show ProofShow ProofShow ProofShow Proof
    Formalization Notes

    The first two statements are about the relation the algorithm works on; the third is about the graph, in Mathlib's terms: for a graph on FinVFin V split at nn, the relation between FinnFin n and Fin(V−n)Fin (V - n) is adjacency across the split, and a matching of the graph is the same thing as an injective assignment of left neighbours to right vertices, edge for edge.

    The proof does not use Berge's lemma. A search from l0l₀ fails only when every right vertex reachable from l0l₀ by alternating exploration is already matched, and the left vertices so reached then outnumber the right vertices so reached by exactly one. This state is stable: a later augmentation from another free vertex keeps the reached left vertices matched, hence into the same set of right neighbours, which it therefore saturates again, so that l0l₀ reaches nothing new and stays failed. At the end the failed left vertices FF and the set SS of all left vertices reachable from them have ∣N(S)∣=∣S∣−∣F∣|N(S)| = |S| - |F|, and any matching matches at most ∣N(S)∣|N(S)| vertices of SS, so it has at most ∣L∣−∣F∣|L| - |F| edges — which is the size of the matching returned, since every left vertex outside FF is matched.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…