Three-sided delivery markets with up-front tips
DefinitionPricingWithTips_ModelA finite three-sided delivery-market model with buyers, stores, and couriers. It defines feasible allocations, welfare, equilibria with and without up-front buyer tips, the endogenous minimum acceptable tip, maximal courier utilities, adjusted buyer–store values, maximum-weight matchings, the two structured cost decompositions used in Theorem 5.2, and a non-vacuous formulation of arbitrarily poor welfare in without-tip equilibria.
import Mathlib
open scoped BigOperators
namespace PricingWithTips
variable {B S D : Type*} [Fintype B] [Fintype S] [Fintype D]
[DecidableEq B] [DecidableEq S] [DecidableEq D]
/-- A finite three-sided delivery market. Store production costs and product prices
are normalized to zero, as in Section 2 of the paper. -/
structure Market (B S D : Type*) where
value : B → S → ℝ
cost : D → B → S → ℝ
value_nonneg : ∀ b s, 0 ≤ value b s
cost_nonneg : ∀ d b s, 0 ≤ cost d b s
/-- A feasible three-sided allocation: each buyer receives at most one
store-courier pair, and no store or courier is used twice. -/
structure Allocation (B S D : Type*) where
assigned : B → Option (S × D)
store_unique : ∀ ⦃b₁ b₂ s d₁ d₂⦄,
assigned b₁ = some (s, d₁) → assigned b₂ = some (s, d₂) → b₁ = b₂
courier_unique : ∀ ⦃b₁ b₂ s₁ s₂ d⦄,
assigned b₁ = some (s₁, d) → assigned b₂ = some (s₂, d) → b₁ = b₂
def Allocation.Trades (A : Allocation B S D) (b : B) (s : S) (d : D) : Prop :=
A.assigned b = some (s, d)
def Allocation.Delivers (A : Allocation B S D) (b : B) (s : S) : Prop :=
∃ d, A.Trades b s d
def Allocation.Sells (A : Allocation B S D) (s : S) : Prop :=
∃ b d, A.Trades b s d
def Allocation.CourierWorks (A : Allocation B S D) (d : D) : Prop :=
∃ b s, A.Trades b s d
noncomputable def welfare (M : Market B S D) (A : Allocation B S D) : ℝ :=
∑ b, match A.assigned b with
| none => 0
| some (s, d) => M.value b s - M.cost d b s
def IsWelfareOptimal (M : Market B S D) (A : Allocation B S D) : Prop :=
∀ A' : Allocation B S D, welfare M A' ≤ welfare M A
def counterfactualTip (t : B → S → ℝ) (b : B) (s : S) (τ : ℝ)
(b' : B) (s' : S) : ℝ :=
if b' = b then if s' = s then τ else 0 else t b' s'
/-- Courier `d` would weakly prefer order `(b,s)` to idling and to every
other order if buyer `b` offered counterfactual tip `τ`, while her tips at
other stores are zero and all other buyers' tips stay fixed. -/
def CourierAccepts (M : Market B S D) (w t : B → S → ℝ)
(b : B) (s : S) (τ : ℝ) (d : D) : Prop :=
0 ≤ w b s + τ - M.cost d b s ∧
∀ b' s',
w b' s' + counterfactualTip t b s τ b' s' - M.cost d b' s' ≤
w b s + τ - M.cost d b s
/-- Definition 2.2's minimum tip: the infimum of nonnegative tips that make
at least one courier willing to deliver the selected order. -/
noncomputable def minimumTip (M : Market B S D) (w t : B → S → ℝ)
(b : B) (s : S) : ℝ :=
sInf {τ : ℝ | 0 ≤ τ ∧ ∃ d, CourierAccepts M w t b s τ d}
/-- Appendix A's closed-form expression for the minimum tip. -/
noncomputable def minimumTipFormula (M : Market B S D) (w t : B → S → ℝ)
(b : B) (s : S) : ℝ :=
⨅ d, max 0 (max (M.cost d b s - w b s)
(⨆ (b' : B) (s' : S), if (b', s') = (b, s) then 0 else
w b' s' + (if b' = b then 0 else t b' s') - M.cost d b' s' - w b s + M.cost d b s))
def courierUtility (M : Market B S D) (w t : B → S → ℝ)
(d : D) (b : B) (s : S) : ℝ :=
w b s + t b s - M.cost d b s
def IsWithoutTipEquilibrium (M : Market B S D) (A : Allocation B S D)
(p : S → ℝ) (w : B → S → ℝ) : Prop :=
(∀ s, 0 ≤ p s) ∧ (∀ b s, 0 ≤ w b s) ∧
(∀ b,
match A.assigned b with
| none => ∀ s, M.value b s - p s ≤ 0
| some (s, _) =>
0 ≤ M.value b s - p s ∧
∀ s', M.value b s' - p s' ≤ M.value b s - p s) ∧
(∀ d b s, A.Trades b s d →
0 ≤ w b s - M.cost d b s ∧
∀ b' s', w b' s' - M.cost d b' s' ≤ w b s - M.cost d b s) ∧
(∀ d, ¬ A.CourierWorks d → ∀ b s, w b s - M.cost d b s ≤ 0) ∧
(∀ s, ¬ A.Sells s → p s = 0) ∧
(∀ b s, ¬ A.Delivers b s → w b s = 0)
def IsWithTipEquilibrium (M : Market B S D) (A : Allocation B S D)
(p : S → ℝ) (w t : B → S → ℝ) : Prop :=
(∀ s, 0 ≤ p s) ∧ (∀ b s, 0 ≤ w b s) ∧ (∀ b s, 0 ≤ t b s) ∧
(∀ b,
match A.assigned b with
| none => ∀ s, M.value b s - p s - minimumTip M w t b s ≤ 0
| some (s, _) =>
t b s = minimumTip M w t b s ∧
0 ≤ M.value b s - p s - minimumTip M w t b s ∧
∀ s', M.value b s' - p s' - minimumTip M w t b s' ≤
M.value b s - p s - minimumTip M w t b s) ∧
(∀ d b s, A.Trades b s d →
0 ≤ courierUtility M w t d b s ∧
∀ b' s', courierUtility M w t d b' s' ≤ courierUtility M w t d b s) ∧
(∀ d, ¬ A.CourierWorks d → ∀ b s, courierUtility M w t d b s ≤ 0) ∧
(∀ s, ¬ A.Sells s → p s = 0) ∧
(∀ b s, ¬ A.Delivers b s → w b s = 0 ∧ t b s = 0)
def HasWithTipEquilibriumAt (M : Market B S D) (A : Allocation B S D) : Prop :=
∃ p w t, IsWithTipEquilibrium M A p w t
def IsCourierPlanFor (M : Market B S D) (A : Allocation B S D)
(w : B → S → ℝ) : Prop :=
(∀ b s, 0 ≤ w b s) ∧
(∀ d b s, A.Trades b s d →
0 ≤ w b s - M.cost d b s ∧
∀ b' s', w b' s' - M.cost d b' s' ≤ w b s - M.cost d b s) ∧
(∀ d, ¬ A.CourierWorks d → ∀ b s, w b s - M.cost d b s ≤ 0) ∧
(∀ b s, ¬ A.Delivers b s → w b s = 0)
noncomputable def courierRealizedUtility (M : Market B S D) (A : Allocation B S D)
(w : B → S → ℝ) (d : D) : ℝ := by
classical
exact if h : ∃ b s, A.Trades b s d then
let b := Classical.choose h
let hs := Classical.choose_spec h
let s := Classical.choose hs
w b s - M.cost d b s
else 0
def IsMaximalCourierUtility (M : Market B S D) (A : Allocation B S D)
(uBar : D → ℝ) : Prop :=
(∃ w, IsCourierPlanFor M A w ∧ ∀ d, courierRealizedUtility M A w d = uBar d) ∧
∀ w, IsCourierPlanFor M A w → ∀ d, courierRealizedUtility M A w d ≤ uBar d
noncomputable def requiredTip (M : Market B S D) (A : Allocation B S D)
(uBar : D → ℝ) (b : B) (s : S) : ℝ := by
classical
exact if A.Delivers b s then 0 else ⨅ d, M.cost d b s + uBar d
noncomputable def adjustedValue (M : Market B S D) (A : Allocation B S D)
(uBar : D → ℝ) (b : B) (s : S) : ℝ :=
M.value b s - requiredTip M A uBar b s
structure BuyerMatching (B S : Type*) where
assigned : B → Option S
store_unique : ∀ ⦃b₁ b₂ s⦄, assigned b₁ = some s → assigned b₂ = some s → b₁ = b₂
def Allocation.toBuyerMatching (A : Allocation B S D) : BuyerMatching B S where
assigned := fun b => (A.assigned b).map Prod.fst
store_unique := by
intro b₁ b₂ s h₁ h₂
simp only [Option.map_eq_some_iff] at h₁ h₂
obtain ⟨x₁, hx₁, rfl⟩ := h₁
obtain ⟨x₂, hx₂, hfst⟩ := h₂
cases x₁ with
| mk s₁ d₁ =>
cases x₂ with
| mk s₂ d₂ =>
simp only at hfst
subst s₂
exact A.store_unique hx₁ hx₂
noncomputable def matchingWeight (z : BuyerMatching B S) (q : B → S → ℝ) : ℝ :=
∑ b, match z.assigned b with | none => 0 | some s => q b s
def IsMaximumWeight (z : BuyerMatching B S) (q : B → S → ℝ) : Prop :=
∀ z' : BuyerMatching B S, matchingWeight z' q ≤ matchingWeight z q
def CourierStoreDecomposable (M : Market B S D) : Prop :=
∃ cBS : B → S → ℝ, ∃ cDS : D → S → ℝ,
∀ d b s, M.cost d b s = cBS b s + cDS d s
def CourierBuyerDecomposable (M : Market B S D) : Prop :=
∃ cBS : B → S → ℝ, ∃ cDB : D → B → ℝ,
∀ d b s, M.cost d b s = cBS b s + cDB d b
/-- A non-vacuous formulation of the paper's “arbitrarily low” clause:
for every loss threshold there is a finite structured market with at least one
without-tip equilibrium, positive optimal welfare, and every such equilibrium
has welfare at most the negative threshold. -/
def ArbitrarilyLowWithoutTipWelfare : Prop :=
∀ K : ℝ, 0 < K →
∃ M : Market (Fin 2) (Fin 1) (Fin 2),
(CourierStoreDecomposable M ∨ CourierBuyerDecomposable M) ∧
(∃ A : Allocation (Fin 2) (Fin 1) (Fin 2),
IsWelfareOptimal M A ∧ 0 < welfare M A) ∧
(∃ A p w, IsWithoutTipEquilibrium M A p w) ∧
∀ A p w, IsWithoutTipEquilibrium M A p w → welfare M A ≤ -K
end PricingWithTips
Read-back
What the Lean code literally says, in plain math · gpt-6.1-sol
Market. For arbitrary types of buyers , stores , and couriers , a market consists of a real value for every buyer–store pair and a real cost for every courier–buyer–store triple, together with the requirements and for every , , and .
Allocation. For arbitrary types , an allocation assigns to each buyer either no pair or a store–courier pair. It must satisfy two injectivity conditions: if buyers are assigned pairs whose store component is the same store , then , regardless of the two couriers; and if they are assigned pairs whose courier component is the same courier , then , regardless of the two stores. Thus each buyer has at most one assigned pair by construction, while no store and no courier can occur in the assignments of two distinct buyers; the types themselves may be empty.
Allocation.Trades. For an allocation , buyer , store , and courier , the proposition that trades means exactly that 's assignment for is the pair .
Allocation.Delivers. For an allocation , buyer , and store , delivers exactly when there exists a courier such that assigns to .
Allocation.Sells. For an allocation and store , says that sells exactly when there exist a buyer and courier such that assigns to .
Allocation.CourierWorks. For an allocation and courier , says that works exactly when there exist a buyer and store such that assigns to .
welfare. Given a market , an allocation , and a finite buyer type , the welfare is the sum over every buyer of if is unassigned, and if is assigned . No separate store-side or courier-side terms are included. If is empty, the sum is .
IsWelfareOptimal. Given a market , an allocation , and a finite buyer type, is welfare-optimal exactly when every allocation on the same buyer, store, and courier types satisfies .
counterfactualTip. Given a tip table , a selected buyer , selected store , proposed tip , and another pair , with decidable equality on buyers and stores, the counterfactual tip is when and , is when but , and is the original tip when . In particular, changing buyer 's tip at also sets that buyer’s tips at every other store to zero, while tips of all other buyers remain unchanged.
CourierAccepts. Given a market , real tables , a selected pair , a real proposed tip , and a courier , with decidable equality on buyers and stores, accepts exactly when and, for every buyer and store , , where at , for , and for . Both conditions are weak inequalities, and the comparison includes the selected pair itself.
minimumTip. Given , with decidable equality on buyers and stores, the minimum tip is the real infimum of the set of all such that and there exists at least one courier satisfying CourierAccepts for . This is an infimum, not an assertion that a least qualifying tip exists or belongs to the set; if no courier exists or no tip qualifies, the real-number infimum operation is still a totalized definition supplied by the library.
minimumTipFormula. Given , with decidable equality on buyers and stores, the formula is , where if , and otherwise when , while when . The outer operation is an infimum over all couriers and the inner operation a supremum over all buyer–store pairs; no theorem here states that this expression equals minimumTip, and the indexed infimum and supremum remain totalized library operations even for empty or otherwise degenerate index types.
courierUtility. Given , courier , buyer , and store , the courier utility assigned to that triple is .
IsWithoutTipEquilibrium. Given a market , allocation , store-price table , and payment table , the predicate holds exactly when all of the following are true: every and is nonnegative; each unassigned buyer has for every store, while each buyer assigned some has and for every store ; whenever assigns to , one has and for every ; every courier unused by satisfies for every ; every store unused by has price ; and every buyer–store pair not delivered by has . These universal clauses include all elements of the possibly empty underlying types.
IsWithTipEquilibrium. Given , with decidable equality on buyers and stores, the predicate holds exactly when every is nonnegative; each unassigned buyer satisfies for every store; each buyer assigned satisfies , , and, for every store , ; every assigned triple gives courier utility and at least as large as for every ; every unused courier has for every ; every unused store has price ; and every undelivered buyer–store pair has both and .
HasWithTipEquilibriumAt. Given a market and allocation , with decidable equality on buyers and stores, the predicate holds exactly when there exist a real store-price table , a real payment table , and a real tip table for which IsWithTipEquilibrium holds at .
IsCourierPlanFor. Given , and , is a courier plan exactly when every ; every assigned triple satisfies and for all ; every courier unused by satisfies for all ; and every buyer–store pair not delivered by has .
courierRealizedUtility. Given and courier , the realized utility is if there are no with assigning to ; otherwise, classical choice selects witnesses of such an assignment and the value is . The definition itself uses the chosen witnesses, although the allocation’s uniqueness conditions ensure that any working courier can occur in only one buyer’s assignment, and that buyer’s single assignment fixes the store as well.
IsMaximalCourierUtility. Given and a proposed utility vector , the predicate holds exactly when, first, there exists at least one payment table that is a courier plan for and whose realized utility for every courier equals , and, second, every courier plan satisfies for every courier . Thus the same vector is required both to be attained simultaneously by one plan and to bound every courier’s realized utility under every plan.
requiredTip. Given , the required tip is if delivers buyer from store , and otherwise is . The infimum is over every courier, whether or not that courier works in , and remains a totalized real-number operation if is empty.
adjustedValue. Given , the adjusted value is .
BuyerMatching. For arbitrary buyer and store types , a buyer matching assigns each buyer either no store or one store and requires that if two buyers are assigned the same store, then the buyers are equal. Thus no store is assigned to two distinct buyers; either type may be empty.
Allocation.toBuyerMatching. Given a three-sided allocation , its buyer matching assigns buyer no store when leaves unassigned and assigns the store when assigns a pair , discarding the courier component. The required uniqueness of stores follows from the allocation’s store-uniqueness condition.
matchingWeight. Given a buyer matching , a real weight table , and a finite buyer type , the matching weight is the sum over buyers of for each unassigned buyer and for each buyer assigned store . If is empty, this sum is .
IsMaximumWeight. Given a buyer matching , a real weight table , and a finite buyer type, has maximum weight exactly when every buyer matching on the same buyer and store types satisfies .
CourierStoreDecomposable. A market is courier–store decomposable exactly when there exist real tables and such that, for every courier , buyer , and store , . No nonnegativity requirement is imposed separately on either component table.
CourierBuyerDecomposable. A market is courier–buyer decomposable exactly when there exist real tables and such that, for every courier , buyer , and store , . No nonnegativity requirement is imposed separately on either component table.
ArbitrarilyLowWithoutTipWelfare. The proposition says that for every real , there exists a market with exactly two buyers, one store, and two couriers such that: 's cost table is either courier–store decomposable or courier–buyer decomposable; there exists an allocation that is welfare-optimal among all allocations for that market and has strictly positive welfare; there exists at least one allocation , nonnegative store-price table , and nonnegative payment table satisfying all clauses of IsWithoutTipEquilibrium; and every allocation and every tables satisfying IsWithoutTipEquilibrium have . The positive-welfare optimal allocation need not be an equilibrium, while the existential equilibrium is covered by the final universal bound.