Hall's Marriage Theorem

lean4-proofgraph-theoryvisualization
SX,  SN(S)     perfect matching\forall S \subseteq X,\; |S| \le |N(S)| \iff \exists \text{ perfect matching}

Statement

Let G=(XY,E)G = (X \cup Y, E) be a bipartite graph. There exists an injection f:XYf: X \to Y that is a matching (each xXx \in X is matched to a distinct neighbor f(x)f(x)) if and only if Hall's condition holds:

SX,SN(S)\forall S \subseteq X,\quad |S| \le |N(S)|

where N(S)={yY:xS, {x,y}E}N(S) = \{y \in Y : \exists x \in S,\ \{x,y\} \in E\} is the neighborhood of SS.

Visualization

Bipartite graph X={a,b,c}X = \{a,b,c\}, Y={1,2,3}Y = \{1,2,3\} with N(a)={1,2}N(a)=\{1,2\}, N(b)={2}N(b)=\{2\}, N(c)={1}N(c)=\{1\}:

X side    Y side
  a ─────── 1
  a ─────── 2
  b ─────── 2
  c ─────── 1

Check Hall's condition for all subsets of XX:

| Subset SS | S|S| | N(S)N(S) | N(S)|N(S)| | Hall? | |-----------|-------|---------|----------|-------| | {a}\{a\} | 1 | {1,2}\{1,2\} | 2 | ok | | {b}\{b\} | 1 | {2}\{2\} | 1 | ok | | {c}\{c\} | 1 | {1}\{1\} | 1 | ok | | {a,b}\{a,b\} | 2 | {1,2}\{1,2\} | 2 | ok | | {a,c}\{a,c\} | 2 | {1,2}\{1,2\} | 2 | ok | | {b,c}\{b,c\} | 2 | {1,2}\{1,2\} | 2 | ok | | {a,b,c}\{a,b,c\} | 3 | {1,2}\{1,2\} | 2 | FAIL |

Hall's condition fails for S={a,b,c}S = \{a,b,c\}: {1,2}=2<3|\{1,2\}| = 2 < 3. No perfect matching exists. Indeed bb and cc both compete for vertex 2 or 1, so one of {b,c}\{b, c\} is unmatched.

For a success example: adding edge cc33 gives N({a,b,c})={1,2,3}N(\{a,b,c\}) = \{1,2,3\} and a perfect matching a2,b2a \mapsto 2, b \mapsto 2 ... no, a1,b2,c3a \mapsto 1, b \mapsto 2, c \mapsto 3.

Proof Sketch

  1. (Necessity) If a matching ff exists, then for any SXS \subseteq X the images f(S)N(S)f(S) \subseteq N(S) are distinct, so SN(S)|S| \le |N(S)|.
  2. (Sufficiency by induction on X|X|) Base: X=0|X|=0 trivial. Inductive step has two cases:
    • Tight case: every proper SXS \subsetneq X satisfies N(S)>S|N(S)| > |S|. Pick any xXx \in X, match it to any yN(x)y \in N(x), remove both, verify Hall's condition still holds for the remainder.
    • Non-tight case: there exists SXS \subsetneq X with N(S)=S|N(S)| = |S|. Recurse on SS to get a matching; the subgraph on XSX \setminus S still satisfies Hall's condition by the tight-case argument on the residual.
  3. In both cases an injection XYX \to Y is constructed, completing the induction.

Connections

Hall's theorem is the combinatorial core underlying the König's Theorem (Bipartite)König's Theorem (Bipartite)ν(G)=τ(G) for bipartite G\nu(G) = \tau(G) \text{ for bipartite } GIn any bipartite graph, the size of a maximum matching equals the size of a minimum vertex cover.Read more → min-cover/max-matching duality. It is also used in the proof of the Dilworth's TheoremDilworth's Theoremwidth(P)=min{k:P=C1Ck}\text{width}(P) = \min\{k : P = C_1 \cup \cdots \cup C_k\}In any finite partially ordered set, the minimum number of chains needed to cover the poset equals the maximum size of an antichain.Read more → via Mirsky's dual. The injection it guarantees connects to Inclusion–Exclusion Principle counting arguments and Pigeonhole PrinciplePigeonhole Principlef1({y})2  for some  yB  when  A>B|f^{-1}(\{y\})| \geq 2 \;\text{for some}\; y \in B \;\text{when}\; |A| > |B|If n+1 objects are placed into n boxes, some box contains at least two objectsRead more → obstructions.

Lean4 Proof

import Mathlib.Combinatorics.Hall.Basic

/-- Hall's Marriage Theorem: a system of finite sets admits an injective
    choice function iff Hall's condition holds for every finite subfamily.
    Mathlib: `Finset.all_card_le_biUnion_card_iff_exists_injective`. -/
theorem halls_marriage {ι α : Type*} [Fintype ι] [DecidableEq α]
    (t : ι  Finset α) :
    ( s : Finset ι, s.card  (s.biUnion t).card) 
     f : ι  α, Function.Injective f   x, f x  t x :=
  Finset.all_card_le_biUnion_card_iff_exists_injective t