goodC:∀ a b,(p.gate (a,b)).v=p.truef a.v b.v
sturdy:∀ {d:ℕ},1≤ d →∀ {x y z w:ℝ},
|x| ≤2*massB i d → |y| ≤2*massB j d → |z| ≤2*massB i d → |w| ≤2*massB j d →
|p.truef x y-p.truef z w| ≤ massB e d*(|x-z|+|y-w|)
defuPair (p:Bid)(k:Knob)(i j o e:ℕ)(f g:Cog):Meld:=
body · 5
lines
letM:=e+i+j+6
{ P:={ n:=fun _=>⟨_,Kn.fix 1⟩, route:=fun _=>⟨_,Kn.first⟩,
margin:=⟨fun x a=>M*k.height.f x a, (Kn.fix _).times k.height.runs⟩,
scans:=fun b=>if b then f else g }
f:=⟨_,p.remoteK k i j o⟩ }
lemmabehold {x y:ℝ}{d :ℕ}(s:0< d) (e i j o:ℕ) (u:p.Fit e i j)
(he:|x| ≤ massB i d)(ht:|y| ≤ massB j d)
{a b:ℝ}(hi:|a-x/massB i d| ≤1)(hk:|b-y/massB j d| ≤1):
|p.truef (a*massB i d) (b*massB j d)/massB o d - p.truef x y/massB o d| ≤
massB (e+i+j) d*(|a-x/massB i d|+|b-y/massB j d|):=by
proof · 28
lines
letI:=massB i d; letJ:=massB j d
have hh1:=mass0 i d; have hh2:=mass0 j d
let v:= |a-x/I|; let w:=|b-y/J|
haveh1: |a*I-x|=I*v:=by
unfold I v; rw [show a*I-x=I*(a-x/I) fromby unfold I; field_simp]
rw [abs_mul,abs_of_pos hh1]
haveh2: |b*J-y|=J*w:=byhavehe':b*J-y=J*(b-y/J):=by unfold J; field_simp
rw [he',abs_mul]; exact congrArg (fun t=> t*w) (abs_of_pos hh2)
haveha: |a*I| ≤2*I:=by
change v ≤1 at hi; change 0<I at hh1; change |x| ≤I at he
have hh:= abs_add_le (a*I-x) x
rw [sub_add_cancel] at hh; nlinarith
havehb:|b*J| ≤2*J:=by
change w ≤1 at hk; change 0<J at hh2; change |y| ≤J at ht
have hh:= abs_add_le (b*J-y) y; rw [sub_add_cancel] at hh; nlinarith
have hz:=u.sturdy s ha hb (le_trans he (by linarith)) (le_trans ht (by linarith))
rw [←sub_div,abs_div,abs_of_pos (mass0 o d)]
apply le_trans (div_le_self (abs_nonneg _) (mass1 o d))
apply le_trans hz
rw [h1,h2, mass_mul,mass_mul]
haveht : 1≤I:= mass1 ..; havehp:1≤J:=mass1 ..
change massB e d*(I*v+J*w) ≤ massB e d*I*J*(v+w)
rw [show massB e d*I*J*(v+w)=massB e d*(I*J*(v+w)) by ring]
apply mul_le_mul_of_nonneg_left _ (mass0 e d).le
havehv:0≤I*v:=mul_nonneg (by unfold I; positivity) (abs_nonneg _)
havehx0:0≤J*w:=mul_nonneg (by unfold J; positivity) (abs_nonneg _)
nlinarith
lemmajoint {s:Port}{k i j o e c H f g VX} (h: Align s k) (he:p.Fit e i j) (hc:1≤ c)
(h1:Ears s c (H+(e+i+j+6)*s.d) i f V)(h2:Ears s c (H+(e+i+j+6)*s.d) j g X)
(hv:|p.truef VX| ≤ massB o s.d) :
Ears s (powder (Oven.price (joinCost e i j c))) H o (p.uPair k i j o e f g).cooked (p.truef VX):=by
proof · 35
lines
have ha:=amplitude h1; have hb:=amplitude h2
obtain ⟨w,h1⟩:=h1; obtain ⟨b,h2⟩:=h2
let d:=s.d; havehd:1≤ s.d:=h.1.1let q:=p.uPair k i j o e f g
letf0:Rill.EV:=fun t _=>if t thenV/massB i d elseX/massB j d
letg0:Rill.DW:=fun t _=>if t then w else b
letC:=joinCost e i j c
havehC:C≥100∧ c ≤C:=by unfold C joinCost; omega
havehM : q.P.margin.f s.l.x s.info=(e+i+j+6)*s.d:=by simp [q,uPair,h.2.1]
havehe0:q.P.Thaw s CH g0 f0:=by
refine ⟨hC.1,h.1,?_,?_,?_⟩
· rw [hM]; unfold C joinCost; exact Nat.mul_le_mul_right s.d (by omega)
· intro b; change 1<2^(C*s.d); have hz:=growing (C*s.d); nlinarith
intro b i hi; cases b
· havehu: q.P.scans false=g:=by simp [q,uPair]
rw [hu, Oven.ext,hM]; exact fewer h2 hc hC.2 le_rfl
· havehu:q.P.scans true=f:=by simp [q,uPair]
rw [hu,Oven.ext,hM]; exact fewer h1 hc hC.2 le_rfl
havehl : q.Lip s (massB (e+i+j) s.d) (p.truef VX/massB o s.d) f0:=by
refine ⟨by rw [abs_div,abs_of_pos (mass0 ..)]; exact (div_le_one (mass0 ..)).2 hv,
mass1 ..,?_,fun x y hs hz=>?_⟩
· rw [hM]; let n:=e+i+j
change massB n s.d*4*3≤ massB (n+6) s.d
rw [mass_mul n 6]; havehh : 12≤ massB 6 s.d:=by
unfold massB
calc
(12:ℝ) ≤2^(6:ℕ):=by norm_num
_ ≤ _:=pow_le_pow_right₀ (by norm_num) (by omega)
have hp:=mass0 n s.d; rw [mul_assoc]; exact mul_le_mul_of_nonneg_left (by linarith) hp.le
· havehx:q.tally s f0 true=V/massB i s.d:=by simp [q,Meld.tally,Oven.labels,uPair,f0,d]
haveht:q.tally s f0 false=X/massB j s.d:=by simp [q,Meld.tally,Oven.labels,uPair,f0,d]
rw [hx] at hs; rw [ht] at hz; rw [hx,ht]
simp only [q,uPair,remote,Coin.mul0,Coin.inv0,he.goodC,scalen h,← div_eq_mul_inv]
exact behold _ hd _ _ _ _ he ha hb hs hz
exact ⟨_,q.stream s he0 hl⟩
| .plus=>fun x y=>x+y
| .minus=>fun x y=>x-y
| .prod=>fun x y=>x*y
| .lesser=>fun x y=> min x y
| .greater=>fun x y=>max x y
| .flip=>fun x _=>(max x 1)⁻¹
letq:History:=dec a.1let u:=p.store.f x q.1let s:=Coin.ofZ ((min u (2^q.2):ℕ):ℤ)
Coin.mult s (Coin.mult (f.f x (q.1,a.2.2)) (Coin.inv (scaleC p i x q.1)))
lemmaeach0 (p:Knob)(f:CubCoinQueryCoin)(i:ℕ)(s:Port)(H)(ha:Align s p)
(hl:Live s p H){v}(hv:(f.f s.l.x (s.info,s.src)).v=v)
(he:|v| ≤ massB i s.d):
s.Feeds (solo p f i) (powder 100) H (tapeR p f i s) (v/massB i s.d):=by
proof · 19
lines
apply lifting ha.1 (by omega)
· intro t ht
refine .edit rfl (s.stale ha.1 t _ (by omega)) (s.alone ha.1 t 100 ?_ ?_)
· omega
have h1:=lb_mono (rangeQ (tapeR p f i s t))
rw [show lb 31=5by rfl] at h1; omega
refine ⟨by rw [abs_div,abs_of_pos (mass0 ..)]; exact (div_le_one (mass0 ..)).2 he,
fun t ht=>?_⟩
let u:=tapeR p f i s t
have hg:=Coin.floorok (center p f i s.l.x (postcard s.info t,0,s.src))
havehz : 2^t ≤ p.store.f s.l.x s.info:= le_trans (Nat.pow_le_pow_right Nat.zero_lt_two ht) hl
let g:= center p f i s.l.x (postcard s.info t,0,s.src)
change (u:ℝ) ≤ g.v ∧ g.v ≤ (u:ℝ)+1 at hg
havehp:g.v=(2:ℝ)^t*(v/massB i s.d):=by
unfold g center; simp only [postcard,Wire.eq,Coin.mul0,Coin.ofv,Coin.inv0,hv,scalen ha,
div_eq_mul_inv]; push_cast
rw [min_eq_right (by exact_mod_cast hz)]
rw [hp] at hg
rw [abs_le]; unfold u at hg; constructor <;>linarith
lemmalease {s:Port}{VH c i f}(h:p.Trust s i V c H f)(hc:1≤ c)(ho:s.OK):
Ears s (powder (Survey.priceB (c+p.e+100))) H i (p.bowl f).poll (rank (p.S s) V (p.key s)):=by
proof · 19
lines
classical
have hh(j): ∃ w,j∈p.S s → (p.port s j).Feeds f c H w (V j/massB i s.d):=byby_cases ht:j∈p.S s
· obtain ⟨w,hx⟩:=h.tick j ht; exact ⟨w,fun _=>hx⟩
exact ⟨fun _=>0,fun hz=> (ht hz).elim⟩
choose w hw using hh
let u:=p.bowl f
letW:=fun (j:ℕ)=>V j/massB i s.d
havehz : u.Clue s (c+p.e+100) HW w:=by
refine ⟨by omega,ho,?_ ,fun j hj=>fewer (hw j (mem_range.2 hj)) hc (by omega) le_rfl⟩
apply h.cheaply.trans_le (Nat.pow_le_pow_right Nat.zero_lt_two ?_)
gcongr; omega
let v:=massB i s.d
havehs:rank (p.S s) W (p.key s)=rank (p.S s) V (p.key s)/v:=byhavehm:W=(fun j=>v⁻¹*V j):=funext fun _=>by unfold v W; ring
rw [hm,scaled_rank (by unfold v; positivity)]; ring
haveht: Ears s (powder (Survey.priceB (c+p.e+100))) H i u.poll (rank (p.S s) V (p.key s)) :=by
unfold Ears; rw [← hs]; exact ⟨_, hz.tasked⟩
exact ht
let o:=r+p.e
letM:=p.e+6let even1 (x:Word)(a:Bid.arm):Coin:=Coin.mult (Coin.mult a.2.1 (scaleC k r x a.1))
(Coin.inv (scaleC k o x a.1))
havehe:Kn even1 :=Coin.multK
(Coin.multK Kn.next.left ((scaleK k r).comp Kn.first))
(Coin.invK ((scaleK k o).comp Kn.first))
{ P:={ n:=fun b=>if b then p.n else ⟨_,Kn.fix 0⟩, route:=fun _=>p.route,
margin:=⟨fun x a=>M*k.height.f x a,(Kn.fix _).times k.height.runs⟩,scans:=fun _=>f }
f:=⟨_,he⟩ }
lemmapoem {s:Port}{VH c i f k}
(h:p.Trust s i V c (H+p.reserve*s.d) f)(hc:1≤ c)(ho:Align s k) :
Ears s (powder (Oven.price (p.foldC c))) H (i+p.e) ((p.collect f k i).cooked) (∑ j∈p.S s, V j):=by
proof · 57
lines
classical
let u:=p.collect f k i
letC:=p.foldC c
let o:=i+p.e
letD:=massB i s.d
letB:=massB o s.d
havehA:0<D:=mass0 i s.d
havehB:0<B:=mass0 o s.d
letW:Rill.EV:=fun b j=>V j/Dhavehk:C≥p.reserve∧C≥100∧ c ≤C:=by unfold C reserve foldC; omega
have hN(q:Bool) : u.P.labels s q ≤ p.n.f s.l.x s.info :=by cases q <;> simp [Oven.labels,u,collect]
have hs(b:Bool)(j):∃ w,(j<u.P.labels s b) → (u.P.rel s b j).Feeds (u.P.scans b) c (H+p.reserve*s.d) w (W b j):=byby_cases ht:j<u.P.labels s b
· obtain ⟨w,h0⟩:=h.tick j (mem_range.2 (ht.trans_le (hN b)))
exact ⟨w,fun _=>h0⟩
exact ⟨fun _=>0,fun hz=> (ht hz).elim⟩
choose w hw using hs
havehe0:u.P.margin.f s.l.x s.info=p.reserve*s.d:=by
simp [u,collect,reserve,ho.2.1]
havehe:u.P.Thaw s CH w W:=by
refine ⟨hk.2.1,ho.1,by rw [he0]; exact Nat.mul_le_mul_right _ hk.1,?_,?_⟩
· intro b; apply lt_of_le_of_lt (hN b)
apply h.cheaply.trans_le
exact Nat.pow_le_pow_right Nat.zero_lt_two (Nat.mul_le_mul_right _ (by unfold C foldC; omega))
intro b i h; unfold Oven.ext; rw [he0]; exact fewer (hw b i h) hc hk.2.2 le_rfl
let m:=p.n.f s.l.x s.info
let v:=∑ j∈p.S s, V j
have hi(Den):0 < massB Den s.d:= mass0 ..
havehb:B=D*massB p.e s.d:= mass_mul ..
havehr:m < massB p.e s.d:=by unfold massB; exact_mod_cast h.cheaply
havehl : u.Lip s 1 (v/B) W:=by
refine ⟨?_,le_rfl,?_,fun x y hx hy=>?_⟩
· rw [abs_div,abs_of_pos hB,div_le_one hB]
apply le_trans (abs_sum_le_sum_abs .. )
havehz:∑ j∈p.S s, |V j| ≤∑ _∈p.S s,D:=by
exact sum_le_sum fun j hz=>amplitude (p:=p.port s j) (h.tick j hz)
apply hz.trans; simp [S,m] at *
rw [hb]; nlinarith
· rw [he0]; simp [u,collect,Oven.labels,m] at *
unfold reserve; rw [add_mul,pow_add]; unfold massB at hr
havehv: (16:ℝ) ≤ (2:ℝ)^(6*s.d):=calc
_ ≤ (2:ℝ)^(6:ℕ):=by norm_num
_ ≤ _:=pow_le_pow_right₀ (by norm_num) (byhave:= ho.1.1; omega)
have hp := mass1 p.e s.d; unfold massB at hp
nlinarith
havehx0:u.tally s Wtrue=v/D:=by
simp only [v,D,W,u,collect,Meld.tally,S,Oven.labels,ite_true,sum_div]
rw [hx0]
simp only [u,collect,Coin.mul0,Coin.inv0,scalen ho,← div_eq_mul_inv,one_mul]
change |x.v*D/B - v/B| ≤ |x.v-v/D| +_
apply le_trans _ (le_add_of_nonneg_right (abs_nonneg _))
havehx1:x.v*D/B-v/B=(x.v-v/D)* (D/B):=by field_simp
rw [hx1,abs_mul,abs_of_nonneg (bypositivity : 0≤D/B)]
apply mul_le_of_le_one_right (abs_nonneg _)
apply (div_le_one hB).2have hz0:=mass1 p.e s.d; nlinarith
exact ⟨_,u.stream s he hl⟩
| .solo ..=> powder 100
| .use ..=>c
| .duet _ x y _=> operate (Doop.fast (weight x) (weight y)) (weight x) (weight y)
(max (cost x c) (cost y c))
| .heap b p f=>if b then powder (Oven.price (p.foldC (cost f c))) else
powder (Survey.priceB (cost f c+p.e+100))
have hp (i:ℕ): 1≤ powder i:=by unfold powder; omega
cases p with
| solo=> exact hp _
| use=> exact hc
| duet=> exact hp _
| heap b=> cases b <;> exact hp _
noncomputabledefchoir (s:Knob) (p:Lyric):Cog:=match p with
body · 9
lines
| .solo i f=>Brick.solo s f i
| .use _ f=>f
| .duet p x y o=>let i:=weight x
let j:=weight y
(p.ration.uPair s i j o (Doop.fast i j) (choir s x) (choir s y)).cooked
| .heap b p f=>let q:=choir s f
if b then (p.collect q s (weight f)).cooked else (p.bowl q).poll
| byear {s r f V} :
Ears s c T r f V→Lethe p c T s (.use r f) V
| played {s i f}(h:Align s p)(e:Live s p T)
(hb: |(f.f s.l.x (s.info,s.src)).v| ≤ massB i s.d):
Lethe p c T s (.solo i f) (f.f s.l.x (s.info,s.src)).v
| doo {s i j AB u o} (h:Align s p)
(ha:Lethe p c T s i A) (hb:Lethe p c T s j B) (hr:|u.val AB| ≤ massB o s.d):
Lethe p c T s (.duet u i j o) (u.val AB)
| little {s q f V b} (h:Align s p)
(he:q.n.f s.l.x s.info<(2:ℕ)^(q.e*s.d)) (hg:∀ i∈q.S s,Lethe p c T (q.port s i) f (V i)):
Lethe p c T s (.heap b q f) (if b then∑ i∈q.S s,V i else rank (q.S s) V (q.key s))
theoremsong {p c T s f V} (hc:1≤ c) (h:Lethe p c T s f V){H:ℕ}(he:H+f.tail*s.d ≤T):
Ears s (f.cost c) H f.weight (choir p f) V:=by
proof · 33
lines
induction h generalizing Hwith
| @byear s i q v h=> apply supply h hc le_rfl; exact (Nat.le_add_right ..).trans he
| @played s i f h hl hb=>havehp:H≤T:=(Nat.le_add_right ..).trans he
exact ⟨_, Brick.each0 p f i s H h ((Nat.pow_le_pow_right Nat.zero_lt_two hp).trans hl) rfl hb⟩
| @doo s i j AB u o h h1 h2 h3 ia ib=>let z:=pulse i.weight j.weight
let v:=H+z*s.d
let k:=max (i.cost c) (j.cost c)
havehp:v+max (tail i) (tail j)*s.d ≤T:=by
change H+(z+max i.tail j.tail)*s.d ≤T at he
unfold v; rwa [add_mul,← add_assoc] at he
havehi : v+(tail i)*s.d ≤T:=by
apply le_trans _ hp
gcongr; exact le_max_left ..
havehj : v+(tail j)*s.d ≤T:=by
apply le_trans _ hp
gcongr; exact le_max_right ..
apply Bid.joint u.ration h (u.legit ..) ((cost_hi (p:=i) hc).trans (le_max_left ..)) _ _ h3
· exact supply (ia hi) (cost_hi hc) (le_max_left ..) le_rfl
exact supply (ib hj) (cost_hi hc) (le_max_right ..) le_rfl
| @little s q f V b h hz hf ih=>let i:= f.weight
let w:=choir p f
havehp:q.Trust s i V (f.cost c) (H+(if b then q.reserve else0)*s.d) w:=by
refine ⟨hz,fun j hj=>ih j hj ?_⟩
unfold tail at he; dsimp only [Branch.port]; rwa [add_mul,← add_assoc] at he
cases b
· simp only [choir,cost,weight,Bool.false_eq_true,ite_false]
simp only [Bool.false_eq_true,ite_false,zero_mul,add_zero] at hp
exact q.lease hp (cost_hi hc) h.1
simp only [choir,cost,weight,ite_true]
exact q.poem hp (cost_hi hc) h
lemmaLethe.bnd {p c T s f V}(h:Lethe p c T s f V):
|V| ≤ massB f.weight s.d:=by
proof · 18
lines
induction h with
| byear he=> exact amplitude he
| played _ _ hb=> exact hb
| doo _ _ _ he _ _=> exact he
| @little s q f V b h he hg ih=>letX:=massB f.weight s.d
havehp:0≤X:= (mass0 ..).le
have hi (i:ℕ)(e:i∈q.S s):|V i| ≤X:=ih i e
cases b
· rw [ite_eq_right (by simp),abs_of_nonneg (rank_nn ..)]; exact rank_le hp
(fun i e=>le_trans (le_abs_self _) (hi _ e))
· simp only [weight,ite_true]
refine le_trans (abs_sum_le_sum_abs ..) ?_
apply le_trans (b:=∑ i ∈ q.S s,X) (sum_le_sum hi)
simp only [Branch.S, sum_const,card_range,nsmul_eq_mul]
havehr:(q.n.f s.l.x s.info:ℝ)< massB q.e s.d:=by unfold massB; exact_mod_cast he
rw [mass_mul]
unfold X at *; nlinarith
lemmafixedjoint {s:Port}{k i j o e c H f g VX w b} (h: Align s k) (he:p.Fit e i j) (hc:1≤ c)
(h1:s.Feeds f c (H+(e+i+j+6)*s.d) w (V/massB i s.d))(h2:s.Feeds g c (H+(e+i+j+6)*s.d) b (X/massB j s.d))
(hv:|p.truef VX| ≤ massB o s.d) :
let q:=p.uPair k i j o e f g
proof · 35
lines
s.Feeds q.cooked (powder (Oven.price (joinCost e i j c))) H (q.out s (fun t _=>if t then w else b)) (p.truef VX /massB o s.d):=byhave ha:=amplitude (p:=s) (v:=V) (f:=f) (i:=i) (T:=H+(e+i+j+6)*s.d) (c:=c) ⟨w,h1⟩; have hb:=amplitude (p:=s) (v:=X) (f:=g) (i:=j) (T:=H+(e+i+j+6)*s.d) (c:=c) ⟨b,h2⟩
let d:=s.d; havehd:1≤ s.d:=h.1.1let q:=p.uPair k i j o e f g
letf0:Rill.EV:=fun t _=>if t thenV/massB i d elseX/massB j d
letg0:Rill.DW:=fun t _=>if t then w else b
letC:=joinCost e i j c
havehC:C≥100∧ c ≤C:=by unfold C joinCost; omega
havehM : q.P.margin.f s.l.x s.info=(e+i+j+6)*s.d:=by simp [q,uPair,h.2.1]
havehe0:q.P.Thaw s CH g0 f0:=by
refine ⟨hC.1,h.1,?_,?_,?_⟩
· rw [hM]; unfold C joinCost; exact Nat.mul_le_mul_right s.d (by omega)
· intro b; change 1<2^(C*s.d); have hz:=growing (C*s.d); nlinarith
intro b i hi; cases b
· havehu: q.P.scans false=g:=by simp [q,uPair]
rw [hu, Oven.ext,hM]; exact fewer h2 hc hC.2 le_rfl
· havehu:q.P.scans true=f:=by simp [q,uPair]
rw [hu,Oven.ext,hM]; exact fewer h1 hc hC.2 le_rfl
havehl : q.Lip s (massB (e+i+j) s.d) (p.truef VX/massB o s.d) f0:=by
refine ⟨by rw [abs_div,abs_of_pos (mass0 ..)]; exact (div_le_one (mass0 ..)).2 hv,
mass1 ..,?_,fun x y hs hz=>?_⟩
· rw [hM]; let n:=e+i+j
change massB n s.d*4*3≤ massB (n+6) s.d
rw [mass_mul n 6]; havehh : 12≤ massB 6 s.d:=by
unfold massB
calc
(12:ℝ) ≤2^(6:ℕ):=by norm_num
_ ≤ _:=pow_le_pow_right₀ (by norm_num) (by omega)
have hp:=mass0 n s.d; rw [mul_assoc]; exact mul_le_mul_of_nonneg_left (by linarith) hp.le
· havehx:q.tally s f0 true=V/massB i s.d:=by simp [q,Meld.tally,Oven.labels,uPair,f0,d]
haveht:q.tally s f0 false=X/massB j s.d:=by simp [q,Meld.tally,Oven.labels,uPair,f0,d]
rw [hx] at hs; rw [ht] at hz; rw [hx,ht]
simp only [q,uPair,remote,Coin.mul0,Coin.inv0,he.goodC,scalen h,← div_eq_mul_inv]
exact behold _ hd _ _ _ _ he ha hb hs hz
exact q.stream s he0 hl
lemmaleased {s:Port}{VH c i f w}(h:p.Faith s i V c H f w)(hc:1≤ c)(ho:s.OK):
s.Feeds (p.bowl f).poll (powder (Survey.priceB (c+p.e+100))) H
(fun t=> (rankN (p.S s) (fun j=>(w j t).toNat) (p.key s):ℤ)) ((rank (p.S s) V (p.key s))/massB i s.d):=by
proof · 12
lines
classical
let u:=p.bowl f
letW:=fun (j:ℕ)=>V j/massB i s.d
havehz : u.Clue s (c+p.e+100) HW w:=by
refine ⟨by omega,ho,?_ ,fun j hj=>fewer (h.tick j (mem_range.2 hj)) hc (by omega) le_rfl⟩
apply h.cheaply.trans_le (Nat.pow_le_pow_right Nat.zero_lt_two ?_)
gcongr; omega
let v:=massB i s.d
havehs:rank (p.S s) W (p.key s)=rank (p.S s) V (p.key s)/v:=byhavehm:W=(fun j=>v⁻¹*V j):=funext fun _=>by unfold v W; ring
rw [hm,scaled_rank (by unfold v; positivity)]; ring
rw [← hs]; exact hz.tasked
| edit f=> edit (stampT q f)
| toss p e=> toss (stampT q p) (outerQ q e)
| seq a b=> seq (ren a) (ren b)
| Cog.bif p a b=>Cog.bif (stampT q p) (ren a) (ren b)
| loop p a=> loop (stampT q p) (ren a)
lemmaMane.rise {l c q w t p d a b}(h:Mane l c ⟨w,t⟩ d q p a b){H}(he:t≤H):
Mane l c ⟨w,H⟩ d q p a b:=by
proof · 13
lines
have h1(i j k:ℕ):span c k t i j → span c k H i j:=fun e=>
le_trans e (Nat.add_le_add_right (Nat.mul_le_mul_left c he) _)
have hh(a)(e:l.state c ⟨w,t⟩ a):l.state c ⟨w,H⟩ a:=⟨e.1,h1 _ _ _ e.2⟩
have hg(a q:ℕ)(e:l.jump c ⟨w,t⟩ d a q):l.jump c ⟨w,H⟩ d a q:=⟨e.1,h1 _ _ _ e.2⟩
induction h
· exact .edit (by assumption) (hh _ ‹_›) (hh _ ‹_›)
· rename_i he hf hk hl he0 ho
exact .toss he hf (hh _ hk) (hh _ hl) (hg _ _ he0) ho
· exact .seq (by assumption) (by assumption)
· exact .yes (by assumption) (by assumption)
· exact .no (by assumption) (by assumption)
· exact .more (by assumption) (by assumption) (by assumption)
· exact .stop (by assumption) (hh _ ‹_›)
lemmaabsorb {c t d W :ℕ} (h:1≤c)(hp:t≤c*d)(_:1≤W)(hz:d≤W)
{j k}(h1:span c W t j k):
span (4*c) W0 j k:=by
proof · 3
lines
havehs : t ≤ c*W:= le_trans hp (Nat.mul_le_mul_left c hz)
have hl:=lax h1 (m:=1) (D:=4*c) (by omega) h; unfold span
nlinarith [Nat.mul_le_mul_left c hs]
lemmaaboard {p:Port} {c v t q} {f:CubHistoryℕ}
(hp:p.OK)(ht:1≤c)(hz:Punct p c v)
{u:Site}(he:(transit f p v).comp t c q (p.s 0) u):
p.comp t (4*c) (encase f q) (p.s v) (hold v u):=by
proof · 6
lines
have h1:=punctspan hz ht (t:=t)
havehc : p.comp t (4*c) (Cog.focus ⟨_,mintK f⟩ q)
(hold v (p.s 0)) (hold v u) :=by
refine Cog.focus_word _ he ?_ h1 hp.2.1 (by omega) ht ht
simp [mint,transit,postcard]
exact .seq (etches _ _ (i:=v) rfl (plight (punct_up hz (by omega)) hp (by omega)) hc.spots.1) hc
lemmaflavor {p:Port}{c b q g f i t v} (_:p.OK) (h:only0 p c q (p.s 0) (p.s b))
(ha:b=0→Ears p c t i g v)(hb:b≠0→Ears p c t i f v):
Ears p c t i (choose q g f) v:=by
proof · 11
lines
by_cases hh:b=0
· obtain ⟨w,hr,hw⟩:=ha hh
refine ⟨w,hr,⟨fun k hk=>?_⟩⟩
have ht:=hw.digits _ hk; have hg:=expands h (t:=k)
refine .seq hg (.yes (show decide (b=0)=trueby simp [hh]) (.seq ?_ ht))
exact etches _ _ (i:=b) rfl hg.spots.2 ht.spots.1
obtain ⟨w,hr,hw⟩:=hb hh
refine ⟨w,hr,⟨fun k hk=>?_⟩⟩
have ht:=hw.digits _ hk; have hg:=expands h (t:=k)
refine .seq hg (.no (show decide (b=0)=falseby simp [hh]) (.seq ?_ ht))
exact etches _ _ (i:=b) rfl hg.spots.2 ht.spots.1
lemmarestores {p:Port}{c b q g C i t v}
(hp:p.OK) (hb:Punct p c b)(hc:1≤ c)(h:only0 p c q (p.s 0) (p.s b))
(ha:Ears (transit C p b) c t i g v) :
Ears p (4*c) t i (combine q g C) v:=by
proof · 8
lines
obtain ⟨w,ht,h0⟩:=ha
refine ⟨w,ht,⟨fun k hk=>?_⟩⟩
have hz:=h0.digits k hk
have he:=aboard hp hc hb hz
have hu := (expands (t:=k) h).mono (D:=4*c) (by omega) hc
refine .seq hu (.seq he ?_)
exact etches _ _ (i:=((b,enc (dsign w k)):History)) rfl he.spots.2
(hz.mono (c:=c) (D:=4*c) (by omega) hc).spots.2
lemmaround {p:Port}{t c u:ℕ} (h:p.OK)(ht:2≤ c)(v x:ℕ→ℕ)(he:v 0=u) (hn:Punct p c (r.n0 p))
(hs:∀ i≤r.n0 p,Punct p c (v i))
(hh:∀ i<r.n0 p,r.poster p i (v i) (x i)=v (i+1) ∧
(Cargo.transit r.recipe p (enc (i,v i))).comp t c r.prog (p.s 0) (p.s (x i))):
p.comp t (16*c) r.walk0 (p.s u) (p.s (v (r.n0 p))) :=by
proof · 30
lines
let pay:=16*c
havehc:1≤c:=by omega
havehu :c≤pay:=by unfold pay; omega
let z:=r.n0 p
have hz(i:ℕ)(hi:i≤z):Punct p (4*c) (enc (i,v i)):=holdroom h
(by unfold Punct; exact le_trans (Nat.add_le_add_right (lb_mono hi) _) hn) (hs i hi)
have hx(i:ℕ)(hi:i≤z):p.l.state pay ⟨p.w,t⟩ (p.s (enc (i,v i))):=
plight (punct_up (hz i hi) (by unfold pay; omega)) h (by omega)
have hk (i:ℕ)(hi:i≤z):p.comp t pay r.solve (p.s (enc (i,v i))) (p.s (enc (z,v z))) :=byhave hd(i:ℕ) : (gear _ r.condK).f p.l.x (postcard p.info t,
Pause (i,v i) p.src)=decide (i<z):=by
rw [gear_at]; simp [postcard,z,cond0,n0]
induction hi usingNat.decreasingInduction with
| self=> exact .stop (by exact (hd _).trans (by simp)) (hx z le_rfl)
| of_succ i hi ih=>
obtain ⟨hj,hp⟩:=hh i hi
have hA:=Cargo.aboard h (byomega:1≤4*c) (hz i hi.le)
(hp.mono (D:=4*c) (by omega) hc)
rw [show4*(4*c)=pay by unfold pay; omega] at hA
apply Lot.Mane.more ((hd _).trans (by simp [hi]))
(Lot.Mane.seq hA ?_) ih
exact etches _ _ (i:=((enc (i,v i),x i):ℕ×ℕ)) (by simp [work0,postcard]; exact hj)
hA.spots.2 (hx _ hi)
haveh0: v 0=u:=he
have hf:=hk 0 (Nat.zero_le _)
subst u
refine .seq (etches _ _ (i:=v 0) rfl ?_ hf.spots.1)
(.seq hf (etches _ _ (i:=(z,v z)) rfl hf.spots.2 ?_))
· exact plight (punct_up (hs 0 (Nat.zero_le _)) hu) h (by omega)
exact plight (punct_up (hs z le_rfl) hu) h (by omega)
lemmaquery {s c t V w} (h:Align s p.k)(hc:1≤ c)(ht:t=p.m*s.d)
(hp:s.Feeds p.p c t w (V/massB p.i s.d))
{j:ℕ}(hk:Punct s c j)
(he:j=p.test.f s.l.x (s.info, Coin.mult (scaleC p.k p.i s.l.x s.info) (Coin.place (w t) (2^t)))) :
Cargo.only0 s (p.tariff c) p.check (s.s 0) (s.s j):=by
proof · 29
lines
let u:=p.one
let c1:=p.tariffStart c
haveh1:100≤ c1∧c ≤ c1:=by unfold c1 tariffStart; omega
havehw:s.OK:=h.1havehe1 : (p.one).Thaw s c1 t (fun b i=>w) (fun b i=> (V/massB p.i s.d)):=by
refine ⟨h1.1,h.1,by change 0≤ _; omega,fun b=>?_,fun b i hi=>?_⟩
· havehh : (p.one).labels s b ≤1:=by cases b <;>exact (by simp [one,Oven.labels])
have hz:=growing (c1*s.d)
apply lt_of_le_of_lt hh; have:=hw.1; nlinarith
exact fewer hp hc h1.2 le_rfl
have hs := he1.finds le_rfl rfl
letv:Comb:=(t+1,2^(t+1),0,w t,0)
havehf : s.comp t (Oven.price c1) p.one.astir (s.s 0) (Pause v s.src):=by
convert hs using1
rw [p.one.finished]
simp [v,one,Oven.labels,Oven.ext]
havehz: 1≤Oven.price c1∧ c ≤Oven.price c1 ∧ p.m ≤Oven.price c1:=by
unfold c1 Oven.price Oven.bill tariffStart; omega
havehe0: Cargo.only0 s (p.tariff c) (Cog.ren ⟨_,p.dispatchK⟩ p.one.astir)
(s.s 0) (Pause v s.src):=by
apply Lot.Mane.pause (t:=t) _ hz.1 h.1.1 h.1.2.1 (ht ▸ Nat.mul_le_mul_right _ hz.2.2)
exact Cog.renameR _ hf (by simp [dispatch,postcard,h.2.1,ht])
apply Lot.Mane.seq he0
refine etches _ _ (i:=v) ?_ he0.spots.2
(plight (v:=j) (punct_up hk ?_) h.1 ?_)
· havehu:2^(t+1)/2=(2:ℕ)^t:=by rw [pow_succ]; omega
simp [v,valuep,postcard,he,hu,cell]
· unfold tariff; change c ≤4*Oven.price c1; omega
· unfold tariff; change 1≤4*Oven.price c1; omega
lemmalocated {s p i c H f V} (h: full s p V i c H f):∃ w,∀ x,s.pass0 x→ p.Faith (s.seat x) i V c H f w:=by
proof · 8
lines
classical
have he(j):∃ w,∀ x,s.pass0 x →∀e:j∈s.freq p,
((s.bench p j).seat x).Feeds f c H w (V j/massB i s.d):=byby_cases hi:j∈s.freq p
· obtain ⟨w,h1⟩:=h.2 j hi; exact ⟨w,fun x hx _=> h1 x hx⟩
exact ⟨fun _=>0,fun _ _ hz=> (hi hz).elim⟩
choose w hw using he
exact ⟨w,fun x hx=>⟨h.1,fun j e=>hw j x hx e⟩⟩
lemmaleasedD {s p i c H f V} (h:full s p V i c H f) (hc:1≤c)(he:hasOK s):
s.band (powder (Survey.priceB (c+p.e+100))) H i (p.bowl f).poll (rank (s.freq p) V (p.key s.head)):=by
proof · 3
lines
obtain ⟨w,h⟩:=located h
exact ⟨fun t=> rankN (s.freq p) (fun j=>(w j t).toNat) (p.key s.head), fun x hx=>
p.leased (h x hx) hc (he x hx)⟩
lemmarhymeD {s:Seats}{p i c H f V k} (h:s.full p V i c (H+p.reserve*s.d) f) (hc:1≤c)(he:stable s k):
s.band (powder (Oven.price (p.foldC c))) H (i+p.e) ((p.collect f k i).cooked) (∑ j∈s.freq p,V j):=by
proof · 2
lines
obtain ⟨w,h⟩:=located h
exact ⟨(p.collect f k i).out s.head (fun _ j=>w j),fun x hx=> p.poems (h x hx) hc (he x hx)⟩
lemmaduetD (p:Bid){s:Seats}{k i j o e c H f g VX} (h:stable s k)(he:p.Fit e i j)(hc:1≤ c)
(h1:s.band c (H+(e+i+j+6)*s.d) i f V)(h2:s.band c (H+(e+i+j+6)*s.d) j g X)
(hv:|p.truef VX| ≤ massB o s.d):
s.band (powder (Oven.price (Bid.joinCost e i j c))) H o (p.uPair k i j o e f g).cooked (p.truef VX):=by
proof · 3
lines
obtain ⟨w,h1⟩:=h1; obtain ⟨b,h2⟩:=h2
exact ⟨(p.uPair k i j o e f g).out s.head (fun t _=>if t then w else b),
fun x hx=> p.fixedjoint (h x hx) he hc (h1 x hx) (h2 x hx) hv⟩
lemmaadvises {s:Seats}{c b q g C i t v}
(hp:s.hasOK) (hb:Punct s.head c b)(hc:1≤c)(h:s.rite c q b)
(ha:(berth C s b).band c t i g v):
s.band (4*c) t i (Cargo.combine q g C) v:=by
proof · 10
lines
obtain ⟨w,ha⟩:=ha
refine ⟨w,fun x hx=>?_⟩
obtain ⟨hv,he⟩:=ha x hx
refine ⟨hv,⟨fun k hk=>?_⟩⟩
have hz:=he.digits k hk
have ht:=Cargo.aboard (f:=C) (t:=k) (v:=b) (hp x hx) hc hb hz
have hu := (Cargo.expands (p:=s.seat x) (t:=k) (h x hx)).mono (D:=4*c) (by omega) hc
refine .seq hu (.seq ht ?_)
exact etches _ _ (i:=((b,enc (dsign w k)):History)) rfl ht.spots.2
(hz.mono (c:=c) (D:=4*c) (by omega) hc).spots.2
| byear {s r f V} :
s.band c T r f V→Chor p c T s (.use r f) V
| played {s i f v}(h:stable s p)(e:Live s.head p T)
(hz:∀ x,s.pass0 x→ f.f s.l.x (s.info,x)=v)
(hb: |v.v| ≤ massB i s.d):
Chor p c T s (.solo i f) v.v
| doo {s i j AB u o} (h:stable s p)
(ha:Chor p c T s i A) (hb:Chor p c T s j B) (hr:|u.val AB| ≤ massB o s.d):
Chor p c T s (.duet u i j o) (u.val AB)
| little {s q f V b} (h:stable s p)
(he:q.n.f s.l.x s.info<(2:ℕ)^(q.e*s.d)) (hg:∀ i∈s.freq q,Chor p c T (s.bench q i) f (V i)):
Chor p c T s (.heap b q f) (if b then∑ i∈ s.freq q,V i else rank (s.freq q) V (q.key s.head))
lemmasing {p c T s f V}(h:Chor p c T s f V)(hc:1≤c) {H:ℕ} (he:H+f.tail*s.d≤T):
s.band (f.cost c) H f.weight (choir p f) V:=by
proof · 39
lines
induction h generalizing Hwith
| @byear s i q v h=> apply flex h hc le_rfl; exact (Nat.le_add_right ..).trans he
| @played s i f v h hl hz hb=>
refine ⟨Brick.tapeR p f i s.head,fun x hx=>?_⟩
haveht:Brick.tapeR p f i (s.seat x)=Brick.tapeR p f i s.head:=by
funext j; unfold Brick.tapeR Brick.center
simp only [postcard,dec_round]
change Coin.floor0 (Coin.mult _ (Coin.mult (f.f s.l.x (s.info,x)) _)) =
Coin.floor0 (Coin.mult _ (Coin.mult (f.f s.l.x (s.info,s.head.src)) _))
rw [hz x hx,hz _ s.hm]
rw [← ht]
havehp:H≤T:=(Nat.le_add_right ..).trans he
exact Brick.each0 p f i (s.seat x) H (h x hx) ((Nat.pow_le_pow_right Nat.zero_lt_two hp).trans hl)
(congrArg Coin.v (hz x hx)) hb
| @doo s i j AB u o h h1 h2 h3 ia ib=>let z:=pulse i.weight j.weight
let v:=H+z*s.d
havehp:v+max (tail i) (tail j)*s.d ≤T:=by
change H+(z+max i.tail j.tail)*s.d ≤T at he
unfold v; rwa [add_mul,← add_assoc] at he
havehi : v+(tail i)*s.d ≤T:=by
apply le_trans _ hp
gcongr; exact le_max_left ..
havehj : v+(tail j)*s.d ≤T:=by
apply le_trans _ hp
gcongr; exact le_max_right ..
apply duetD u.ration h (u.legit ..) ((cost_hi (p:=i) hc).trans (le_max_left ..)) _ _ h3
· exact flex (ia hi) (cost_hi hc) (le_max_left ..) le_rfl
exact flex (ib hj) (cost_hi hc) (le_max_right ..) le_rfl
| @little s q f V b h hz hf ih=>havehp:s.full q V f.weight (f.cost c) (H+(if b then q.reserve else0)*s.d) (choir p f):=by
refine ⟨hz,fun j hj=>ih j hj ?_⟩
unfold tail at he; rwa [add_mul,← add_assoc] at he
cases b
· simp only [choir,cost,weight,Bool.false_eq_true,ite_false]
simp only [Bool.false_eq_true,ite_false,zero_mul,add_zero] at hp
exact leasedD hp (cost_hi hc) (rocks h)
simp only [choir,cost,weight,ite_true]
exact rhymeD hp (cost_hi hc) h
lemmaChor.nominal {p c T s f V}(h:Chor p c T s f V):Lethe p c T s.head f V:=by
proof · 8
lines
induction h with
| @byear s r f V h=>
obtain ⟨w,h⟩:=h; exact .byear ⟨w,h _ s.hm⟩
| @played s i f v h e hz hb=>havehu:f.f s.l.x (s.info,s.head.src)=v:=hz _ s.hm
subst v; exact .played (stable_home h) e hb
| doo h _ _ hi ih ik=> exact .doo (stable_home h) ih ik hi
| little h he _ hi=> exact .little (stable_home h) he hi
lemmapointed0 {s c v k} (hp:hasOK s) (he:2≤ c)(ht:Punct s.head c v)(hz:Punct s.head c k):
s.hear 0 c (etch (α:=ℕ) (fun _ _=>k) (Kn.fix _)) v k:=fun x hx=>
proof · 1
line
etches _ _ (i:=v) rfl (plight ht (hp x hx) (by omega)) (plight hz (hp x hx) (by omega))
lemmatransportD (P:Cubℕℕ){s:Seats}{T i f c x v}(e:P.f s.l.x s.info=v)
(h:band (panelx s v) c T i f x):s.band c T i (transformed P f) x:=by
proof · 4
lines
obtain ⟨w,h⟩:=h
have hh(t:ℕ)(ht:t ≤T):hear (panelx s v) t c f 0 (enc (dsign w t)):=fun z hz=>(h z hz).2.digits t ht
exact ⟨w,fun z hz=> ⟨(h z hz).1,⟨fun t ht=>importD P e (hh t ht) z hz⟩⟩⟩
Pick the zero-based kth nonzero answer; the pair of index and answer is positive, or 0 if none.
lemmaheightp (v k i):(relief v k i).1 = (part v i).card:=by
proof · 9
lines
induction i with
| zero=>simp [relief,part]
| succ i ih=>havehh : part v (i+1) = if v i ≠0then insert i (part v i) else part v i:=by
unfold part; rw [range_add_one,filter_insert]
by_cases he:v i=0
· simp [relief,transfer,he,ih,hh]
havehm:i ∉ part v i:=by simp [part]
simp [relief,transfer,he,ih,hh,hm]
lemmaorder {v:ℕ→ℕ}{k i j:ℕ}(hi:i<j) (he:v i≠0)(ht:(part v i).card=k):
(relief v k j).2=bin i (v i):=by
proof · 6
lines
induction hi with
| refl=> simp only [relief,transfer,ite_eq_right he,heightp,ht,ite_true]
| @step j hi ih=>havehh : (relief v k j).1≠ k:=by rw [heightp,← ht]; exact ne_of_gt (ticket hi he)
simp only [relief,transfer,hh,ite_false]
split <;> exact ih
lemmafound_min {v:ℕ→ℕ}{k j:ℕ} (ht:k < (part v j).card):
∃ i∈part v j, (part v i).card=k:=by
proof · 12
lines
induction j with
| zero=>simp [part] at ht
| succ j ih=>by_cases he:k < (part v j).card
· obtain ⟨i,h,e⟩:=ih he; exact ⟨i,catalogs (by omega) h,e⟩
rw [←heightp v k] at he ht
rw [relief,transfer] at ht
split at ht
· contradiction
next h=>
refine ⟨j,by simp [part,h],?_⟩
dsimp only at ht; simp_rw [heightp] at ht he; omega
abbrevgrainK {α} [Wire α] {p g f:PT α ℕ} {q:PT α SeqN}
(hp:Kn p)(hg:Kn g)(hf:Kn f)(hq:Kn q): Kn (fun x a=> transfer (p x a) (g x a) (f x a) (q x a)):=by
body · 4
lines
have hi:=Kn.wash (α:=SeqN)
havehh:Kn (fun x a=>if (q x a).1=p x a then bin (g x a) (f x a) else (q x a).2):=by simpa only [decide_eq_true_eq] using ((hq.left.eq hp).cond (hi.comp (hg.tuple hf)) hq.right)
simpa only [transfer,decide_eq_true_eq] using ((hf.eq (Kn.fix 0)).cond hq (hq.left.succ.tuple hh))
lemmaearns {c}{p:Seats} (h:p.hasOK)(hc:2≤ c)(v:ℕ→ℕ)
(he:Punct p.head c (s.N p))
(hp:∀ i<s.N p,Punct p.head c (v i) ∧ (p.bench s.b i).rite c s.mask (v i)):
let z:=(relief v (s.b.key p.head) (s.N p)).2
proof · 31
lines
Punct p.head (4*c) z ∧ p.rite (16*(16*c)) s.latch z:=bylet k:=s.b.key p.head; let m:=s.N p; let w:= relief v k
have ha:= has_home h
have hk(i)(hi:i ≤ m) : Punct p.head c i:=by
unfold Punct; exact le_trans (Nat.add_le_add_right (lb_mono hi) _) he
have hw(i)(hi:i ≤ m) : Punct p.head (4*c) (w i).2:=by
rcases casebook v k i with hh|⟨j,h1,-,hg⟩
· change (w i).2=0 at hh; rw [hh]; exact punct0 ha (by omega)
change (w i).2=bin j _ at hg; rw [hg]; have he:=lt_of_lt_of_le (mem_range.1 (mem_filter.1 h1).1) hi
exact holdroom ha (hk j he.le) (hp j he).1have hh (i)(hi:i ≤ m): Punct p.head (16*c) (enc (w i)):=byhaveht : (w i).1≤ m:=by change (relief v k i).1≤ m; rw [heightp]; exact (countle ..).trans hi
have he:= holdroom ha (punct_up (hk _ ht) (show c ≤4*c by omega)) (hw i hi)
convert he using1 ; grind
dsimp only; refine ⟨hw m le_rfl,fun x hx=>?_⟩
have hz:=h x hx
have hr:=s.tent.round (t:=0) (p:=p.seat x) hz (byomega:2≤16*c) (fun i=>enc (w i)) v rfl
(vscale he) (fun i hi=>hh i hi) (show∀ i < s.tent.n0 (p.seat x),
_ fromfun i hi=>byhavehn:i < m:=hi
have hs:= ((hp i hn).2 x hx).mono (D:=16*c) (by omega) (by omega)
constructor
· unfold Camp.poster tent fill; simp only [dec_round]; rfl
convert hs using1 <;> simp [Cargo.transit,tent,road,seat,Branch.port])
unfold Port.comp at *
refine .seq (etches _ _ (i:=0) rfl ?_ hr.spots.1) (.seq hr
(etches _ _ (i:=w m) rfl hr.spots.2 ?_))
· exact plight (punct0 hz (by omega)) hz (by omega)
exact plight (punct_up (hw m le_rfl) (by omega)) hz (by omega)
where
vscale {c n p}(e:Punct p c n): Punct p (16*c) n:=punct_up e (by omega)