Documentation

CslibFrontier.Algorithms.Lean.StableMatching.DeferredAcceptance

Gale–Shapley deferred acceptance #

This module implements proposer-proposing deferred acceptance [GS62] as a total, computable Lean function on Instance n, and proves that it terminates within the classical proposal bound, that its output is stable, and that it is proposer-optimal.

We use the iterative formulation in which one rejection happens at a time; McVitie and Wilson [McVW71] showed that the outcome does not depend on the order of rejections. A state records, for each proposer p, how many receivers have turned p down; p currently proposes to its next choice. While some receiver receives proposals from two proposers, it turns down the one it likes less, which moves on to its next choice. The step function always turns down the first outranked proposer in index order, so deferredAcceptance is a definite function that decide evaluates on concrete instances. The proofs use only step_cases and the invariant Inv, so they adapt to any rejection order; order independence is not stated as a theorem here.

Main definitions #

Main results #

Cost model #

proposals counts proposals, the standard cost measure for deferred acceptance. This module does not charge the cost of finding an outranked proposer or of the surrounding bookkeeping on any machine model.

References #

@[reducible, inline]

A deferred-acceptance state: s p is the number of receivers that have turned proposer p down so far. Proposer p currently proposes to its choice of rank s p.

The receiver proposer p currently proposes to: its choice of rank s p (clamped to the last rank, which reachable states never exceed).

Proposer p is outranked when its current receiver also receives a proposal from someone it strictly prefers to p.

Instances For
    @[instance_reducible]

    One step of deferred acceptance: the first outranked proposer is turned down and moves on to its next choice. A state with no outranked proposer is fixed.

    The state after k steps, starting with every proposer at its first choice.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.step_cases {n : ℕ} (I : Instance n) (s : State n) :
    (I.step s = s ∧ ∀ (p : Fin n), ¬I.Outranked s p) ∨ ∃ (p : Fin n), I.Outranked s p ∧ I.step s = Function.update s p (s p + 1)

    A step either fixes a state with no outranked proposer or turns down one outranked proposer.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.target_of_lt {n : ℕ} (I : Instance n) {s : State n} {p : Fin n} (h : s p < n) :
    I.target s p = (I.propPref p) ⟨s p, h⟩

    Within the list, target is the choice of rank s p.

    The deferred-acceptance invariant: every proposer is within its list; whenever proposer p has been turned down by its choice of rank k, that receiver currently receives a proposal from someone it prefers to p; and at most one proposer has reached its last choice.

    • lt (p : Fin n) : s p < n

      Every proposer is within its list.

    • rejected (p k : Fin n) : ↑k < s p → ∃ (q : Fin n), I.target s q = (I.propPref p) k ∧ I.RecvPrefers ((I.propPref p) k) q p

      A receiver that turned p down currently holds a proposal it prefers to p.

    • last_unique (p q : Fin n) : s p + 1 = n → s q + 1 = n → p = q

      At most one proposer has reached its last choice.

    The initial state satisfies the invariant.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.inv_step {n : ℕ} (I : Instance n) {s : State n} (hs : I.Inv s) :
    I.Inv (I.step s)

    Steps preserve the invariant.

    Every state of the run satisfies the invariant.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.sum_le {n : ℕ} (I : Instance n) {s : State n} (hs : I.Inv s) :
    ∑ p : Fin n, s p ≤ (n - 1) ^ 2

    The total number of rejections in an invariant state is at most (n - 1)^2.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.run_fixed_of_le {n : ℕ} (I : Instance n) {j k : ℕ} (hjk : j ≤ k) (h : I.step (I.run j) = I.run j) :
    I.run k = I.run j

    Once the run reaches a fixed state, it stays there.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.step_run_fixed {n : ℕ} (I : Instance n) :
    I.step (I.run ((n - 1) ^ 2)) = I.run ((n - 1) ^ 2)

    Deferred acceptance stops after at most (n - 1)^2 rejections.

    The state reached by deferred acceptance.

    The final state satisfies the invariant.

    One more round of the run is one more step.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.run_le_run_succ {n : ℕ} (I : Instance n) (k : ℕ) (p : Fin n) :
    I.run k p ≤ I.run (k + 1) p

    Rejection counts never decrease along the run.

    theorem Cslib.Algorithms.Lean.StableMatching.Instance.run_mono {n : ℕ} (I : Instance n) {j k : ℕ} (hjk : j ≤ k) (p : Fin n) :
    I.run j p ≤ I.run k p

    Rejection counts are monotone in the number of rounds.

    After (n - 1) ^ 2 rounds the run has reached the final state.

    Every intermediate rejection count is bounded by the final one.

    No proposer is outranked in the final state.

    The proposer-proposing deferred-acceptance matching.

    Proposer p is matched to the receiver it proposes to in the final state.

    Proposer p ends at its choice of rank finalState p.

    Deferred acceptance outputs a stable matching ([GS62], Theorem 1).

    Proposer-optimality ([GS62], Theorem 2): every proposer weakly prefers its deferred-acceptance partner to its partner in any stable matching.

    The number of proposals made by deferred acceptance: proposer p proposed to its first finalState p + 1 choices.

    The number of proposals depends only on the output: proposer p proposed to every receiver that it ranks no lower than its final partner.

    Deferred acceptance makes at most n^2 - n + 1 proposals (see [GI89]).

    Deferred acceptance is the proposer-optimal stable matching.

    Every market has a stable matching ([GS62], Theorem 1).

    Every market has a (unique) proposer-optimal stable matching.

    Receiver-proposing deferred acceptance: run deferred acceptance on the swapped market.