GS.galeShapley_isProposingOptimal
theoremverifiedformalizationimported Lean
Men-optimal stable matching (Gale–Shapley 1962, [MSZ 22.10]): in the men-proposing DA, every man's GS partner is at least as preferred (by him) as his partner under *any* other stable matching μ. Equivalently: for any stable μ pairing man j with woman wj, the GS output's matching of j is ranked at most as high (i.e., as good or better) as wj in m.prefs j.
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in open GS in open GS in variable {n : ℕ} [NeZero n] in variable (w m : Preferences n) in theorem GS.galeShapley_isProposingOptimal (μ : Matching (Fin n) (Fin n)) (hμ : Matching.IsStable (MatchingMarket.ofEquivData w m) μ) : ∀ (j wj : Fin n), μ.matchW j = some wj → (m.prefs j).idxOf ((Equiv.ofBijective (gs w m) (gs_bijective w m)).symm j) ≤ (m.prefs j).idxOf wj
- Formalizes
- EconCSLib, `GS.galeShapley_isProposingOptimal`
- Lean proof
- By xbei (from the file's git history), from github.com/gametheoryinlean/EconCSLib at
1a88f809b538(Copyright (c) 2026 EconCSLib contributors. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.30.0.GS.galeShapley_isProposingOptimal← GS.galeShapley_isProposingOptimal (EconCSLib/MarketDesign/Matching/Optimal.lean:318): verbatim
- Verified
- 08 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 15
- GS.finalState_NoAchievableRejectionThe invariant holds at
finalState. - final_holding_injective
finalStateholding is injective. - final_all_women_holdAt termination, every woman holds some man.
- holdinv_finalStateholdinv_finalState
- gs_bijective
gs w mis a bijection onFin n. - GS.PreferencesList-based preferences:
prefs iis a full permutation ofFin n, ordered from most to least preferred. - GS.gsThe Gale-Shapley function: woman
j's partner at termination. - GS.DAStateDA state: per-man proposal cursor + per-woman tentative hold.
- GS.finalState
finalState: rundaRunwith fueln*n + 1frominitState. - MatchingA matching is a partial bijection between
MandW.matchM iis the partner ofi ∈ M(ornoneif unmatched).matchW jis the… - Matching.IsStableA matching is stable if it has no blocking pair. [MSZ 22.5]
- MatchingMarket.ofEquivDataBuild a
MatchingMarket (Fin n) (Fin n)from list-based preference data.some j ≻ some kiffjappears earlier in the list;noneis… - GS.IsAchievable
IsAchievable w m j wjsays womanwjis achievable for manj: some stable matching pairs them. Recall the codebase convention… - GS.pref_list_memEvery element of
Fin nappears in a full-permutation list. - instCoeFunPrefForallForallPropinstCoeFunPrefForallForallProp
- GS.finalState_NoAchievableRejectionThe invariant holds at
- Used by 1
- GS.StableMatching.gsStable_greatestThe GS output is the greatest stable matching in the men-preference order: every man weakly prefers his GS partner to his partner in…
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
set_option autoImplicit true inset_option relaxedAutoImplicit true inopen GS inopen GS invariable {n : ℕ} [NeZero n] invariable (w m : Preferences n) in/-- **Men-optimal stable matching** (Gale–Shapley 1962, [MSZ 22.10]): in the men-proposing DA, every man's GS partner is at least as preferred (by him) as his partner under *any* other stable matching `μ`. Equivalently: for any stable `μ` pairing man `j` with woman `wj`, the GS output's matching of `j` is ranked at most as high (i.e., as good or better) as `wj` in `m.prefs j`. -/theorem GS.galeShapley_isProposingOptimal (μ : Matching (Fin n) (Fin n)) (hμ : Matching.IsStable (MatchingMarket.ofEquivData w m) μ) : ∀ (j wj : Fin n), μ.matchW j = some wj → (m.prefs j).idxOf ((Equiv.ofBijective (gs w m) (gs_bijective w m)).symm j) ≤ (m.prefs j).idxOf wj := by intro j wj hwj -- `(j, wj)` is achievable via `μ`. have hach : IsAchievable w m j wj := ⟨μ, hμ, hwj⟩ -- Let `wjs` be j's GS partner. set wjs : Fin n := (Equiv.ofBijective (gs w m) (gs_bijective w m)).symm j with wjs_def -- Step 1. `wjs` holds `j` in `finalState`. have hwjs_apply : gs w m wjs = j := (Equiv.ofBijective (gs w m) (gs_bijective w m)).apply_symm_apply j have hwjs_holds : (finalState w m).holding wjs = some j := by obtain ⟨h, hh⟩ := final_all_women_hold w m wjs have hgs_h : gs w m wjs = h := by simp [gs, hh] rw [hgs_h] at hwjs_apply exact hwjs_apply ▸ hh -- Step 2. By `HoldInv` at `finalState`, `idxOf wjs < nextChoice j`. have hwjs_lt : (m.prefs j).idxOf wjs < (finalState w m).nextChoice j := (List.mem_take_iff_idxOf_lt (pref_list_mem _ (m.valid j).1 (m.valid j).2 _)).mp (holdinv_finalState w m j wjs hwjs_holds) -- Step 3. Case-split on whether `wj` lies inside j's proposed-prefix. by_cases hwj_lt : (m.prefs j).idxOf wj < (finalState w m).nextChoice j · -- `wj` was proposed to. By the invariant, `wj` must currently hold `j`. have hwj_holds : (finalState w m).holding wj = some j := finalState_NoAchievableRejection w m j wj hach hwj_lt -- Both `wjs` and `wj` hold `j` — by injectivity, they're equal. have hwj_eq_wjs : wj = wjs := final_holding_injective w m wj wjs j hwj_holds hwjs_holds rw [hwj_eq_wjs] · -- `wj` was not proposed to: `nextChoice j ≤ idxOf wj`. push_neg at hwj_lt omega