Posterior.lean

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

1import Verification23open Std Lean.Grind Scapegoating4namespace Posterior56variable {R : Type} [Field R] [LE R] [LT R] [IsLinearOrder R] [LawfulOrderLT R] [OrderedRing R]78/-- Punctured limit along feasible support choices. -/9def Tends (c : R) (f : R → R) (l : R) : Prop :=10  ∀ ε, 0<ε → ∃ δ, 0<δ ∧ ∀ x, 0≤x → c-δ<x → x<c+δ → x≠c →11    l-ε<f x ∧ f x<l+ε1213private theorem smaller (a b : R) (ha : 0<a) (hb : 0<b) : ∃ t, 0<t ∧ t≤a ∧ t≤b := by14  by_cases h : a≤b15  · exact ⟨a,ha,by grind,h⟩16  · exact ⟨b,hb,by grind,by grind⟩1718private theorem positiveDivide (a b : R) (ha : 0<a) (hb : 0<b) : 0<a/b ∧ a/b*b=a := by19  have e := Field.div_mul_cancel (x := a) (show b≠0 by grind)20  refine ⟨?_,e⟩21  apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right hb).mp22  grind2324private theorem magnitude (x : R) : ∃ b, 0<b ∧ -b<x ∧ x<b := by25  by_cases h : 0≤x26  · exact ⟨x+1,by grind,by grind,by grind⟩27  · exact ⟨1-x,by grind,by grind,by grind⟩2829private theorem productBound (t b x y : R) (_ht : 0<t) (hb : 0<b)30    (hx : -t<x ∧ x<t) (hy : -b<y ∧ y<b) : -(t*b)<x*y ∧ x*y<t*b := by31  have i := OrderedRing.mul_lt_mul_of_pos_right hx.1 hb32  have j := OrderedRing.mul_lt_mul_of_pos_right hx.2 hb33  by_cases h : 0≤x34  · have a := OrderedRing.mul_le_mul_of_nonneg_left (le_of_lt hy.1) h35    have d := OrderedRing.mul_le_mul_of_nonneg_left (le_of_lt hy.2) h36    grind37  · have a := OrderedRing.mul_le_mul_of_nonpos_left (le_of_lt hy.1) (show x≤0 by grind)38    have d := OrderedRing.mul_le_mul_of_nonpos_left (le_of_lt hy.2) (show x≤0 by grind)39    grind4041private theorem constLimit (c k : R) : Tends c (fun _ => k) k := by42  intro ε h; exact ⟨ε,h,by grind⟩4344omit [IsLinearOrder R] [LawfulOrderLT R] [OrderedRing R] in45private theorem idLimit (c : R) : Tends c id c := by46  intro ε h; exact ⟨ε,h,by simp [id]; grind⟩4748private theorem subLimit {c a b : R} {f g : R → R} (hf : Tends c f a) (hg : Tends c g b) :49    Tends c (fun x => f x-g x) (a-b) := by50  intro ε h51  have ⟨ht,eq⟩ := positiveDivide ε 2 h (by grind)52  obtain ⟨u,hu,U⟩ := hf _ ht53  obtain ⟨v,hv,V⟩ := hg _ ht54  obtain ⟨δ,hδ,du,dv⟩ := smaller u v hu hv55  refine ⟨δ,hδ,?_⟩56  intro x hx hl hr hn57  have := U x hx (by grind) (by grind) hn58  have := V x hx (by grind) (by grind) hn59  grind6061theorem mulLimit {c a b : R} {f g : R → R} (hf : Tends c f a) (hg : Tends c g b) :62    Tends c (fun x => f x*g x) (a*b) := by63  intro ε h64  obtain ⟨A,hA,al,ar⟩ := magnitude a65  obtain ⟨B,hB,bl,br⟩ := magnitude b66  have ⟨ht,eq⟩ := positiveDivide ε (A+B+1) h (by grind)67  obtain ⟨t,hp,tw,t1⟩ := smaller _ 1 ht (by grind)68  obtain ⟨u,hu,U⟩ := hf t hp69  obtain ⟨v,hv,V⟩ := hg t hp70  obtain ⟨δ,hδ,du,dv⟩ := smaller u v hu hv71  refine ⟨δ,hδ,?_⟩72  intro x hx hl hr hn73  have f1 := U x hx (by grind) (by grind) hn74  have g1 := V x hx (by grind) (by grind) hn75  have := productBound t (B+1) (f x-a) (g x) hp (by grind) (by grind) (by grind)76  have := productBound t A (g x-b) a hp hA (by grind) ⟨al,ar⟩77  have := OrderedRing.mul_le_mul_of_nonneg_right tw (show 0≤A+B+1 by grind)78  grind7980theorem divLimit {c a b : R} {f g : R → R} (hf : Tends c f a) (hg : Tends c g b)81    (hb : 0<b) : Tends c (fun x => f x/g x) (a/b) := by82  have inverse : Tends c (fun x => 1/g x) (1/b) := by83    intro ε h84    obtain ⟨hp,half⟩ := positiveDivide b 2 hb (by grind)85    let t := ε*b*(b/2)86    have ht : 0<t := OrderedRing.mul_pos (OrderedRing.mul_pos h hb) hp87    obtain ⟨d,hd,ds,dh⟩ := smaller t _ ht hp88    obtain ⟨δ,hδ,D⟩ := hg d hd89    refine ⟨δ,hδ,?_⟩90    intro x hx hl hr hn91    have g1 := D x hx hl hr hn92    have gx : b/2<g x := by grind93    have pos := OrderedRing.mul_pos hb (show 0<g x by grind)94    have margin := OrderedRing.mul_lt_mul_of_pos_left gx (OrderedRing.mul_pos h hb)95    have i := Field.div_mul_cancel (x := (1:R)) (show b≠0 by grind)96    have j := Field.div_mul_cancel (x := (1:R)) (show g x≠0 by grind)97    have u := congrArg (fun z => z*g x) i98    have v := congrArg (fun z => z*b) j99    dsimp [t] at *100    constructor <;> apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right pos).mp <;> grind101  have p := mulLimit hf inverse102  have eq (x y : R) : x*(1/y)=x/y := by simp [Field.div_eq_mul_inv]; grind103  simpa only [eq] using p104105private def secant (f : R → R) (c x : R) := (f x-f c)/(x-c)106107private theorem secantEq (f : R → R) (c x : R) (h : x≠c) :108    secant f c x*(x-c)=f x-f c := Field.div_mul_cancel (by grind)109110private theorem secants {f : R → R} {c d : R} : HasSlopeAt f c d ↔ Tends c (secant f c) d := by111  constructor112  · intro H ε he113    obtain ⟨δ,hδ,D⟩ := H ε he114    refine ⟨δ,hδ,?_⟩115    intro x hx hl hr hn116    obtain ⟨v,eq,lo,hi⟩ := D x hx hl hr hn117    have eq' := secantEq f c x hn118    have vs : secant f c x=v := by119      have K := Field.mul_inv_cancel (show x-c≠0 by grind)120      have U := congrArg (fun z => z*(x-c)⁻¹) (show secant f c x*(x-c)=v*(x-c) by grind)121      grind122    grind123  · intro H ε he124    obtain ⟨δ,hδ,D⟩ := H ε he125    exact ⟨δ,hδ,fun x hx hl hr hn => ⟨_,(secantEq f c x hn).symm,D x hx hl hr hn⟩⟩126127theorem slopeLimit {f : R → R} {c d : R} (der : HasSlopeAt f c d) : Tends c f (f c) := by128  have dx := subLimit (idLimit c) (constLimit c c)129  have gap := mulLimit (secants.mp der) dx130  intro ε he131  obtain ⟨δ,hδ,D⟩ := gap ε he132  refine ⟨δ,hδ,?_⟩133  intro x hx hl hr hn134  have := D x hx hl hr hn135  have eq := secantEq f c x hn136  simp [id] at *137  grind138139/-- The derivative of a quotient, derived from the paper's one-sided feasible140secants at zero and two-sided secants at positive support. -/141theorem quotientSlope {f g : R → R} {c a b : R} (hf : HasSlopeAt f c a)142    (hg : HasSlopeAt g c b) (positive : 0<g c) :143    HasSlopeAt (fun x => f x/g x) c ((a*g c-f c*b)/(g c*g c)) := by144  have N := subLimit (mulLimit (secants.mp hf) (constLimit c (g c)))145    (mulLimit (constLimit c (f c)) (secants.mp hg))146  have D := mulLimit (slopeLimit hg) (constLimit c (g c))147  have L := divLimit N D (OrderedRing.mul_pos positive positive)148  intro ε he149  obtain ⟨u,hu,U⟩ := L ε he150  obtain ⟨v,hv,V⟩ := slopeLimit hg (g c) positive151  obtain ⟨δ,hδ,du,dv⟩ := smaller u v hu hv152  refine ⟨δ,hδ,?_⟩153  intro x hx hl hr hn154  have bounds := U x hx (by grind) (by grind) hn155  have gv := V x hx (by grind) (by grind) hn156  let k := (secant f c x*g c-f c*secant g c x)/(g x*g c)157  refine ⟨k,?_,bounds⟩158  have prod := OrderedRing.mul_pos (show 0<g x by grind) positive159  have ke : k*(g x*g c)=secant f c x*g c-f c*secant g c x :=160    Field.div_mul_cancel (by grind)161  have atX := Field.div_mul_cancel (x := f x) (show g x≠0 by grind)162  have atC := Field.div_mul_cancel (x := f c) (show g c≠0 by grind)163  have A := congrArg (fun z => z*g c) atX164  have B := congrArg (fun z => z*g x) atC165  have E := congrArg (fun z => z*(x-c)) ke166  have F := congrArg (fun z => z*g c) (secantEq f c x hn)167  have G := congrArg (fun z => z*(f c)) (secantEq g c x hn)168  apply le_antisymm <;> apply (Field.IsOrdered.mul_le_mul_iff_of_pos_right prod).mp <;> grind169170theorem continuousOfDerivatives {f : R → R} (h : ∀ c, 0≤c → ∃ d, HasSlopeAt f c d) :171    ContinuousSupport f := by172  intro c hc ε he173  obtain ⟨d,D⟩ := h c hc174  obtain ⟨δ,hδ,U⟩ := slopeLimit D ε he175  refine ⟨δ,hδ,?_⟩176  intro x hx hl hr177  by_cases eq : x=c178  · rw [eq]; grind179  · exact U x hx hl hr eq180181182theorem affineSlope {f g : R → R} {c d e : R} (a b k : R)183    (hf : HasSlopeAt f c d) (hg : HasSlopeAt g c e) :184    HasSlopeAt (fun x => a*f x+b*g x+k) c (a*d+b*e) := by185  have L := subLimit (mulLimit (constLimit c a) (secants.mp hf))186    (mulLimit (constLimit c (-b)) (secants.mp hg))187  intro ε he188  obtain ⟨δ,hδ,D⟩ := L ε he189  refine ⟨δ,hδ,?_⟩190  intro x hx hl hr hn191  have bounds := D x hx hl hr hn192  have F := congrArg (fun z => a*z) (secantEq f c x hn)193  have G := congrArg (fun z => b*z) (secantEq g c x hn)194  exact ⟨a*secant f c x+b*secant g c x, by grind, by grind, by grind⟩195196/-- Derivatives of both Bayesian posteriors under either interaction between support and type. -/197theorem bayesDerivatives (G B : R → R) (β c dG dB : R)198    (prior : 0<β ∧ β<1) (tech : 0<B c ∧ B c<G c ∧ G c<1)199    (dg : HasSlopeAt G c dG) (db : HasSlopeAt B c dB) :200    let P := fun x => mix β (G x) (B x)201    let H := fun x => highRep β (G x) (P x)202    let F := fun x => lowRep β (G x) (P x) 1203    ∃ dH dF, HasSlopeAt H c dH ∧ HasSlopeAt F c dF ∧204      HasSlopeAt (fun x => H x-F x) c (dH-dF) ∧205      P c*P c*dH=β*(1-β)*(B c*dG-G c*dB) ∧206      (1-P c)*(1-P c)*dF=β*(1-β)*((1-G c)*dB-(1-B c)*dG) := by207  let P := fun x => mix β (G x) (B x)208  let dp := β*dG+(1-β)*dB209  have ⟨_,_,p0,p1⟩ := probabilityBounds β (G c) (B c) 1 prior.1 prior.2 tech.1 tech.2.1 tech.2.2210    OrderedRing.zero_lt_one (by grind)211  have hp : 0<P c := by dsimp [P]; grind212  have hq : 0<1-P c := by dsimp [P]; grind213  have pd : HasSlopeAt P c dp := by214    simpa [P,mix,dp,Semiring.add_zero] using affineSlope β (1-β) 0 dg db215  have gd : HasSlopeAt (fun x => β*G x) c (β*dG) := by216    simpa [Semiring.zero_mul,Semiring.add_zero] using affineSlope β 0 0 dg db217  have fd : HasSlopeAt (fun x => β*(1-G x)) c (-(β*dG)) := by218    have funEq : (fun x => -β*G x+0*B x+β)=(fun x => β*(1-G x)) := by funext x; grind219    rw [← funEq]220    have e : -β*dG+0*dB=-(β*dG) := by grind221    rw [← e]222    exact affineSlope (-β) 0 β dg db223  have qd : HasSlopeAt (fun x => 1-P x) c (-dp) := by224    have e : (fun x => (-1)*P x+0*P x+1)=(fun x => 1-P x) := by funext x; grind225    rw [← e]226    have t : (-1)*dp+0*dp = -dp := by grind227    rw [← t]228    exact affineSlope (-1) 0 1 pd pd229  have hi := quotientSlope gd pd hp230  have lo := quotientSlope fd qd hq231  let dh := ((β*dG)*P c-(β*G c)*dp)/(P c*P c)232  let dl := ((-(β*dG))*(1-P c)-(β*(1-G c))*(-dp))/((1-P c)*(1-P c))233  have eH := Field.div_mul_cancel (x := (β*dG)*P c-(β*G c)*dp)234    (show P c*P c≠0 by have := OrderedRing.mul_pos hp hp; grind)235  have eL := Field.div_mul_cancel (x := (-(β*dG))*(1-P c)-(β*(1-G c))*(-dp))236    (show (1-P c)*(1-P c)≠0 by have := OrderedRing.mul_pos hq hq; grind)237  have hH : P c*P c*dh=β*(1-β)*(B c*dG-G c*dB) := by238    change dh*(P c*P c)=_ at eH239    dsimp [P,mix,dp] at *; grind240  have hL : (1-P c)*(1-P c)*dl=β*(1-β)*((1-G c)*dB-(1-B c)*dG) := by241    change dl*((1-P c)*(1-P c))=_ at eL242    dsimp [P,mix,dp] at *; grind243  have H : HasSlopeAt (fun x => highRep β (G x) (P x)) c dh := hi244  have F : HasSlopeAt (fun x => lowRep β (G x) (P x) 1) c dl := by245    simpa only [lowRep,Semiring.one_mul] using lo246  exact ⟨dh,dl,H,F,Verification.slopeSub H F,hH,hL⟩247248249/-- Lemma A2 from primitive production derivatives. The denominator-cleared250expressions and strict signs are conclusions rather than assumed derivatives. -/251theorem posteriorDerivatives (G B : R → R) (β c dG dB : R)252    (prior : 0<β ∧ β<1) (tech : 0<B c ∧ B c<G c ∧ G c<1)253    (dg : HasSlopeAt G c dG) (db : HasSlopeAt B c dB)254    (prod : 0<dB) (comp : G c*dB<B c*dG) :255    let P := fun x => mix β (G x) (B x)256    let H := fun x => highRep β (G x) (P x)257    let F := fun x => lowRep β (G x) (P x) 1258    ∃ dH dF, HasSlopeAt H c dH ∧ HasSlopeAt F c dF ∧259      HasSlopeAt (fun x => H x-F x) c (dH-dF) ∧260      P c*P c*dH=β*(1-β)*(B c*dG-G c*dB) ∧261      (1-P c)*(1-P c)*dF=β*(1-β)*((1-G c)*dB-(1-B c)*dG) ∧262      0<dH ∧ dF<0 ∧ 0<dH-dF := by263  obtain ⟨dh,df,H,F,D,hH,hF⟩ := bayesDerivatives G B β c dG dB prior tech dg db264  exact ⟨dh,df,H,F,D,hH,hF,posteriorSlopes β (G c) (B c) dG dB _ dh df prior.1 prior.2265    tech.1 tech.2.1 tech.2.2 prod comp rfl hH hF⟩266267theorem affineLimit {f g : R → R} {c p q : R} (a b k : R) (F : Tends c f p) (G : Tends c g q) :268    Tends c (fun x => a*f x+b*g x+k) (a*p+b*q+k) := by269  have H := subLimit (subLimit (mulLimit (constLimit c a) F) (mulLimit (constLimit c (-b)) G)) (constLimit c (-k))270  intro ε he271  obtain ⟨δ,hδ,D⟩ := H ε he272  refine ⟨δ,hδ,?_⟩273  intro x hx hl hr hn274  have := D x hx hl hr hn275  grind276277theorem identitySlope (c : R) : HasSlopeAt (fun x : R => x) c 1 := by278  intro ε he279  exact ⟨ε,he,fun x _ _ _ _ => ⟨1,by grind,by grind,by grind⟩⟩280281theorem mulSlope {f g : R → R} {c p q : R} (F : HasSlopeAt f c p) (G : HasSlopeAt g c q) :282    HasSlopeAt (fun x => f x*g x) c (p*g c+f c*q) := by283  have L := affineLimit 1 1 0 (mulLimit (secants.mp F) (slopeLimit G))284    (mulLimit (constLimit c (f c)) (secants.mp G))285  intro ε he286  obtain ⟨δ,hδ,D⟩ := L ε he287  refine ⟨δ,hδ,?_⟩288  intro x hx hl hr hn289  have bounds := D x hx hl hr hn290  have ff := congrArg (fun z => z*g x) (secantEq f c x hn)291  have gg := congrArg (fun z => f c*z) (secantEq g c x hn)292  exact ⟨secant f c x*g x+f c*secant g c x,by grind,by grind,by grind⟩293294/-- Continuity of the selected root follows from a positive lower bound295on its difference quotient in the effort direction. -/296theorem implicitLimit {y A D : R → R} {c d δ0 : R} (der : HasSlopeAt A c d) (pos : 0<δ0)297    (bound : ∀ x, 0≤x → δ0≤D x) (eq : ∀ x, 0≤x → (y x-y c)*D x=A x-A c) :298    Tends c y (y c) := by299  intro ε he300  obtain ⟨δ,hδ,U⟩ := slopeLimit der (ε*δ0) (OrderedRing.mul_pos he pos)301  refine ⟨δ,hδ,?_⟩302  intro x hx hl hr hn303  have B := bound x hx304  have b := OrderedRing.mul_le_mul_of_nonneg_left B (le_of_lt he)305  have Dp : 0<D x := by grind306  have s := eq x hx307  have h := U x hx hl hr hn308  constructor <;> apply (Field.IsOrdered.mul_lt_mul_iff_of_pos_right Dp).mp <;> grind309310theorem implicitSlope {y A D : R → R} {c d : R} (der : HasSlopeAt A c d)311    (cont : Tends c D (D c)) (dc : 0<D c) (pos : ∀ x, 0≤x → 0<D x)312    (eq : ∀ x, 0≤x → (y x-y c)*D x=A x-A c) : HasSlopeAt y c (d/D c) := by313  have L := divLimit (secants.mp der) cont dc314  intro ε he315  obtain ⟨δ,hδ,U⟩ := L ε he316  refine ⟨δ,hδ,?_⟩317  intro x hx hl hr hn318  have k := U x hx hl hr hn319  have de := Field.div_mul_cancel (x := secant A c x) (show D x≠0 by have := pos x hx; grind)320  have t := congrArg (fun z => z*(x-c)) de321  have h := secantEq A c x hn322  have z := eq x hx323  refine ⟨secant A c x/D x,?_,k⟩324  apply le_antisymm <;> apply (Field.IsOrdered.mul_le_mul_iff_of_pos_right (pos x hx)).mp <;> grind325end Posterior