Verification.lean

Board Support, CEO (Mis)Reporting, and Scapegoating · December 2, 2026 verification

1import Scapegoating23open Std Lean.Grind Scapegoating4namespace Verification5variable {R : Type} [Field R] [LE R] [LT R] [IsLinearOrder R] [LawfulOrderLT R] [OrderedRing R]67/-- At any positive divisor the field quotient solves the indicated equation. -/8private theorem quotient (a b : R) (hb : 0 < b) : a/b*b=a :=9  Field.div_mul_cancel (by grind)1011/-- A quadratic effort payoff has the stated unique maximizer even allowing12arbitrary real deviations, if its linear coefficient is ψe. -/13theorem quadraticChoice (ψ e c : R) (hψ : 0 < ψ) (hc : c=ψ*e) :14    ∀ v, v ≠ e → 2*c*v-ψ*v*v < 2*c*e-ψ*e*e := by15  intro v hv16  have sq : 0 < (v-e)*(v-e) := by17    by_cases h : e < v18    · exact OrderedRing.mul_pos (by grind) (by grind)19    · have := OrderedRing.mul_pos (a := e-v) (b := e-v) (by grind) (by grind)20      grind21  have := OrderedRing.mul_pos hψ sq22  rw [hc]23  grind2425/-- Index the technology by s≥0, t=s+2. A good type fails with probability262/(3t), a bad type with probability 4/(3t). Both success probabilities27strictly increase and stay in (0,1). p is their equal-weight mixture. -/28theorem technology (s : R) (hs : 0 ≤ s) :29    let f := 1/(s+2)30    let G := 1-(2*f)/331    let B := 1-(4*f)/332    0 < B ∧ B < G ∧ G < 1 ∧ G+B=2*(1-f) ∧ 1 ≤ 2*(1-f) := by33  let f : R := 1/(s+2)34  have one := OrderedRing.zero_lt_one (R := R)35  have eqn : f*(s+2)=1 := quotient 1 _ (by grind)36  have hf : 0 < f := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (show 0 < s+2 by grind)).mp; grind37  have := OrderedRing.mul_nonneg (le_of_lt hf) hs38  have eG := quotient (2*f) 3 (by grind)39  have eB := quotient (4*f) 3 (by grind)40  change 0 < 1-(4*f)/3 ∧ _ < _ ∧ _ < _ ∧ _ = _ ∧ _ ≤ _41  grind4243private theorem denominatorIncreases (s t : R) (hs : 0 ≤ s) (ht : s < t) :44    1/(t+2) < 1/(s+2) := by45  have one := OrderedRing.zero_lt_one (R := R)46  have h1 := quotient (1:R) (s+2) (by grind)47  have h2 := quotient (1:R) (t+2) (by grind)48  have a := congrArg (fun z => z*(t+2)) h149  have b := congrArg (fun z => z*(s+2)) h250  apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (OrderedRing.mul_pos51    (show 0 < s+2 by grind) (show 0 < t+2 by grind))).mp52  grind5354theorem productionIncreasing (s t : R) (hs : 0 ≤ s) (ht : s < t) :55    let gs := 1-(2*(1/(s+2)))/356    let gt := 1-(2*(1/(t+2)))/357    let bs := 1-(4*(1/(s+2)))/358    let bt := 1-(4*(1/(t+2)))/359    gs < gt ∧ bs < bt := by60  have h := denominatorIncreases s t hs ht61  have one := OrderedRing.zero_lt_one (R := R)62  have h1 := quotient (2*(1/(s+2))) 3 (by grind)63  have h2 := quotient (2*(1/(t+2))) 3 (by grind)64  have h3 := quotient (4*(1/(s+2))) 3 (by grind)65  have h4 := quotient (4*(1/(t+2))) 3 (by grind)66  dsimp only; grind6768/-- The same support technology satisfies both operating viability conditions69at X=5, L=2, β=1/2 and every feasible production multiplier a≥1/2. -/70theorem viability (s a : R) (hs : 0 ≤ s) (ha : 1 ≤ 2*a) :71    let p := 1-1/(s+2)72    2 < 5*p ∧ 1 ≤ 2*a*p*(5-2) := by73  obtain ⟨_,_,_,_,hp⟩ := technology s hs74  have one := OrderedRing.zero_lt_one (R := R)75  have := OrderedRing.mul_le_mul_of_nonneg_right ha (c := 1-1/(s+2)) (by grind)76  dsimp only; grind7778/-- Actual market spread at effort e. This is the paper's Bayes formula,79with multiplication by 2 used to write the equal-weight prior and a(e). -/80private theorem spreadAt (β G B p a K r : R)81    (hb : 2*β=1) (hp : 2*p=G+B) (hB : 0 < B) (hBG : B < G) (hG : G < 1)82    (ha : 0 < a) (ha1 : a ≤ 1) (hk : 4*p*K=G-B) (hr : (1-a*p)*r=K) :83    spread β G p a = r := by84  have one := OrderedRing.zero_lt_one (R := R)85  have hmix : mix β G B=p := by unfold mix; grind86  have ⟨_,hw⟩ := bayesCancellation β G B a (by grind) (by grind) hB hBG hG ha ha187  rw [hmix] at hw88  have ⟨_,_,_,hh⟩ := probabilityBounds β G B a (by grind) (by grind) hB hBG hG ha ha189  rw [hmix] at hh90  have hq := quotient (β*(1-β)*(G-B)) p (by grind)91  have hpi := Field.mul_inv_cancel (show p ≠ 0 by grind)92  have hfi := Field.mul_inv_cancel (show 1-a*p ≠ 0 by grind)93  grind9495/-- A truthful effort equilibrium for this fixed contract and m=β=1/2.96The FOC is sufficient on the closed effort interval by quadraticChoice.97The two truthful ICs compare both possible reports after each signal. -/98def TruthfulEffort (ψ β G _B p lo hi e : R) : Prop :=99  let r := spread β G p ((1+e)/2)100  0 ≤ e ∧ e ≤ 1 ∧ Truthful β r lo hi 0 0 ∧101    ∀ v, v ≠ e → p*(hi-lo+r)*v-ψ*v*v < p*(hi-lo+r)*e-ψ*e*e102103private theorem equilibriumOf (ψ β G B p lo hi e r : R)104    (hψ : 0 < ψ) (_hb : 2*β=1) (he : 0 ≤ e ∧ e ≤ 1)105    (hspread : spread β G p ((1+e)/2)=r)106    (hIC : Truthful β r lo hi 0 0) (hfoc : p*(hi-lo+r)=2*ψ*e) :107    TruthfulEffort ψ β G B p lo hi e := by108  unfold TruthfulEffort109  rw [hspread]110  refine ⟨he.1,he.2,hIC,?_⟩111  intro v hv112  have H := quadraticChoice ψ e (ψ*e) hψ rfl v hv113  rw [hfoc]114  grind115116/-- For every ψ≥2, s=96ψ−1 is feasible on the *same* pair of smooth117technology curves. The reduced binding bonus has the same value at an118interior effort and one. Moreover one fixed actual contract has two119truthful-effort equilibria. The high bonus exceeds the operating spread 3. -/120theorem twoEfforts (ψ : R) (hψ : 2 ≤ ψ) :121    let s := 96*ψ-1122    let f := 1/(s+2)123    let p := 1-f124    let G := 1-(2*f)/3125    let B := 1-(4*f)/3126    let β : R := 1/2127    ∃ lo hi e b, 3 < hi ∧ 0 < e ∧ e < b ∧ b < 1 ∧128       TruthfulEffort ψ β G B p lo hi 1 ∧ TruthfulEffort ψ β G B p lo hi e ∧129       p*(hi+spread β G p ((1+b)/2))=4*ψ*b ∧130       p*(hi+spread β G p 1)=4*ψ := by131  let s := 96*ψ-1132  let f : R := 1/(s+2)133  let p : R := 1-f134  let G : R := 1-(2*f)/3135  let B : R := 1-(4*f)/3136  let β : R := 1/2137  let u : R := 1/(96*ψ)138  let r : R := 1/(6*p)139  let e := 1-6*u140  let b := 1-2*u141  let lo := 2*ψ/p142  let hi := 2*lo-r143  let K := f*r144  have one := OrderedRing.zero_lt_one (R := R)145  have hs : 0 ≤ s := by dsimp [s]; grind146  have ⟨hB,hBG,hG,hMix,hfloor⟩ := technology s hs147  change 0 < B at hB148  change B < G at hBG149  change G < 1 at hG150  change G+B=2*p at hMix151  change 1 ≤ 2*p at hfloor152  have hp : 0 < p := by grind153  have hfEq : f*(96*ψ+1)=1 := by154    have h := quotient (1:R) (s+2) (by grind)155    change f*(s+2)=1 at h156    dsimp [s] at h; grind157  have huEq : u*(96*ψ)=1 := quotient 1 _ (by grind)158  have hu : 0 < u := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (show 0 < 96*ψ by grind)).mp; grind159  have hcut := OrderedRing.mul_le_mul_of_nonneg_right hψ (le_of_lt hu)160  have he : 0 < e ∧ e < b ∧ b < 1 := by dsimp [e,b]; grind161  have hpEq : p=96*ψ*f := by dsimp [p]; grind162  have huf : u*p=f := by rw [hpEq]; have := congrArg (fun z => z*f) huEq; grind163  have hrEq : r*(6*p)=1 := quotient 1 _ (by grind)164  have hr : 0 < r := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (show 0 < 6*p by grind)).mp; grind165  have hβ : 2*β=1 := by have h := quotient (1:R) 2 (by grind); dsimp [β]; grind166  have hGq := quotient (2*f) 3 (by grind)167  have hBq := quotient (4*f) 3 (by grind)168  have hK : 4*p*K=G-B := by169    have h := congrArg (fun z => z*f) hrEq170    dsimp [K,G,B]; grind171  have hpf : 1-p=f := by dsimp [p]; grind172  have r1 : spread β G p 1=r := spreadAt β G B p 1 K r hβ hMix.symm hB hBG hG one (by grind) hK173    (by dsimp [K]; rw [← hpf]; grind)174  have heHalf := quotient (1+e) 2 (by grind)175  have hbHalf := quotient (1+b) 2 (by grind)176  have heHR : 1-((1+e)/2)*p=4*f := by177    have h := congrArg (fun z => z*p) heHalf178    dsimp [e] at h; grind179  have hbHR : 1-((1+b)/2)*p=2*f := by180    have h := congrArg (fun z => z*p) hbHalf181    dsimp [b] at h; grind182  have r4 := quotient r 4 (by grind)183  have r2 := quotient r 2 (by grind)184  have re : spread β G p ((1+e)/2)=r/4 := spreadAt _ _ _ _ _ K _ hβ hMix.symm hB hBG hG185    (by grind) (by grind) hK (by rw [heHR]; dsimp [K]; have := congrArg (fun z => f*z) r4; grind)186  have rb : spread β G p ((1+b)/2)=r/2 := spreadAt _ _ _ _ _ K _ hβ hMix.symm hB hBG hG187    (by grind) (by grind) hK (by rw [hbHR]; dsimp [K]; have := congrArg (fun z => f*z) r2; grind)188  have hl : lo*p=2*ψ := quotient _ _ hp189  have hfpos : 0 < f := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (show 0 < 96*ψ+1 by grind)).mp; grind190  have hh : 3 < hi := by191    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hp).mp192    dsimp [hi]; grind193  have hlo : 0 < lo := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hp).mp; grind194  have hrl : r < lo := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hp).mp; grind195  have hhi : lo ≤ hi := by dsimp [hi]; grind196  have ic (v : R) (hv : 0 ≤ v) (hvr : v ≤ r) : Truthful β v lo hi 0 0 := by197    have h1 := congrArg (fun z => z*(hi+v)) hβ198    have h2 := congrArg (fun z => z*lo) hβ199    have h3 := OrderedRing.mul_nonneg (a := β) (by grind) hv200    unfold Truthful201    dsimp [hi] at *202    grind203  have eq1 : (1+(1:R))/2=1 := by have := quotient (1+(1:R)) 2 (by grind); grind204  have h4 := congrArg (fun z => z*p) r4205  have h2 := congrArg (fun z => z*p) r2206  refine ⟨lo,hi,e,b,hh,he.1,he.2.1,he.2.2,?_,?_,?_,?_⟩207  · exact equilibriumOf _ _ _ _ _ _ _ _ r (by grind) hβ ⟨by grind,by grind⟩208      (by rw [eq1]; exact r1) (ic r (by grind) (by grind)) (by dsimp [hi]; grind)209  · exact equilibriumOf _ _ _ _ _ _ _ _ (r/4) (by grind) hβ ⟨by grind,by grind⟩ re210      (ic _ (by grind) (by grind)) (by dsimp [hi,e]; grind)211  · change p*(hi+spread β G p ((1+b)/2))=4*ψ*b212    rw [rb]; dsimp [hi,b]; grind213  · change p*(hi+spread β G p 1)=4*ψ214    rw [r1]; dsimp [hi]; grind215216/-- The bad branch in twoEfforts is immaterial to board optimality. This217comparison uses only IC-L, so it also works before binding IC-L is proved.218The zero-bonus truthful alternative operates at its own success probability. -/219theorem expensiveContractsLose (p h h0 m r K hi lo X L C V0 : R)220    (_p : 0 < p) (hh : 0 < h) (hh1 : h < 1) (hh0 : 0 < h0)221    (hm : 0 < m) (hx : L < X) (hIC : m*(hi+r) ≤ lo)222    (ident : (1-h)*r=K) (expensive : X-L ≤ hi)223    (benchmark : V0 = L+h0*(X-L)-m*K-C) :224    L+h*(X-L)-(h*hi+(1-h)*lo)-C < V0 := by225  have h1 := OrderedRing.mul_le_mul_of_nonneg_left hIC (c := 1-h) (by grind)226  have h2 := OrderedRing.mul_nonneg (le_of_lt hh) (b := hi-(X-L)) (by grind)227  have h3 := OrderedRing.mul_pos (OrderedRing.mul_pos hm (b := 1-h) (by grind)) (b := hi) (by grind)228  have h4 := OrderedRing.mul_pos hh0 (b := X-L) (by grind)229  have h5 := congrArg (fun z => m*z) ident230  grind231232/-- Every potentially optimal contract induces effort below 1/2 for the233explicit support-independent sufficient bound ψ > 2a'(X-L+1).234The KKT inequality covers full effort. Zero effort is included. -/235theorem optimalEffortLocalizes (ψ α p X L hi lo r e : R)236    (hψ : 0 < ψ) (hα : 0 < α) (hp : 0 < p) (hp1 : p < 1)237    (hX : L < X) (hhi : hi < X-L) (hlo : 0 ≤ lo) (hr : r < 1)238    (hsize : 2*α*(X-L+1) ≤ ψ)239    (hbest : e=0 ∨ ψ*e ≤ α*p*(hi-lo+r)) : 2*e < 1 := by240  have one := OrderedRing.zero_lt_one (R := R)241  have h1 := OrderedRing.mul_lt_mul_of_pos_left (show hi-lo+r < X-L+1 by grind) (OrderedRing.mul_pos hα hp)242  have h2 := OrderedRing.mul_lt_mul_of_pos_right hp1 (OrderedRing.mul_pos hα (b := X-L+1) (by grind))243  cases hbest with244  | inl h => rw [h]; grind245  | inr h =>246    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left hψ).mp247    grind248249/-- On the localized effort interval the failure probability stays uniformly250away from zero at every support, even when both success functions tend to one. -/251theorem localizedFailureFloor (a0 p e : R) (ha0 : 0 < a0) (ha1 : a0 < 1)252    (_hp : 0 < p) (hp1 : p < 1) (he : 0 ≤ e) (he1 : 2*e ≤ 1) :253    0 < 1-a0 ∧ 1-a0 ≤ 2*(1-(a0+(1-a0)*e)*p) := by254  have α : 0 < 1-a0 := by grind255  have := OrderedRing.mul_le_mul_of_nonneg_left he1 (le_of_lt α)256  have := OrderedRing.mul_nonneg (le_of_lt α) he257  have := OrderedRing.mul_lt_mul_of_pos_left hp1 (c := a0+(1-a0)*e) (by grind)258  grind259260/-- Under global complementarity every failure probability is bounded away261from zero even at e=1. The likelihood ratio at zero is strictly above one262and gives the uniform lower bound (1-β)(1-B(0)/G(0)). -/263theorem complementarityFloor (β G0 B0 G B : R)264    (hb : 0 < β) (hb1 : β < 1) (hB0 : 0 < B0) (h0 : B0 < G0)265    (hg : G < 1) (hRatio : G0*B ≤ G*B0) :266    0 < (1-β)*(1-B0/G0) ∧ (1-β)*(1-B0/G0) < 1-mix β G B := by267  have hG0 : 0 < G0 := by grind268  have hq := quotient B0 G0 hG0269  have hSmall : B0/G0 < 1 := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hG0).mp; grind270  have hbSmall : B < B0/G0 := by271    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hG0).mp272    have := OrderedRing.mul_lt_mul_of_pos_right hg hB0273    grind274  have h1 := OrderedRing.mul_pos hb (b := 1-G) (by grind)275  have h2 := OrderedRing.mul_lt_mul_of_pos_left hbSmall (c := 1-β) (by grind)276  exact ⟨OrderedRing.mul_pos (by grind) (by grind), by unfold mix; grind⟩277278/-- On a region with failure at least d, probability effort load v ≤ 1 and2790<K<1, the rational effort spread satisfies both large-ψ derivative280inequalities. These bounds are uniform in support. -/281theorem uniformCurvatureBounds (d failure v K ψ rE rEE : R)282    (hd : 0 < d) (hf : d ≤ failure) (hv : 0 < v) (hv1 : v ≤ 1)283    (hk : 0 < K) (hk1 : K < 1) (hψ : 0 < ψ)284    (size1 : 1 ≤ ψ*(d*d)) (size2 : 1 ≤ ψ*(d*d*d))285    (d1 : failure*failure*rE=v*K)286    (d2 : failure*failure*failure*rEE=2*v*v*K) : v*rE < ψ ∧ rEE < 2*ψ := by287  have ff := OrderedRing.mul_pos (show 0 < failure by grind) (show 0 < failure by grind)288  have dSq := OrderedRing.mul_pos hd hd289  have h1 := OrderedRing.mul_le_mul_of_nonneg_left hf (le_of_lt hd)290  have h2 := OrderedRing.mul_le_mul_of_nonneg_right hf (c := failure) (by grind)291  have h3 := OrderedRing.mul_le_mul_of_nonneg_left hf (le_of_lt dSq)292  have h4 := OrderedRing.mul_le_mul_of_nonneg_right (show d*d ≤ failure*failure by grind) (c := failure) (by grind)293  have h5 := OrderedRing.mul_le_mul_of_nonneg_left (show d*d ≤ failure*failure by grind) (le_of_lt hψ)294  have h6 := OrderedRing.mul_le_mul_of_nonneg_left (show d*d*d ≤ failure*failure*failure by grind) (le_of_lt hψ)295  have h7 := OrderedRing.mul_le_mul_of_nonneg_right hv1 (le_of_lt hk)296  have h8 := OrderedRing.mul_le_mul_of_nonneg_right hv1 (le_of_lt (OrderedRing.mul_pos hv hk))297  have h9 := congrArg (fun z => v*z) d1298  constructor299  · apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left ff).mp300    grind301  · apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left (OrderedRing.mul_pos ff (show 0 < failure by grind))).mp302    grind303304private theorem magnitude (x : R) : ∃ A, 0 < A ∧ -A < x ∧ x < A := by305  have := OrderedRing.zero_lt_one (R := R)306  by_cases h : 0 ≤ x307  · exact ⟨x+1,by grind,by grind,by grind⟩308  · exact ⟨1-x,by grind,by grind,by grind⟩309310private theorem productBound (x y A B : R) (_hA : 0 < A) (hB : 0 < B)311    (hx : -A < x ∧ x < A) (hy : -B < y ∧ y < B) :312    -(A*B) < x*y ∧ x*y < A*B := by313  have h1 := OrderedRing.mul_lt_mul_of_pos_right hx.1 hB314  have h2 := OrderedRing.mul_lt_mul_of_pos_right hx.2 hB315  by_cases h : 0 ≤ x316  · have h3 := OrderedRing.mul_le_mul_of_nonneg_left (le_of_lt hy.1) h317    have h4 := OrderedRing.mul_le_mul_of_nonneg_left (le_of_lt hy.2) h318    grind319  · have h3 := OrderedRing.mul_le_mul_of_nonpos_left (le_of_lt hy.1) (c := x) (by grind)320    have h4 := OrderedRing.mul_le_mul_of_nonpos_left (le_of_lt hy.2) (c := x) (by grind)321    grind322323private theorem nearRadius (x y : R) (hx : 0 < x) (hy : 0 < y) :324    ∃ δ, 0 < δ ∧ δ ≤ x ∧ δ ≤ y := by325  by_cases h : x ≤ y326  · exact ⟨x,hx,by grind,h⟩327  · exact ⟨y,hy,by grind,by grind⟩328329private theorem continuousConst (a : R) : ContinuousSupport (fun _ : R => a) := by330  intro c hc ε hε331  exact ⟨ε,hε,by grind⟩332333omit [IsLinearOrder R] [LawfulOrderLT R] [OrderedRing R] in334private theorem continuousId : ContinuousSupport (fun x : R => x) := by335  intro c hc ε hε336  exact ⟨ε,hε,by grind⟩337338private theorem continuousSub {f g : R → R} (hf : ContinuousSupport f) (hg : ContinuousSupport g) :339    ContinuousSupport (fun x => f x-g x) := by340  intro c hc ε hε341  have one := OrderedRing.zero_lt_one (R := R)342  let t := ε/2343  have eqn : t*2=ε := quotient ε 2 (by grind)344  have hpos : 0 < t := by grind345  obtain ⟨u,hu,hf'⟩ := hf c hc t hpos346  obtain ⟨v,hv,hg'⟩ := hg c hc t hpos347  obtain ⟨δ,hd,h1,h2⟩ := nearRadius _ _ hu hv348  refine ⟨δ,hd,?_⟩349  intro x hx hl hr350  have := hf' x hx (by grind) (by grind)351  have := hg' x hx (by grind) (by grind)352  grind353354private theorem continuousMul {f g : R → R} (hf : ContinuousSupport f) (hg : ContinuousSupport g) :355    ContinuousSupport (fun x => f x*g x) := by356  intro c hc ε hε357  have one := OrderedRing.zero_lt_one (R := R)358  obtain ⟨A,hA,fa,fb⟩ := magnitude (f c)359  obtain ⟨B,hB,ga,gb⟩ := magnitude (g c)360  let M := A+B+1361  let w := ε/M362  have hM : 0 < M := by dsimp [M]; grind363  have hw : w*M=ε := quotient ε M hM364  have hw0 : 0 < w := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hM).mp; grind365  obtain ⟨t,ht,htw,ht1⟩ := nearRadius w 1 hw0 one366  obtain ⟨u,hu,hf'⟩ := hf c hc t ht367  obtain ⟨v,hv,hg'⟩ := hg c hc t ht368  obtain ⟨δ,hd,h1,h2⟩ := nearRadius _ _ hu hv369  refine ⟨δ,hd,?_⟩370  intro x hx hl hr371  have hfx := hf' x hx (by grind) (by grind)372  have hgx := hg' x hx (by grind) (by grind)373  have p1 := productBound (f x-f c) (g x) t (B+1) ht (by grind) (by grind) (by grind)374  have p2 := productBound (g x-g c) (f c) t A ht hA (by grind) ⟨fa,fb⟩375  have h3 := OrderedRing.mul_le_mul_of_nonneg_right htw (le_of_lt hM)376  dsimp [M] at hw h3377  grind378379/-- The zero-bonus effort threshold exists in the localized interval.380The sign at the upper endpoint is given as a primitive coefficient381inequality. No postulated root or derivative is used. -/382theorem boundaryExists (ψ v m K u cap : R) (hcap : 0 < cap)383    (_hψ : 0 < ψ) (hv : 0 < v) (hk : 0 < K) (hm : m < 1)384    (endpoint : (1-m)*v*K < ψ*cap*(u-v*cap)) (complete : CompleteSupport R) :385    ∃ e, 0 < e ∧ e < cap ∧ ψ*e*(u-v*e)=(1-m)*v*K := by386  let F := fun e : R => ψ*e*(u-v*e)387  have cont : ContinuousSupport F := continuousMul (continuousMul (continuousConst ψ) continuousId)388    (continuousSub (continuousConst u) (continuousMul (continuousConst v) continuousId))389  have pos := OrderedRing.mul_pos (OrderedRing.mul_pos (a := 1-m) (by grind) hv) hk390  exact intermediateValue F 0 cap _ (by grind) hcap (by dsimp [F]; grind) endpoint cont complete391392/-- Exact tangent loss for the reduced board payoff c+l e-ψ e²+K/(u-v e).393The last term of the tangent loss is bounded uniformly using the minimum394failure probability. This supplies a *strict global* comparison on either395side of an interior stationary point, or to the right of a boundary. -/396private theorem belowTangent (ψ K u v l c d e x : R) (hψ : 0 < ψ) (hd : 0 < d)397    (he : d ≤ u-v*e) (hx : d ≤ u-v*x) (hne : x ≠ e)398    (bound : v*v*K < ψ*d*d*d) :399    let U := fun y => c+l*y-ψ*y*y+K/(u-v*y)400    let Q := (l-2*ψ*e)*((u-v*e)*(u-v*e))+v*K401    ((u-v*e)*(u-v*e))*(U x-U e) < Q*(x-e) := by402  let f := u-v*e403  let g := u-v*x404  have hf : 0 < f := by dsimp [f]; grind405  have hg : 0 < g := by dsimp [g]; grind406  change d ≤ f at he407  change d ≤ g at hx408  have h0 := OrderedRing.mul_le_mul_of_nonneg_left he (le_of_lt hd)409  have h1 := OrderedRing.mul_le_mul_of_nonneg_right he (le_of_lt hf)410  have h2 := OrderedRing.mul_le_mul_of_nonneg_left hx (le_of_lt (OrderedRing.mul_pos hd hd))411  have h3 := OrderedRing.mul_le_mul_of_nonneg_right (show d*d ≤ f*f by grind) (le_of_lt hg)412  have h4 := OrderedRing.mul_le_mul_of_nonneg_left (show d*d*d ≤ f*f*g by grind) (le_of_lt hψ)413  have sq : 0 < (x-e)*(x-e) := by414    by_cases h : e < x415    · exact OrderedRing.mul_pos (by grind) (by grind)416    · have := OrderedRing.mul_pos (a := e-x) (b := e-x) (by grind) (by grind); grind417  have pos := OrderedRing.mul_pos (a := ψ*f*f*g-v*v*K) (by grind) sq418  have e1 := quotient K f hf419  have e2 := quotient K g hg420  have m1 := congrArg (fun z => f*g*z) e1421  have m2 := congrArg (fun z => f*f*z) e2422  have eqn : f-g=v*(x-e) := by dsimp [f,g]; grind423  have m3 := congrArg (fun z => z*(f*K)) eqn424  have m4 := congrArg (fun z => z*(v*K*(x-e))) eqn425  try dsimp only at m1 m2 m3 m4426  change f*f*((c+l*x-ψ*x*x+K/g)-(c+l*e-ψ*e*e+K/f)) <427    ((l-2*ψ*e)*(f*f)+v*K)*(x-e)428  apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left hg).mp429  grind430431/-- Existence, uniqueness and upper-endpoint exclusion for the board's432reduced effort objective on the binding branch. A boundary optimum e=e₀433is admitted and corresponds to zero high-report bonus. -/434theorem optimalBindingEffort (ψ K u v l c e0 cap : R) (hψ : 0 < ψ) (hv : 0 < v)435    (he0 : 0 < e0) (hec : e0 < cap) (hf : 0 < u-v*cap)436    (curvature : v*v*K < ψ*(u-v*cap)*(u-v*cap)*(u-v*cap))437    (endpoint : (l-2*ψ*cap)*((u-v*cap)*(u-v*cap))+v*K < 0)438    (complete : CompleteSupport R) :439    let U := fun y => c+l*y-ψ*y*y+K/(u-v*y)440    ∃ e, e0 ≤ e ∧ e < cap ∧ ∀ x, e0 ≤ x → x ≤ cap → x ≠ e → U x < U e := by441  let F := fun y => (u-v*y)442  let D := fun y => (l-2*ψ*y)*(F y*F y)+v*K443  have fmono (x : R) (hx : x ≤ cap) : F cap ≤ F x := by444    have := OrderedRing.mul_le_mul_of_nonneg_left hx (le_of_lt hv); dsimp [F]; grind445  have contF : ContinuousSupport F := continuousSub (continuousConst u) (continuousMul (continuousConst v) continuousId)446  let N := fun y => (0-(l-2*ψ*y)*(F y*F y))-v*K447  have cont : ContinuousSupport N := continuousSub (continuousSub (continuousConst 0)448    (continuousMul (continuousSub (continuousConst l) (continuousMul (continuousConst (2*ψ)) continuousId))449    (continuousMul contF contF))) (continuousConst (v*K))450  have opt (e : R) (he : e0 ≤ e) (he' : e < cap) (q : D e=0 ∨ (e=e0 ∧ D e ≤ 0)) :451      ∀ x, e0 ≤ x → x ≤ cap → x ≠ e →452        c+l*x-ψ*x*x+K/(F x) < c+l*e-ψ*e*e+K/(F e) := by453    intro x hx hxc hn454    have hfe := fmono e (le_of_lt he')455    have hfx := fmono x hxc456    have h := belowTangent ψ K u v l c (F cap) e x hψ hf hfe hfx hn curvature457    have sign : D e*(x-e) ≤ 0 := by458      cases q with459      | inl h => rw [h]; grind460      | inr h =>461        have := OrderedRing.mul_nonneg (a := -(D e)) (by grind) (b := x-e) (by grind)462        grind463    change F e*F e*((c+l*x-ψ*x*x+K/(F x))-(c+l*e-ψ*e*e+K/(F e))) < D e*(x-e) at h464    have hp : 0 < F e := lt_of_lt_of_le hf hfe465    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left (OrderedRing.mul_pos hp hp)).mp466    grind467  by_cases h : D e0 ≤ 0468  · exact ⟨e0,by grind,hec,opt e0 (by grind) hec (Or.inr ⟨rfl,h⟩)⟩469  · obtain ⟨e,hl,hr,hd⟩ := intermediateValue N e0 cap 0 (le_of_lt he0) hec470      (by dsimp [N,D] at *; grind) (by dsimp [N,F]; grind) cont complete471    have hzero : D e=0 := by dsimp [N] at hd; dsimp [D]; grind472    exact ⟨e,le_of_lt hl,hr,opt e (le_of_lt hl) hr (Or.inl hzero)⟩473474/-- Strict optimality of effort among deviations is needed only against475slightly lower effort to obtain the pooling inequality. This also covers476an optimal effort of one. ψ is positive and lo/hi are total conditional477utility, including the posterior at the corresponding public history. -/478theorem effortKKT (v ψ lo hi e : R) (hψ : 0 < ψ) (he : 0 < e) (he1 : e ≤ 1)479    (optimal : ∀ x, 0 ≤ x → x ≤ 1 →480      2*v*(hi-lo)*x-ψ*x*x ≤ 2*v*(hi-lo)*e-ψ*e*e) :481    ψ*e ≤ v*(hi-lo) := by482  by_cases h : v*(hi-lo) < ψ*e483  · let g := ψ*e-v*(hi-lo)484    have hg : 0 < g := by dsimp [g]; grind485    let t := g/ψ486    have hte : t*ψ=g := quotient g ψ hψ487    have ht : 0 < t := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hψ).mp; grind488    obtain ⟨δ,hδ,hte',hδt⟩ := nearRadius e t he ht489    have hm := OrderedRing.mul_le_mul_of_nonneg_right hδt (le_of_lt hψ)490    have hprod := OrderedRing.mul_pos hδ (b := 2*g-ψ*δ) (by grind)491    have := optimal (e-δ) (by grind) (by grind)492    dsimp [g] at hprod493    grind494  · grind495496/-- Conditional wages plus hiring probabilities from pooling high. On497a corrected false high signal the market sees low; an unflagged report498receives its actual pooled Bayes posterior. -/499theorem poolingHighFromHistories (h m high low hi d0 v ψ e : R)500    (hh : 0 < h) (hh1 : h < 1) (hm : 0 < m) (hm1 : m < 1)501    (hv : 0 < v) (hψ : 0 < ψ) (he : 0 < e) (he1 : e ≤ 1)502    (optimal : let pool := (h*high+m*(1-h)*low)/(h+m*(1-h))503               let UH := hi+pool504               let UL := m*(hi+pool)+(1-m)*(d0+low)505               ∀ x, 0 ≤ x → x ≤ 1 →506                2*v*(UH-UL)*x-ψ*x*x ≤ 2*v*(UH-UL)*e-ψ*e*e) :507    let q := ψ*e/((1-m)*v)508    0 ≤ (h+m*(1-h))*(hi-d0-q)+h*(high-low) := by509  let n := h+m*(1-h)510  let z := (h*high+m*(1-h)*low)/n511  let q := ψ*e/((1-m)*v)512  have pos := OrderedRing.mul_pos hm (b := 1-h) (by grind)513  have hn : 0 < n := by dsimp [n]; grind514  have hk := OrderedRing.mul_pos (a := 1-m) (by grind) hv515  have hz : z*n=h*high+m*(1-h)*low := quotient _ _ hn516  have hq : q*((1-m)*v)=ψ*e := quotient _ _ hk517  have foc := effortKKT v ψ (m*(hi+z)+(1-m)*(d0+low)) (hi+z) e hψ he he1 optimal518  have cut : q ≤ hi-d0+z-low := by519    apply (Field.IsOrdered.mul_le_mul_iff_of_pos_left hk).mp520    grind521  have b := OrderedRing.mul_le_mul_of_nonneg_left cut (le_of_lt hn)522  have hdiff : n*(z-low)=h*(high-low) := by523    have h := congrArg (fun x => x*low) (show n = h+m*(1-h) from rfl)524    try dsimp only at h525    grind526  change 0 ≤ n*(hi-d0-q)+h*(high-low)527  grind528529/-- Pooling low. The contractual ceiling on a corrected misreport makes530the attainable effort wedge smaller than the truthful zero-bonus wedge. -/531theorem poolingLowFromHistories (h m high low lo dx v ψ e : R)532    (hh : 0 < h) (hh1 : h < 1) (hm : 0 < m) (hm1 : m < 1) (hr : low < high)533    (hv : 0 < v) (hψ : 0 < ψ) (he : 0 < e) (he1 : e ≤ 1) (hcap : dx ≤ lo)534    (optimal : let pool := (m*h*high+(1-h)*low)/(1-h+m*h)535               let UH := m*(lo+pool)+(1-m)*(dx+high)536               let UL := lo+pool537               ∀ x, 0 ≤ x → x ≤ 1 →538                2*v*(UH-UL)*x-ψ*x*x ≤ 2*v*(UH-UL)*e-ψ*e*e) :539    ψ*e < v*(1-m)*(high-low) := by540  let n := 1-h+m*h541  let z := (m*h*high+(1-h)*low)/n542  have mh := OrderedRing.mul_pos hm hh543  have hn : 0 < n := by dsimp [n]; grind544  have hk := OrderedRing.mul_pos hv (b := 1-m) (by grind)545  have hz : z*n=m*h*high+(1-h)*low := quotient _ _ hn546  have hmix : n*(z-low)=m*h*(high-low) := by547    have h := congrArg (fun x => x*low) (show n=1-h+m*h from rfl)548    try dsimp only at h549    grind550  have hpos := OrderedRing.mul_pos mh (b := high-low) (by grind)551  have hzL : low < z := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left hn).mp; grind552  have b := OrderedRing.mul_lt_mul_of_pos_left (show dx-lo+high-z < high-low by grind) hk553  have H := effortKKT v ψ (lo+z) (m*(lo+z)+(1-m)*(dx+high)) e hψ he he1 optimal554  grind555556/-- The local monotonicity argument suffices to classify *all* feasible557targets relative to the zero-bonus threshold. Outside the local interval558the cost of effort already exceeds the entire reputational wedge. -/559theorem signBeyondThreshold (w : R → R) (e0 cap : R) (h0 : 0 < e0) (hc : e0 < cap)560    (root : w e0=0) (inc : ∀ x y, 0 ≤ x → x < y → y ≤ cap → w x < w y)561    (outside : ∀ y, cap < y → y ≤ 1 → 0 < w y) :562    ∀ e, 0 ≤ e → e ≤ 1 → (w e < 0 ↔ e < e0) ∧ (0 < w e ↔ e0 < e) := by563  intro e he he1564  by_cases h : e < e0565  · have := inc e e0 he h (by grind); grind566  · by_cases eq : e=e0567    · rw [eq,root]; grind568    · by_cases late : cap < e569      · have := outside e late he1; grind570      · have := inc e0 e (by grind) (by grind) (by grind); grind571572/-- Any randomized continuation decision on a pooled report lies below a573strictly superior truthful outcome if both deterministic responses do. -/574theorem mixtureDominated (x y t q : R) (hx : x < t) (hy : y < t) (hq : 0 ≤ q) (hq1 : q ≤ 1) :575    q*x+(1-q)*y < t := by576  by_cases h : 0 < q577  · have h1 := OrderedRing.mul_lt_mul_of_pos_left hx h578    have h2 := OrderedRing.mul_le_mul_of_nonneg_left (le_of_lt hy) (c := 1-q) (by grind)579    grind580  · have hz : q=0 := by grind581    rw [hz]; grind582583/-- The four reporting strategies exhaust maps from a binary signal to a584binary attempted report; the two bits are low-signal and high-signal actions. -/585inductive Rule | truth | poolHigh | poolLow | invert586  deriving DecidableEq587def ruleOf (strategy : Bool → Bool) : Rule :=588  match strategy false, strategy true with589  | false,true => .truth590  | true,true => .poolHigh591  | false,false => .poolLow592  | true,false => .invert593594theorem boardOptimalTruth (strategy : Bool → Bool) (s payoff : R) (values : R → R)595    (global : ∀ x, 0 ≤ x → values x ≤ payoff) (hs : 0 ≤ s)596    (high : ruleOf strategy = .poolHigh → payoff < values s)597    (low : ruleOf strategy = .poolLow → payoff < values s)598    (inverse : ruleOf strategy ≠ .invert) :599    ∀ σ, strategy σ = σ := by600  have h := global s hs601  intro σ602  cases e0 : strategy false <;> cases e1 : strategy true <;>603    cases σ <;> simp_all [ruleOf] <;> grind604605/-- Subtraction for the epsilon-delta derivative on feasible supports. -/606theorem slopeSub {f g : R → R} {x p q : R} (hf : HasSlopeAt f x p) (hg : HasSlopeAt g x q) :607    HasSlopeAt (fun y => f y-g y) x (p-q) := by608  intro ε hε609  have one := OrderedRing.zero_lt_one (R := R)610  let t := ε/2611  have ht : t*2=ε := quotient ε 2 (by grind)612  obtain ⟨d,hd,F⟩ := hf t (by grind)613  obtain ⟨w,hw,G⟩ := hg t (by grind)614  obtain ⟨δ,hδ,h1,h2⟩ := nearRadius d w hd hw615  refine ⟨δ,hδ,?_⟩616  intro y hy hl hr hn617  obtain ⟨v,hv,hvl,hvr⟩ := F y hy (by grind) (by grind) hn618  obtain ⟨z,hz,hzl,hzr⟩ := G y hy (by grind) (by grind) hn619  exact ⟨v-z,by dsimp only; grind,by grind,by grind⟩620621private theorem slopeSides {f : R → R} {c p : R} (h : HasSlopeAt f c p) (hp : 0 < p) :622    ∃ δ, 0 < δ ∧ ∀ x, 0 ≤ x → c-δ < x → x < c+δ →623      (x<c → f x < f c) ∧ (c<x → f c < f x) := by624  obtain ⟨δ,hd,F⟩ := h p hp625  refine ⟨δ,hd,?_⟩626  intro x hx hl hr627  constructor628  · intro hxc629    obtain ⟨v,hv,hvl,_⟩ := F x hx hl hr (by grind)630    have := OrderedRing.mul_pos (a := v) (by grind) (b := c-x) (by grind)631    grind632  · intro hcx633    obtain ⟨v,hv,hvl,_⟩ := F x hx hl hr (by grind)634    have := OrderedRing.mul_pos (a := v) (by grind) (b := x-c) (by grind)635    grind636637private theorem shortStep (a b : R) (ha : 0 < a) (hb : 0 < b) :638    ∃ δ, 0 < δ ∧ δ < a ∧ δ < b := by639  obtain ⟨z,hz,h1,h2⟩ := nearRadius a b ha hb640  have one := OrderedRing.zero_lt_one (R := R)641  have eqn := quotient z 2 (by grind)642  exact ⟨z/2,by grind,by grind,by grind⟩643644/-- Positive slope implies strict increase. The slope may vanish at the645left endpoint, as it does for the cost difference at support zero. -/646theorem increaseOnInterval (f : R → R) (complete : CompleteSupport R)647    (a b : R) (ha : 0 ≤ a) (hab : a < b) (cont : ∀ ε, 0<ε → ∃ δ, 0<δ ∧ ∀ x, 0≤x → a-δ<x → x<a+δ → f a-ε<f x ∧ f x<f a+ε)648    (positive : ∀ c, a<c → c≤b → ∃ d, 0 < d ∧ HasSlopeAt f c d) : f a < f b := by649  have interior (l r : R) (hl : a < l) (hlr : l < r) (hr : r ≤ b) : f l < f r := by650    obtain ⟨p,hp,hD⟩ := positive l hl (by grind)651    obtain ⟨δ,hδ,H⟩ := slopeSides hD hp652    obtain ⟨t,ht,h1,h2⟩ := shortStep δ (r-l) hδ (by grind)653    have hstart := (H (l+t) (by grind) (by grind) (by grind)).2 (by grind)654    let S := fun z => l ≤ z ∧ z ≤ r ∧ f l < f z655    obtain ⟨c,hup,least⟩ := complete r S ⟨l+t,by dsimp [S]; grind⟩ (by intro z hz; exact hz.2.1)656    have hc := hup (l+t) (by dsimp [S]; grind)657    have hcb := least r (by intro z hz; exact hz.2.1)658    obtain ⟨q,hq,hDq⟩ := positive c (by grind) (by grind)659    obtain ⟨w,hw,U⟩ := slopeSides hDq hq660    have hgood : f l < f c := by661      by_cases bad : f l < f c662      · exact bad663      · obtain ⟨v,hv,hvw,hvc⟩ := shortStep w (c-l) hw (by grind)664        have hu : ∀ z, S z → z ≤ c-v := by665          intro z hz666          have hzc := hup z hz667          obtain ⟨haz,_,hgz⟩ := hz668          by_cases lt : c-v < z669          · have hlt : z < c := by by_cases heq : z=c <;> grind670            have := (U z (by grind) (by grind) (by grind)).1 hlt671            grind672          · grind673        have := least (c-v) hu674        grind675    by_cases h : c=r676    · simpa [h] using hgood677    · obtain ⟨v,hv,hvw,hvb⟩ := shortStep w (r-c) hw (by grind)678      have := (U (c+v) (by grind) (by grind) (by grind)).2 (by grind)679      have hz := hup (c+v) (by dsimp [S]; grind)680      grind681  obtain ⟨t,ht,htb,_⟩ := shortStep (b-a) (b-a) (by grind) (by grind)682  let c := a+t683  have hc : a<c := by dsimp [c]; grind684  have hcb : c<b := by dsimp [c]; grind685  have hmid := interior c b hc hcb (by grind)686  by_cases h : f a ≤ f c687  · grind688  · obtain ⟨δ,hd,H⟩ := cont (f a-f c) (by grind)689    obtain ⟨u,hu,hud,huc⟩ := shortStep δ (c-a) hd (by grind)690    have := H (a+u) (by grind) (by grind) (by grind)691    have := interior (a+u) c (by grind) (by grind) (by grind)692    grind693694theorem strictIncreaseFromSlope (f : R → R) (complete : CompleteSupport R)695    (a b : R) (ha : 0 ≤ a) (hab : a < b) (cont : ContinuousSupport f)696    (positive : ∀ c, a<c → c≤b → ∃ d, 0 < d ∧ HasSlopeAt f c d) : f a < f b :=697  increaseOnInterval f complete a b ha hab (cont a ha) positive698699/-- OA1. The type payoff difference equals C₀-C₁. The derivative ordering700on s>0 gives global single crossing, including comparisons to zero. -/701theorem boardSingleCrossing (common C0 C1 d0 d1 : R → R) (complete : CompleteSupport R)702    (c0 : ContinuousSupport C0) (c1 : ContinuousSupport C1)703    (derivs : ∀ s, 0 < s → HasSlopeAt C0 s (d0 s) ∧ HasSlopeAt C1 s (d1 s) ∧ d1 s < d0 s) :704    ∀ s t, 0 ≤ s → s<t →705      (common s-C1 s)-(common s-C0 s) < (common t-C1 t)-(common t-C0 t) := by706  intro s t hs hst707  have hpos (x : R) (hx : s<x) (_ : x≤t) :708      ∃ d, 0 < d ∧ HasSlopeAt (fun y => C0 y-C1 y) x d := by709    obtain ⟨h0,h1,hd⟩ := derivs x (by grind)710    exact ⟨d0 x-d1 x,by grind,slopeSub h0 h1⟩711  have h := strictIncreaseFromSlope _ complete s t hs hst (continuousSub c0 c1) hpos712  grind713714/-- Strict concavity gives a strictly declining right tail from a maximizer. -/715theorem concaveTail (f : R → R) (p : R) (opt : Maximizes f p)716    (chord : ∀ a b c, 0 ≤ a → a<b → b<c →717      (c-b)*f a+(b-a)*f c < (c-a)*f b) :718    ∀ x y, p ≤ x → x<y → f y < f x := by719  intro x y hx hxy720  obtain ⟨hp,hm⟩ := opt721  have hmx := hm x (by grind)722  by_cases he : p=x723  · subst x724    obtain ⟨t,ht,h1,_⟩ := shortStep (y-p) (y-p) (by grind) (by grind)725    have h := chord p (p+t) y hp (by grind) (by grind)726    have hmid := hm (p+t) (by grind)727    have hh := OrderedRing.mul_le_mul_of_nonneg_left hmid (c := y-p) (by grind)728    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left ht).mp729    grind730  · have h := chord p x y hp (by grind) hxy731    have h1 := OrderedRing.mul_le_mul_of_nonneg_left hmx (c := y-x) (by grind)732    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_left (show 0 < x-p by grind)).mp733    grind734735/-- Uniform hiring. Write J(y)-J(x) for the integral of the increasing736function V on [x,y]. The elementary upper/lower rectangle bounds imply737the tangent for Γ(r)=rV(r)+J(1)-J(r), including strictness. -/738theorem uniformHiringIntegral (V J g : R → R)739    (increases : ∀ r y, 0 ≤ r → r<y → y≤1 → V r < V y)740    (rectangles : ∀ r y, 0 ≤ r → r≤y → y≤1 →741      (y-r)*V r ≤ J y-J r ∧ J y-J r ≤ (y-r)*V y)742    (tangent : ∀ r y, 0 ≤ r → r≤1 → 0 ≤ y → y≤1 → V r+g r*(y-r) ≤ V y)743    (r y : R) (hr : 0≤r) (hr1 : r≤1) (hy : 0≤y) (hy1 : y≤1) :744    let Γ := fun x => x*V x+J 1-J x745    Γ r+(r*g r)*(y-r) ≤ Γ y ∧ (r<y → Γ r+(r*g r)*(y-r) < Γ y) := by746  have tan := tangent r y hr hr1 hy hy1747  have ht := OrderedRing.mul_le_mul_of_nonneg_left tan hr748  by_cases h : r<y749  · obtain ⟨t,h0,hb,_⟩ := shortStep (y-r) (y-r) (by grind) (by grind)750    have ru := (rectangles r (r+t) hr (by grind) (by grind)).2751    have uy := (rectangles (r+t) y (by grind) (by grind) hy1).2752    have gap := OrderedRing.mul_lt_mul_of_pos_left (increases (r+t) y (by grind) (by grind) hy1) h0753    dsimp only; grind754  · have yr := (rectangles y r hy (by grind) hr1).1755    dsimp only; grind756757/-- A positive number works simultaneously at every point of a compact758support interval if each support has its own open neighborhood with a759positive number. The hypotheses concern one-sided limits in m. -/760theorem uniformOnSupport (P : R → R → Prop) (S : R) (hS : 0 ≤ S)761    (complete : CompleteSupport R)762    (nearby : ∀ c, 0 ≤ c → c ≤ S → ∃ δ η, 0 < δ ∧ 0 < η ∧763      ∀ x m, 0 ≤ x → x ≤ S → c-δ < x → x < c+δ → 0 < m → m < η → P x m) :764    ∃ η, 0 < η ∧ ∀ x m, 0 ≤ x → x ≤ S → 0 < m → m < η → P x m := by765  let good := fun r => 0 ≤ r ∧ r ≤ S ∧766    ∃ η, 0 < η ∧ ∀ x m, 0 ≤ x → x ≤ r → 0 < m → m < η → P x m767  obtain ⟨δ,η,hδ,hη,H⟩ := nearby 0 (by grind) hS768  have hz : good 0 := ⟨by grind,hS,η,hη,by769    intro x m hx hx' hm hm'770    exact H x m hx (by grind) (by grind) (by grind) hm hm'⟩771  obtain ⟨c,ub,least⟩ := complete S good ⟨0,hz⟩ (by intro x hx; exact hx.2.1)772  have hc := ub 0 hz773  have hcs := least S (by intro x hx; exact hx.2.1)774  obtain ⟨w,k,hw,hk,N⟩ := nearby c hc hcs775  have existsLeft : ∃ x, good x ∧ c-w < x := by776    apply Classical.byContradiction777    intro no778    have bound (x : R) (hx : good x) : x ≤ c-w := by779      by_cases h : c-w<x780      · exact False.elim (no ⟨x,hx,h⟩)781      · grind782    have := least (c-w) bound783    grind784  obtain ⟨x,hx,hleft⟩ := existsLeft785  obtain ⟨_,_,q,hq,Q⟩ := hx786  obtain ⟨v,hv,hqv,hkv⟩ := nearRadius q k hq hk787  have extend (z : R) (hzc : c≤z) (hzS : z≤S) (hzw : z<c+w) : good z := by788    refine ⟨by grind,hzS,v,hv,?_⟩789    intro t m ht htz hm hmv790    by_cases old : t ≤ x791    · exact Q t m ht old hm (by grind)792    · exact N t m ht (by grind) (by grind) (by grind) hm (by grind)793  by_cases eqn : c=S794  · have h := extend S (by grind) (by grind) (by grind)795    exact h.2.2796  · obtain ⟨t,ht,h1,h2⟩ := shortStep w (S-c) hw (by grind)797    have := ub (c+t) (extend (c+t) (by grind) (by grind) (by grind))798    grind799800/-- A lower Darboux sum over a finite partition of [0,x], using left801endpoints for the increasing outside-option value. No grid is prescribed. -/802inductive LowerSum (V : R → R) : R → R → Prop803  | zero : LowerSum V 0 0804  | extend {x a : R} (previous : LowerSum V x a) (y : R) (step : x≤y) :805      LowerSum V y (a+(y-x)*V x)806807private theorem sumNonnegativeEndpoint {V : R → R} {x a : R} (h : LowerSum V x a) : 0 ≤ x := by808  induction h with809  | zero => grind810  | extend _ _ _ ih => grind811812/-- Splitting any partition at x can only increase a lower sum. For the813upper bound on its remaining length it suffices to use the value at y. -/814private theorem splitSum (V : R → R)815    (mono : ∀ x y, 0 ≤ x → x≤y → y≤1 → V x ≤ V y)816    {y a : R} (h : LowerSum V y a) (hy : y≤1) (x : R) (hx : 0≤x) (hxy : x≤y) :817    ∃ t, LowerSum V x t ∧ a ≤ t+(y-x)*V y := by818  induction h with819  | zero =>820    have e : x=0 := by grind821    subst x822    exact ⟨0,.zero,by grind⟩823  | @extend b a H z hb ih =>824    have b0 := sumNonnegativeEndpoint H825    have monot := mono b z b0 hb hy826    by_cases xb : x≤b827    · obtain ⟨t,ht,hbound⟩ := ih (by grind) xb828      have h1 := OrderedRing.mul_le_mul_of_nonneg_left monot (c := b-x) (by grind)829      have h2 := OrderedRing.mul_le_mul_of_nonneg_left monot (c := z-b) (by grind)830      exact ⟨t,ht,by grind⟩831    · have h1 := OrderedRing.mul_le_mul_of_nonneg_left monot (c := z-x) (by grind)832      exact ⟨a+(x-b)*V b,H.extend x (by grind),by grind⟩833834/-- Construct the integral J(x) as the supremum of finite lower sums.835Both rectangle bounds then follow from the construction itself. -/836theorem monotoneIntegral (V : R → R) (complete : CompleteSupport R)837    (mono : ∀ x y, 0 ≤ x → x≤y → y≤1 → V x ≤ V y) :838    ∃ J : R → R, ∀ r y, 0 ≤ r → r≤y → y≤1 →839      (y-r)*V r ≤ J y-J r ∧ J y-J r ≤ (y-r)*V y := by840  classical841  have sup (x : R) (hx : 0≤x ∧ x≤1) : ∃ j,842      (∀ t, LowerSum V x t → t≤j) ∧843      ∀ u, (∀ t, LowerSum V x t → t≤u) → j≤u := by844    have init : LowerSum V 0 0 := .zero845    have bound {z t : R} (H : LowerSum V z t) (hz : z≤x) : t ≤ z*V x := by846      induction H with847      | zero => grind848      | @extend b a h y hy ih =>849        have hprev := ih (by grind)850        have hle := mono b x (sumNonnegativeEndpoint h) (by grind) hx.2851        have := OrderedRing.mul_le_mul_of_nonneg_left hle (c := y-b) (by grind); grind852    exact complete (x*V x) (LowerSum V x) ⟨_,init.extend x hx.1⟩853      (by intro t ht; exact bound ht (by grind))854  let J := fun x => if hx : 0≤x ∧ x≤1 then Classical.choose (sup x hx) else 0855  have spec (x : R) (hx : 0≤x ∧ x≤1) :856      (∀ t, LowerSum V x t → t≤J x) ∧ (∀ u, (∀ t, LowerSum V x t → t≤u) → J x≤u) := by857    simpa [J,hx] using Classical.choose_spec (sup x hx)858  refine ⟨J,?_⟩859  intro r y hr hry hy860  obtain ⟨ur,lr⟩ := spec r ⟨hr,by grind⟩861  obtain ⟨uy,ly⟩ := spec y ⟨by grind,hy⟩862  have a := lr (J y-(y-r)*V r) (by863    intro t ht864    have := uy _ (ht.extend y hry)865    grind)866  have b := ly (J r+(y-r)*V y) (by867    intro t ht868    obtain ⟨u,hu,hbound⟩ := splitSum V mono ht hy r hr hry869    have := ur u hu870    grind)871  grind872873/-- Proposition 5's hiring tangent starting from a uniform outside874option, an increasing continuation value and its supporting lines.875Both the integral and the comparison are constructed on [0,1]. -/876theorem uniformHiringFromValue (V g : R → R) (complete : CompleteSupport R)877    (inc : ∀ r y, 0≤r → r<y → y≤1 → V r < V y)878    (tan : ∀ r y, 0≤r → r≤1 → 0≤y → y≤1 → V r+g r*(y-r) ≤ V y) :879    ∃ J : R → R,880      (∀ r y, 0≤r → r≤y → y≤1 → (y-r)*V r ≤ J y-J r ∧ J y-J r ≤ (y-r)*V y) ∧881      let Γ := fun x => x*V x+J 1-J x882      ∀ r y, 0≤r → r≤1 → 0≤y → y≤1 →883        Γ r+(r*g r)*(y-r) ≤ Γ y ∧ (r<y → Γ r+(r*g r)*(y-r) < Γ y) := by884  have mono (x y : R) (hx : 0≤x) (hxy : x≤y) (hy : y≤1) : V x ≤ V y := by885    by_cases eq : x=y886    · rw [eq]; grind887    · exact le_of_lt (inc x y hx (by grind) hy)888  obtain ⟨J,rect⟩ := monotoneIntegral V complete mono889  exact ⟨J,rect,uniformHiringIntegral V J g inc rect tan⟩890891/-- The zero-bonus comparator is implementable at the polynomial root.892The reporting ICs, effort optimum, and compensation all use the same r. -/893theorem zeroBonusAtRoot (v ψ m e h K r : R)894    (_hv : 0<v) (hψ : 0<ψ) (hm : 0<m) (hm1 : m<1)895    (he : 0<e) (he1 : e<1) (hh : h<1) (hr : 0<r)896    (bayes : (1-h)*r=K) (root : ψ*e*(1-h)=(1-m)*v*K) :897    0<e ∧ e<1 ∧ Truthful m r (m*r) 0 0 0 ∧ cost h (m*r) 0=m*K ∧898    ∀ x, x≠e → 2*v*(0-m*r+r)*x-ψ*x*x < 2*v*(0-m*r+r)*e-ψ*e*e := by899  have k := congrArg (fun z => (1-m)*v*z) bayes900  have heq : ψ*e=(1-m)*v*r := by901    have eq : (1-h)*(ψ*e)=(1-h)*((1-m)*v*r) := by grind902    have h1 := congrArg (fun z => (1-h)⁻¹*z) eq903    have h2 := Field.mul_inv_cancel (show 1-h ≠ 0 by grind)904    grind905  have pay := OrderedRing.mul_pos hm hr906  have hi := OrderedRing.mul_lt_mul_of_pos_right hm1 pay907  have hc := congrArg (fun z => m*z) bayes908  refine ⟨he,he1,?_,?_,?_⟩909  · unfold Truthful; grind910  · unfold cost; grind911  · intro x hx912    have H := quadraticChoice ψ e (v*(0-m*r+r)) hψ (by grind) x hx913    grind914915/-- Uniform uniqueness for one fixed contract among feasible truthful916interior effort choices with failure probabilities at least d. The two917low payments are literally the same. -/918theorem sameContractEffortUnique (v ψ d K u lo hi x y rx ry : R)919    (hd : 0<d) (hx : d≤u-v*x) (hy : d≤u-v*y) (hψ : 0<ψ)920    (bound : v*v*K < ψ*d*d)921    (bayesX : (u-v*x)*rx=K) (bayesY : (u-v*y)*ry=K)922    (focX : ψ*x=v*(hi-lo+rx)) (focY : ψ*y=v*(hi-lo+ry)) : x=y := by923  let f := u-v*x924  let g := u-v*y925  change d ≤ f at hx926  change d ≤ g at hy927  change f*rx=K at bayesX928  change g*ry=K at bayesY929  have p1 := OrderedRing.mul_le_mul_of_nonneg_left hx (le_of_lt hd)930  have p2 := OrderedRing.mul_le_mul_of_nonneg_right hy (c := f) (by grind)931  have p3 := OrderedRing.mul_le_mul_of_nonneg_left (show d*d≤f*g by grind) (le_of_lt hψ)932  have id1 := congrArg (fun z => v*g*z) bayesX933  have id2 := congrArg (fun z => v*f*z) bayesY934  have id3 := congrArg (fun z => f*g*z) focX935  have id4 := congrArg (fun z => f*g*z) focY936  have df : f-g=v*(y-x) := by dsimp [f,g]; grind937  have id5 := congrArg (fun z => v*K*z) df938  have e : (ψ*f*g-v*v*K)*x=(ψ*f*g-v*v*K)*y := by grind939  have h1 := congrArg (fun z => (ψ*f*g-v*v*K)⁻¹*z) e940  have h2 := Field.mul_inv_cancel (show ψ*f*g-v*v*K ≠ 0 by grind)941  grind942943/-- Below the binding threshold, a lower low payment and a larger success944probability strictly improve the zero-high-payment contract. -/945theorem slackPayoffIncreases (h h' lo lo' X L C : R) (hx : L<X)946    (prob : h<h') (hh : h'<1) (wage : lo'≤lo) (limited : 0≤lo) :947    L+h*(X-L)-(1-h)*lo-C < L+h'*(X-L)-(1-h')*lo'-C := by948  have gain := OrderedRing.mul_pos (a := h'-h) (by grind) (b := X-L) (by grind)949  have w1 := OrderedRing.mul_le_mul_of_nonneg_left wage (c := 1-h') (by grind)950  have w2 := OrderedRing.mul_nonneg (a := h'-h) (by grind) limited951  grind952953theorem slopeAtMaximum {f : R → R} {x d : R} (hx : 0<x) (hmax : Maximizes f x)954    (D : HasSlopeAt f x d) : d=0 := by955  by_cases pos : 0<d956  · obtain ⟨w,hw,H⟩ := slopeSides D pos957    obtain ⟨t,ht,h1,_⟩ := shortStep w w hw hw958    have := (H (x+t) (by grind) (by grind) (by grind)).2 (by grind)959    have := hmax.2 (x+t) (by grind); grind960  · by_cases neg : d<0961    · obtain ⟨w,hw,H⟩ := D (-d) (by grind)962      obtain ⟨t,ht,h1,h2⟩ := shortStep w x hw hx963      obtain ⟨v,hv,_,hvr⟩ := H (x-t) (by grind) (by grind) (by grind) (by grind)964      have hp := OrderedRing.mul_pos (a := -v) (by grind) ht965      have := hmax.2 (x-t) (by grind); grind966    · grind967968/-- The full-information supportive type strictly exceeds the other969type's support, from the common operating return and the marginal-cost970assumption. Shared maximizers are ruled out using interiority. -/971theorem fullInfoOrder (W C0 C1 d0 d1 : R → R) (f0 f1 marginal : R)972    (complete : CompleteSupport R) (c0 : ContinuousSupport C0) (c1 : ContinuousSupport C1)973    (dC : ∀ x, 0<x → HasSlopeAt C0 x (d0 x) ∧ HasSlopeAt C1 x (d1 x) ∧ d1 x<d0 x)974    (h0 : 0<f0) (op0 : Maximizes (fun x => W x-C0 x) f0)975    (op1 : Maximizes (fun x => W x-C1 x) f1) (der : HasSlopeAt W f0 marginal) : f0<f1 := by976  have ⟨der0,der1,cheaper⟩ := dC f0 h0977  have d := slopeAtMaximum h0 op0 (slopeSub der der0)978  by_cases eqn : f0=f1979  · subst f1980    have h := slopeAtMaximum h0 op1 (slopeSub der der1)981    grind982  · by_cases rev : f1<f0983    · have cross := boardSingleCrossing W C0 C1 d0 d1 complete c0 c1 dC f1 f0 op1.1 rev984      have h := op1.2 f0 (le_of_lt h0)985      have h' := op0.2 f1 op1.1986      grind987    · grind988989/-- Pure separation on feasible supports only. Tests every nonnegative990deviation under threshold beliefs and every other feasible separating pair. -/991theorem feasibleSeparation (V0 V1 : R → R) (f0 f1 b : R)992    (hb : 0<b) (h01 : f0<f1) (best0 : Maximizes V0 f0) (best1 : Maximizes V1 f1)993    (unique0 : ∀ x, 0≤x → x≠f0 → V0 x<V0 f0)994    (unique1 : ∀ x, 0≤x → x≠f1 → V1 x<V1 f1)995    (tail0 : ∀ x y, f0≤x → x<y → V0 y<V0 x)996    (tail1 : ∀ x y, f1≤x → x<y → V1 y<V1 x)997    (cross : ∀ x y, 0≤x → x<y → V1 x-V0 x < V1 y-V0 y)998    (cont : ContinuousSupport (fun x => V0 f0-V0 x))999    (coercive : ∃ u, f1<u ∧ b<V0 f0-V0 u) (complete : CompleteSupport R) :1000    ∃ z, f1≤z ∧ V0 z+b≤V0 f0 ∧ (f1<z → V0 z+b=V0 f0) ∧1001      (∀ x, 0≤x → (x<z → V0 x≤V0 f0 ∧ V1 x≤V1 z+b) ∧1002        (z≤x → V0 x+b≤V0 f0 ∧ V1 x+b≤V1 z+b)) ∧1003      (∀ l h, 0≤l → 0≤h → l≠h → V0 f0≤V0 l → V0 h+b≤V0 l → V1 l≤V1 h+b →1004        l=f0 ∧ l<h ∧ (h≠z → V1 h<V1 z)) := by1005  obtain ⟨z,hz,ic,binds,_⟩ := separatingSignalExists (fun x => V0 f0-V0 x) f1 b best1.11006    coercive (by intro x y hfx hxy; have := tail0 x y (by grind) hxy; grind) cont complete1007  refine ⟨z,hz,by grind,(by intro h; have := binds h; grind),?_,?_⟩1008  · intro x hx1009    have m0 := best0.2 x hx1010    have m1 := best1.2 x hx1011    constructor1012    · intro _1013      by_cases eqn : f1=z1014      · grind1015      · have h := binds (by grind)1016        have C := cross f1 z best1.1 (by grind)1017        have := best0.2 f1 best1.11018        grind1019    · intro hzx1020      by_cases eqn : z=x1021      · grind1022      · have := tail0 z x (by grind) (by grind)1023        have := tail1 z x hz (by grind)1024        grind1025  · intro l h hl hh distinct dev i0 i11026    have lf : l=f0 := by by_cases eqn : l=f0; exact eqn; have := unique0 l hl eqn; grind1027    have lh : l<h := by1028      by_cases rev : h<l1029      · have := cross h l hh rev; grind1030      · grind1031    refine ⟨lf,lh,?_⟩1032    intro hn1033    by_cases eqn : f1=z1034    · have := unique1 h hh (by grind); grind1035    · have H := binds (by grind)1036      by_cases rev : h<z1037      · have := tail0 h z (by grind) rev; grind1038      · exact tail1 z h hz (by grind)10391040/-- The other one-sided effort optimality condition follows by reflecting1041the effort interval. It also tests zero effort against an upward deviation. -/1042theorem effortKKTup (v ψ lo hi e : R) (hψ : 0<ψ) (he : 0≤e) (he1 : e<1)1043    (opt : ∀ x, 0≤x → x≤1 →1044      2*v*(hi-lo)*x-ψ*x*x ≤ 2*v*(hi-lo)*e-ψ*e*e) :1045    v*(hi-lo) ≤ ψ*e := by1046  have H := effortKKT 1 ψ 0 (ψ-v*(hi-lo)) (1-e) hψ (by grind) (by grind) (by1047    intro x hx hx11048    have := opt (1-x) (by grind) (by grind)1049    grind)1050  grind10511052/-- Every pair of truthful effort equilibria under one potentially optimal1053contract coincides. Effort and the ICs are allowed to be at an endpoint.1054The cost bounds are uniform, and are independent of support and controls. -/1055theorem uniqueAffordableEffort (α p a0 ψ X L lo hi K x y rx ry d : R)1056    (hα : 0<α) (floor : α=1-a0) (ha0 : 0<a0) (ha1 : a0<1)1057    (hp : 0<p) (hp1 : p<1) (hψ : 0<ψ) (hl : L<X) (hlo : 0≤lo) (cap : hi<X-L)1058    (large : 2*α*(X-L+1)≤ψ) (dDef : 2*d=1-a0)1059    (size : (α*p)*(α*p)*K<ψ*d*d)1060    (hx : 0≤x ∧ x≤1) (hy : 0≤y ∧ y≤1)1061    (r1 : rx<1 ∧ ry<1)1062    (bayesX : (1-(a0+α*x)*p)*rx=K) (bayesY : (1-(a0+α*y)*p)*ry=K)1063    (optX : ∀ t, 0≤t → t≤1 → 2*(α*p)*(hi+rx-lo)*t-ψ*t*t ≤ 2*(α*p)*(hi+rx-lo)*x-ψ*x*x)1064    (optY : ∀ t, 0≤t → t≤1 → 2*(α*p)*(hi+ry-lo)*t-ψ*t*t ≤ 2*(α*p)*(hi+ry-lo)*y-ψ*y*y) : x=y := by1065  have hd : 0<d := by grind1066  let v := α*p1067  let u := 1-a0*p1068  have bounds (e r : R) (he : 0≤e ∧ e≤1) (hr : r<1)1069      (op : ∀ t, 0≤t → t≤1 → 2*(α*p)*(hi+r-lo)*t-ψ*t*t ≤ 2*(α*p)*(hi+r-lo)*e-ψ*e*e) :1070      d≤u-v*e ∧ v*(hi-lo+r) ≤ ψ*e ∧ (0<e → ψ*e≤v*(hi-lo+r)) := by1071    have down (pos : 0<e) : ψ*e≤α*p*(hi-lo+r) := by1072      have := effortKKT (α*p) ψ lo (hi+r) e hψ pos he.2 op; grind1073    have small := optimalEffortLocalizes ψ α p X L hi lo r e hψ hα hp hp1 hl cap hlo hr large1074      (by by_cases pos : 0<e; exact Or.inr (down pos); exact Or.inl (by grind))1075    have D := localizedFailureFloor a0 p e ha0 ha1 hp hp1 he.1 (by grind)1076    have h := effortKKTup (α*p) ψ lo (hi+r) e hψ he.1 (by grind) op1077    have prod := congrArg (fun z => z*e*p) floor1078    dsimp [u,v]; grind1079  obtain ⟨dx,upX,downX⟩ := bounds x rx hx r1.1 optX1080  obtain ⟨dy,upY,downY⟩ := bounds y ry hy r1.2 optY1081  let f := u-v*x1082  let g := u-v*y1083  have fx : f*rx=K := by dsimp [f,u,v]; grind1084  have gy : g*ry=K := by dsimp [g,u,v]; grind1085  change d≤f at dx1086  change d≤g at dy1087  have h1 := OrderedRing.mul_le_mul_of_nonneg_left dx (le_of_lt hd)1088  have h2 := OrderedRing.mul_le_mul_of_nonneg_right dy (c := f) (by grind)1089  have h3 := OrderedRing.mul_le_mul_of_nonneg_left (show d*d≤f*g by grind) (le_of_lt hψ)1090  have sc : 0 < ψ*(f*g)-v*v*K := by change v*v*K<ψ*d*d at size; grind1091  have pos := OrderedRing.mul_pos (show 0<f by grind) (show 0<g by grind)1092  have df : f-g=v*(y-x) := by dsimp [f,g]; grind1093  have i1 := congrArg (fun z => v*g*z) fx1094  have i2 := congrArg (fun z => v*f*z) gy1095  have i3 := congrArg (fun z => v*K*z) df1096  by_cases lt : x<y1097  · have dY := downY (by grind)1098    have ineq := OrderedRing.mul_le_mul_of_nonneg_left1099      (show ψ*(y-x) ≤ v*(ry-rx) by grind) (le_of_lt pos)1100    have := OrderedRing.mul_pos sc (b := y-x) (by grind)1101    grind1102  · by_cases rev : y<x1103    · have dX := downX (by grind)1104      have ineq := OrderedRing.mul_le_mul_of_nonneg_left1105        (show ψ*(x-y) ≤ v*(rx-ry) by grind) (le_of_lt pos)1106      have := OrderedRing.mul_pos sc (b := x-y) (by grind)1107      grind1108    · grind11091110private theorem positiveAffineSlope {f : R → R} {x d : R} (a k : R) (hk : 0<k)1111    (F : HasSlopeAt f x d) : HasSlopeAt (fun y => a+k*f y) x (k*d) := by1112  intro ε hε1113  let t := ε/k1114  have h : t*k=ε := quotient _ _ hk1115  have ht : 0<t := by apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hk).mp; grind1116  obtain ⟨w,hw,H⟩ := F t ht1117  refine ⟨w,hw,?_⟩1118  intro y hy hl hr hn1119  obtain ⟨v,h1,h2,h3⟩ := H y hy hl hr hn1120  have l := OrderedRing.mul_lt_mul_of_pos_left h2 hk1121  have u := OrderedRing.mul_lt_mul_of_pos_left h3 hk1122  have id := congrArg (fun z => k*z) h11123  exact ⟨k*v,by dsimp only; grind,by grind,by grind⟩11241125private theorem slopeAdd {f g : R → R} {x p q : R} (hf : HasSlopeAt f x p) (hg : HasSlopeAt g x q) :1126    HasSlopeAt (fun y => f y+g y) x (p+q) := by1127  intro ε hε1128  have one := OrderedRing.zero_lt_one (R := R)1129  let t := ε/21130  have ht : t*2=ε := quotient ε 2 (by grind)1131  obtain ⟨d,hd,F⟩ := hf t (by grind)1132  obtain ⟨w,hw,G⟩ := hg t (by grind)1133  obtain ⟨δ,hδ,h1,h2⟩ := nearRadius d w hd hw1134  refine ⟨δ,hδ,?_⟩1135  intro y hy hl hr hn1136  obtain ⟨v,hv,hvl,hvr⟩ := F y hy (by grind) (by grind) hn1137  obtain ⟨z,hz,hzl,hzr⟩ := G y hy (by grind) (by grind) hn1138  exact ⟨v+z,by dsimp only; grind,by grind,by grind⟩11391140/-- Proposition 2 from the primitive success and cost functions, with1141the two maximizers and strict concavity as maintained in the manuscript.1142The proof derives interiority and the frictionless first-order condition. -/1143theorem mainSupportRanking (G B C dG dB dC : R → R) (β m X L fb s : R)1144    (hβ : 0<β) (hβ1 : β<1) (hm : 0<m) (cash : L<X)1145    (prob : ∀ x, 0≤x → 0<B x ∧ B x<G x ∧ G x<1)1146    (der : ∀ x, 0≤x → HasSlopeAt G x (dG x) ∧ HasSlopeAt B x (dB x) ∧ HasSlopeAt C x (dC x))1147    (prod : 0<dG 0 ∧ 0<dB 0) (cost0 : dC 0=0) :1148    let W := fun x => L+(X-L)*mix β (G x) (B x)-C x1149    let V := baselineValue W G B β m1150    Maximizes W fb → Maximizes V s →1151    (∀ a b c, 0≤a → a<b → b<c → (c-b)*V a+(b-a)*V c < (c-a)*V b) →1152    (G fb*dB fb < B fb*dG fb → s<fb) ∧ (B fb*dG fb < G fb*dB fb → fb<s) := by1153  let W := fun x => L+(X-L)*mix β (G x) (B x)-C x1154  let V := baselineValue W G B β m1155  change Maximizes W fb → Maximizes V s →1156    (∀ a b c, 0≤a → a<b → b<c → (c-b)*V a+(b-a)*V c < (c-a)*V b) → _1157  intro optW optV chord1158  change Maximizes W fb at optW1159  change Maximizes V s at optV1160  have D (x : R) (hx : 0≤x) : HasSlopeAt W x ((X-L)*(β*dG x+(1-β)*dB x)-dC x) := by1161    obtain ⟨g,b,c⟩ := der x hx1162    have mixSlope := slopeAdd (positiveAffineSlope 0 β hβ g) (positiveAffineSlope 0 (1-β) (by grind) b)1163    have h := slopeSub (positiveAffineSlope L (X-L) (by grind) mixSlope) c1164    have eqn : (fun y => L+(X-L)*((0+β*G y)+(0+(1-β)*B y))-C y)=W := by1165      funext y; dsimp [W,mix]; grind1166    exact eqn ▸ h1167  have hfb : 0<fb := by1168    by_cases h : 0<fb1169    · exact h1170    · have hz : fb=0 := by have := optW.1; grind1171      have gp := OrderedRing.mul_pos hβ prod.11172      have bp := OrderedRing.mul_pos (a := 1-β) (by grind) prod.21173      have pos := OrderedRing.mul_pos (a := X-L) (by grind)1174        (b := β*dG 0+(1-β)*dB 0) (by grind)1175      obtain ⟨w,hw,H⟩ := slopeSides (D 0 (by grind)) (by grind)1176      obtain ⟨t,ht,htw,_⟩ := shortStep w w hw hw1177      have := (H t (by grind) (by grind) (by grind)).2 ht1178      have := optW.2 t (le_of_lt ht)1179      grind1180  have zero := slopeAtMaximum hfb optW (D fb (le_of_lt hfb))1181  have crit : HasSlopeAt W fb 0 := zero ▸ D fb (le_of_lt hfb)1182  have quasi : Quasiconcave V := by1183    intro a b c y ha hab hbc hya hyc1184    have H := chord a b c ha hab hbc1185    have h1 := OrderedRing.mul_le_mul_of_nonneg_left hya (c := c-b) (by grind)1186    have h2 := OrderedRing.mul_le_mul_of_nonneg_left hyc (c := b-a) (by grind)1187    change (c-b)*V a+(b-a)*V c < (c-a)*V b at H1188    apply (Field.IsOrdered.mul_le_mul_iff_of_pos_left (show 0<c-a by grind)).mp1189    grind1190  obtain ⟨g,b,_⟩ := der fb (le_of_lt hfb)1191  exact scapegoating W G B β m fb s (dG fb) (dB fb) hβ hβ1 hm prob hfb crit g b quasi optV119211931194/-- Proposition 5 with the uniform outside option constructed from the1195future firm's increasing value and its supporting lines. The cutoff is1196the positive tangent gap at the zero-support posterior pair. -/1197theorem uniformWelfare (W P H L V g : R → R) (complete : CompleteSupport R)1198    (inc : ∀ r y, 0≤r → r<y → y≤1 → V r<V y)1199    (tan : ∀ r y, 0≤r → r≤1 → 0≤y → y≤1 → V r+g r*(y-r)≤V y)1200    (prob : ∀ x, 0≤x → 0<P x ∧ P x<1 ∧ 0<L x ∧ L x<H x ∧ H x<1)1201    (bayes : ∀ x y, 0≤x → 0≤y → P x*H x+(1-P x)*L x=P y*H y+(1-P y)*L y)1202    (nested : ∀ x y, 0≤x → x<y → P x<P y ∧ H x<H y ∧ L y<L x) :1203    ∃ J : R → R,1204      (∀ r y, 0≤r → r≤y → y≤1 → (y-r)*V r ≤ J y-J r ∧ J y-J r ≤ (y-r)*V y) ∧1205      let Γ := fun x => x*V x+J 1-J x1206      ∃ cutoff, 0<cutoff ∧ ∀ star fb dag m, 0≤star → star<fb → fb≤dag → 0<m → m<cutoff →1207        Maximizes W fb → Maximizes (fun x => silentValue W P (fun s => H s-L s) m x dag) dag →1208        let T := fun s => W s+hiringValue Γ P H L s1209        T star<T dag := by1210  obtain ⟨J,rect,Hire⟩ := uniformHiringFromValue V g complete inc tan1211  let Γ := fun x => x*V x+J 1-J x1212  let d := fun x => x*g x1213  have h0 := prob 0 (by grind)1214  have strict := (Hire (L 0) (H 0) (by grind) (by grind) (by grind) (by grind)).2 h0.2.2.2.11215  let gap := Γ (H 0)-Γ (L 0)-d (L 0)*(H 0-L 0)1216  change Γ (L 0)+d (L 0)*(H 0-L 0)<Γ (H 0) at strict1217  refine ⟨J,rect,gap,by dsimp [gap]; grind,?_⟩1218  intro star fb dag m hs hsf hfd hm small optW optD1219  have Hh := disclosureWelfare W P H L Γ d star fb dag m hs hsf hfd hm optW optD prob bayes nested1220    (by intro r y hr hr1 hy hy1; exact (Hire r y (by grind) (by grind) (by grind) (by grind)).1)1221    strict small1222  exact lt_of_lt_of_le Hh.1 Hh.2122312241225private theorem rationalSecant (V F G : R → R) (c d : R) (hc : 0≤c) (hg : 0<G c)1226    (cf : ContinuousSupport F) (cg : ContinuousSupport G) (atC : G c*d=F c)1227    (secant : ∀ x, 0≤x → 0<G x → G x*(V x-V c)=F x*(x-c)) : HasSlopeAt V c d := by1228  intro ε hε1229  have one := OrderedRing.zero_lt_one (R := R)1230  obtain ⟨A,hA,d1,d2⟩ := magnitude d1231  let h := G c/21232  have hhalf : h*2=G c := quotient _ _ (by grind)1233  have hp : 0<h := by grind1234  let η := (ε*h)/(A+1)1235  have ηeq : η*(A+1)=ε*h := quotient _ _ (by grind)1236  have ηpos : 0<η := by1237    apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right (show 0<A+1 by grind)).mp1238    have := OrderedRing.mul_pos hε hp; grind1239  obtain ⟨t,ht,h1,h2⟩ := nearRadius η h ηpos hp1240  obtain ⟨u,hu,U⟩ := cf c hc t ht1241  obtain ⟨w,hw,W⟩ := cg c hc t ht1242  obtain ⟨δ,hd,du,dw⟩ := nearRadius u w hu hw1243  refine ⟨δ,hd,?_⟩1244  intro x hx hl hr _1245  have fd := U x hx (by grind) (by grind)1246  have gd := W x hx (by grind) (by grind)1247  have gx : 0<G x := by grind1248  have noise := productBound (G x-G c) d t A ht hA (by grind) ⟨d1,d2⟩1249  have et := OrderedRing.mul_le_mul_of_nonneg_right h1 (c := A+1) (by grind)1250  have margin := OrderedRing.mul_lt_mul_of_pos_left (show h<G x by grind) hε1251  let v := F x/G x1252  have vv : v*G x=F x := quotient _ _ gx1253  have sv := secant x hx gx1254  have eq : V x-V c = v*(x-c) := by1255    have id := congrArg (fun z => z*(x-c)) vv1256    have zero : G x*((V x-V c)-v*(x-c))=0 := by grind1257    have id2 := congrArg (fun z => (G x)⁻¹*z) zero1258    have inv := Field.mul_inv_cancel (show G x≠0 by grind)1259    grind1260  refine ⟨v,eq,?_,?_⟩1261  · apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right gx).mp; grind1262  · apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right gx).mp; grind12631264/-- Actual first and second derivatives of the truthful Bayes spread as1265a function of effort. This verifies the differentiated identities used1266in the uniform curvature bound against the epsilon-delta definition. -/1267theorem spreadEffortDerivatives (K u v c : R) (hc : 0≤c) (hcF : 0<u-v*c) :1268    let F := fun x => u-v*x1269    let r := fun x => K/F x1270    let rE := fun x => v*K/(F x*F x)1271    HasSlopeAt r c (rE c) ∧ HasSlopeAt rE c ((2*v*v*K)/(F c*F c*F c)) := by1272  let F := fun x => u-v*x1273  let r := fun x => K/F x1274  let rE := fun x => v*K/(F x*F x)1275  have cf : ContinuousSupport F := continuousSub (continuousConst u) (continuousMul (continuousConst v) continuousId)1276  have pos : 0<F c := hcF1277  have psq := OrderedRing.mul_pos pos pos1278  have pcube := OrderedRing.mul_pos psq pos1279  have norm := quotient K (F c) pos1280  have normD := quotient (v*K) (F c*F c) psq1281  constructor1282  · apply rationalSecant r (fun _ => v*K) (fun x => F x*F c) c (rE c) hc psq1283      (continuousConst _) (continuousMul cf (continuousConst _)) (by dsimp [rE]; grind)1284    intro x _ h1285    have px : 0<F x := by by_cases H : 0<F x; exact H; have := OrderedRing.mul_le_mul_of_nonneg_right (show F x≤0 by grind) (le_of_lt pos); grind1286    have nx := quotient K (F x) px1287    have i1 := congrArg (fun z => F x*z) norm1288    have i2 := congrArg (fun z => F c*z) nx1289    have diff : F c-F x=v*(x-c) := by dsimp [F]; grind1290    have i3 := congrArg (fun z => K*z) diff1291    dsimp [r]; grind1292  · let N := fun x => v*v*K*(F c+F x)1293    let D := fun x => (F c*F c)*(F x*F x)1294    let d := (2*v*v*K)/(F c*F c*F c)1295    have cn : ContinuousSupport N := by1296      have inner := continuousSub (continuousConst (F c)) (continuousSub (continuousConst 0) cf)1297      have e : (fun x => F c-(0-F x))=(fun x => F c+F x) := by funext x; grind1298      rw [e] at inner1299      exact continuousMul (continuousConst _) inner1300    have cd : ContinuousSupport D := continuousMul (continuousConst _) (continuousMul cf cf)1301    have deq : d*(F c*F c*F c)=2*v*v*K := quotient _ _ pcube1302    apply rationalSecant rE N D c d hc (OrderedRing.mul_pos psq psq) cn cd1303    · have id := congrArg (fun z => F c*z) deq1304      dsimp [D,N]; grind1305    · intro x _ h1306      have g : F x*F x≠0 := by dsimp [D] at h; intro hn; rw [hn] at h; grind1307      have nx := Field.div_mul_cancel (x := v*K) g1308      have i1 := congrArg (fun z => (F x*F x)*z) normD1309      have i2 := congrArg (fun z => (F c*F c)*z) nx1310      have diff : F c-F x=v*(x-c) := by dsimp [F]; grind1311      have i3 := congrArg (fun z => v*K*(F c+F x)*z) diff1312      dsimp [D,N,rE]; grind131313141315/-- The board can restrict effort to [0,1/2]. This result instantiates1316the root and the binding optimizer with one set of support-independent1317sufficient size inequalities. The linear coefficient of the reduced1318payoff is bounded above by v times the operating surplus Q. -/1319theorem localizedBoardChoice (a0 α p m K ψ Q l c d : R)1320    (a : 0<a0 ∧ a0<1 ∧ α=1-a0) (prob : 0<p ∧ p<1)1321    (control : 0<m ∧ m<1) (k : 0<K ∧ K<1) (hQ : 0<Q) (hψ : 0<ψ)1322    (lin : l≤α*p*Q) (floor : 2*d=1-a0)1323    (largeRoot : 2≤ψ*d) (largeCurv : 1≤ψ*d*d*d)1324    (largeEnd : Q<ψ ∧ 1≤(ψ-Q)*d*d) (complete : CompleteSupport R) :1325    let u := 1-a0*p1326    let v := α*p1327    let cap : R := 1/21328    let U := fun e => c+l*e-ψ*e*e+K/(u-v*e)1329    ∃ e0 e, 0<e0 ∧ e0<cap ∧ ψ*e0*(u-v*e0)=(1-m)*v*K ∧1330      e0≤e ∧ e<cap ∧ ∀ x, e0≤x → x≤cap → x≠e → U x<U e := by1331  let u := 1-a0*p1332  let v := α*p1333  let cap : R := 1/21334  let f := u-v*cap1335  have one := OrderedRing.zero_lt_one (R := R)1336  have half : cap*2=1 := quotient 1 2 (by grind)1337  have hcap : 0<cap := by grind1338  have hd : 0<d := by grind1339  have hα : 0<α := by grind1340  have hv : 0<v := OrderedRing.mul_pos hα prob.11341  have hv1 : v<1 := by1342    have := OrderedRing.mul_lt_mul_of_pos_left prob.2 hα1343    dsimp [v]; grind1344  have dB := localizedFailureFloor a0 p cap a.1 a.2.1 prob.1 prob.2 (le_of_lt hcap) (by grind)1345  have αeq := congrArg (fun z => z*cap*p) a.2.21346  have low : d≤f := by dsimp [f,u,v]; grind1347  have hf : 0<f := by grind1348  have vK := OrderedRing.mul_lt_mul_of_pos_right hv1 k.11349  have vvK := OrderedRing.mul_lt_mul_of_pos_left (show v*K<1 by grind) hv1350  have mK := OrderedRing.mul_lt_mul_of_pos_right1351    (show 1-m<1 by grind) (OrderedRing.mul_pos hv k.1)1352  have Qv := OrderedRing.mul_lt_mul_of_pos_right hv1 hQ1353  have f2a := OrderedRing.mul_le_mul_of_nonneg_left low (le_of_lt hd)1354  have f2b := OrderedRing.mul_le_mul_of_nonneg_right low (le_of_lt hf)1355  have f2 : d*d≤f*f := by grind1356  have f3a := OrderedRing.mul_le_mul_of_nonneg_left low (le_of_lt (OrderedRing.mul_pos hd hd))1357  have f3b := OrderedRing.mul_le_mul_of_nonneg_right f2 (le_of_lt hf)1358  have uB := OrderedRing.mul_le_mul_of_nonneg_left low (le_of_lt hψ)1359  have root2 := congrArg (fun z => z*(ψ*f)) half1360  have ep : (1-m)*v*K<ψ*cap*f := by grind1361  obtain ⟨e0,he0,hec,hroot⟩ := boundaryExists ψ v m K u cap hcap hψ hv k.1 control.2 ep complete1362  have cB := OrderedRing.mul_le_mul_of_nonneg_left (show d*d*d≤f*f*f by grind) (le_of_lt hψ)1363  have C : v*v*K<ψ*f*f*f := by grind1364  have dB2 := OrderedRing.mul_le_mul_of_nonneg_left f2 (c := ψ-Q) (by grind)1365  change l≤v*Q at lin1366  have dB3 := OrderedRing.mul_le_mul_of_nonneg_right (show ψ-Q ≤ ψ-l by grind)1367    (le_of_lt (OrderedRing.mul_pos hf hf))1368  have half2 := congrArg (fun z => z*(ψ*f*f)) half1369  have E : (l-2*ψ*cap)*(f*f)+v*K < 0 := by grind1370  obtain ⟨e,he,he',opt⟩ := optimalBindingEffort ψ K u v l c e0 cap hψ hv he0 hec hf C E complete1371  exact ⟨e0,e,he0,hec,hroot,he,he',opt⟩13721373end Verification