AFTD Auto-Formalizing Theoretical Domains

MatchingMarket.ofEquivData

defimported Lean

Build a MatchingMarket (Fin n) (Fin n) from list-based preference data. some j ≻ some k iff j appears earlier in the list; none is worst. Side transposition (read carefully). ofEquivData a b puts a on the market's MEN (prefM) and b on the market's WOMEN (prefW). Hence when it is applied as ofEquivData w m with the algorithm's w (women's / choosing preferences) and m (men's / proposing preferences), the market's "men" are the algorithm's *women* and the market's "women" are the algorithm's *men* — the two sides are transposed. Stability is symmetric, so this is harmless, but be aware that a market-M index corresponds to an algorithm woman (and vice versa); the stability proof reasons in the algorithm frame.

Statement

set_option autoImplicit true in
set_option relaxedAutoImplicit true in
open List Finset in
open GS in
variable {n : ℕ} [NeZero n] in
noncomputable def MatchingMarket.ofEquivData (wPrefs mPrefs : GS.Preferences n) :
    MatchingMarket (Fin n) (Fin n)
Defined in
EconCSLib, `MatchingMarket.ofEquivData`
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.
Verified
08 Oct 2026
Axioms
none listed
Built on 5
  • IsPreferenceA weak preference relation is admissible if it is reflexive, transitive, and total.
  • instCoeFunPrefForallForallPropinstCoeFunPrefForallForallProp
  • GS.PreferencesList-based preferences: prefs i is a full permutation of Fin n, ordered from most to least preferred.
  • MatchingMarketA two-sided matching market. M and W are the two sides (e.g., men and women, hospitals and residents). Each agent has a preference…
  • PrefA bundled weak preference relation. Use this interface when several agents may rank the same outcome type differently. Use…
Used by 54

Lean source view module on GitHub

set_option autoImplicit true in
set_option relaxedAutoImplicit true in
open List Finset in
open GS in
variable {n : ℕ} [NeZero n] in
/-- Build a `MatchingMarket (Fin n) (Fin n)` from list-based preference data. `some j ≻ some k` iff `j` appears earlier in the list; `none` is worst. **Side transposition (read carefully).** `ofEquivData a b` puts `a` on the market's MEN (`prefM`) and `b` on the market's WOMEN (`prefW`). Hence when it is applied as `ofEquivData w m` with the algorithm's `w` (women's / choosing preferences) and `m` (men's / proposing preferences), the market's "men" are the algorithm's *women* and the market's "women" are the algorithm's *men* — the two sides are **transposed**. Stability is symmetric, so this is harmless, but be aware that a market-`M` index corresponds to an algorithm woman (and vice versa); the stability proof reasons in the algorithm frame. -/
noncomputable def MatchingMarket.ofEquivData (wPrefs mPrefs : GS.Preferences n) :
    MatchingMarket (Fin n) (Fin n) where
  prefM := fun i =>
    { rel := fun ow1 ow2 =>
        match ow1, ow2 with
        | none,    none    => True
        | none,    some _  => False
        | some _,  none    => True
        | some w1, some w2 => (wPrefs.prefs i).idxOf w1 ≤ (wPrefs.prefs i).idxOf w2
      prop :=
        { reflexive := by intro ow; cases ow <;> simp
          transitive := by
            intro ow1 ow2 ow3 h12 h23
            cases ow1 <;> cases ow2 <;> cases ow3 <;> simp_all
            exact Nat.le_trans h12 h23
          total := by
            intro ow1 ow2; cases ow1 <;> cases ow2 <;> simp
            exact Nat.le_or_le _ _ } }
  prefW := fun j =>
    { rel := fun om1 om2 =>
        match om1, om2 with
        | none,    none    => True
        | none,    some _  => False
        | some _,  none    => True
        | some m1, some m2 => (mPrefs.prefs j).idxOf m1 ≤ (mPrefs.prefs j).idxOf m2
      prop :=
        { reflexive := by intro om; cases om <;> simp
          transitive := by
            intro om1 om2 om3 h12 h23
            cases om1 <;> cases om2 <;> cases om3 <;> simp_all
            exact Nat.le_trans h12 h23
          total := by
            intro om1 om2; cases om1 <;> cases om2 <;> simp
            exact Nat.le_or_le _ _ } }
See it in the graphDiscuss this resultChallenge it