lemmaunique_small {α} {f:PT (α×ℕ) Bool} {x a n} :
tube f x a n=0↔∀ j < n, f x (a,j)=false:=by
proof · 12
lines
induction n with
| zero=> simp [tube,forNat]
| succ n ih=>havehe : (∀ j<n+1,f x (a,j)=false) ↔ f x (a,n)=false∧ (∀ j<n,f x (a,j)=false) :=by
constructor
· exact fun h=>⟨h n (by omega),fun i he=> h i (by omega)⟩
intro h i hi
rcases Nat.eq_or_lt_of_le (Nat.le_of_lt_succ hi) with he|he
· simpa [he] using h.1
· exact h.2 i he
rw [he]; change (if f x (a,n) then n+1else _)=0↔ _
cases h:f x (a,n) <;> simp [← ih,tube]
lemmauniquely {α} {f:PT (α×ℕ) Bool} {x a n i}
(h:tube f x a n=i+1) : i < n ∧ f x (a,i)=true:=by
proof · 8
lines
induction n with
| zero=> simp [tube,forNat] at h
| succ n ih=>
change (if f x (a,n) then n+1else tube f x a n)=i+1 at h
split at h
· havehe:i=n:=by omega
subst i; exact ⟨by omega,by assumption⟩
obtain ⟨ht,hh⟩:=ih h; exact ⟨by omega,hh⟩
lemmatubeK {α} [Wire α] {f:PT (α×ℕ) Bool}{n:PT α ℕ}(h:Kn f)(he:Kn n):
Kn (fun x a=>tube f x a (n x a)):=
proof · 3
lines
Kn.stroll (fun x (b:α×ℕ×ℕ)=>if f x (b.1,b.2.1) then b.2.1+1else b.2.2)
n (fun _ _=>0) n ((h.comp (Kn.first.tuple Kn.next.left)).cond Kn.next.left.succ Kn.next.right)
he (Kn.fix 0) he (fun _ _ _ hv=> le_trans (tube_hi ..) hv)
lemmalast_prime (x n)(h:0<n) : (last x n).Prime∧ n < last x n ∧ last x n≤2*n:=by
proof · 11
lines
obtain ⟨p,hp,ht,hk⟩:=Nat.bertrand n (by omega)
havehl: atp x (n,p)=true:=by rw [atp]; simp [ht,(px_eq ..).2 hp]
unfold last
cases hh:tube atp x n (2*n+1) with
| zero=>have he:=unique_small.1 hh p (by omega); simp_all
| succ i=>have he:=uniquely hh
simp only [Nat.add_sub_cancel]
unfold atp at *; split at he
· exact ⟨(px_eq ..).1 he.2,by assumption,by omega⟩
· grind
lemmaaffine :∃ a b,∀ x,p.w.ceiling (p.B x)=p.linE a b x:=by
proof · 4
lines
let m:=p.w.p.Mlet g:=p.w.A0
use 8*g+1,8*(4+g*(Net.lag p.w.p)+(1+m)+2)+1+(1+m)
intro x; unfold Wares.ceiling Wares.top Wares.tolls Wares.density linE Net.coreR m g; ring
intro a b h
havehe1 : a.1.val=b.1.val:=by rw [← nr a.1.val,← nr b.1.val, show ncard a.1.val=ncard b.1.val from
congrArg Prod.fst h]
exact Prod.ext (Subtype.ext he1) (by rw [← nr a.2,← nr b.2,show ncard a.2=ncard b.2from congrArg Prod.snd h])
lemmaonK {f:PT α Stamp}{g:PT α ℕ}(h:Kn f)(k:Kn g):
Kn (fun x a=>decide (on (f x a) (g x a))):=by
proof · 10
lines
let t:=h.left
havehe:Kn (fun x a=> decide ((f x a).1≠0)):=by
convert bneg _ ((Kn.wash.comp h.left).eq (Kn.fix (enc (0:Page)))) using1
ext x a; rw [Bool.eq_iff_iff]; simp; exact ⟨fun e h=>e (by
simpa using congrArg (fun n=>(dec n:Page)) h), fun e h=>e (by rw [h])⟩
convert both (bytesK h.left k) (both he (bytesK h.right k)) using1
ext x a
rw [Bool.eq_iff_iff]
simp only [decide_eq_true_eq, Bool.and_eq_true]
rfl
lemmapubK {f g:PT α ℕ}(h:Kn f)(k:Kn g):
Kn (fun x a=>publish (f x a) (g x a)):=by
proof · 7
lines
have he:=(Kn.unpack (α:=Issue)).comp k
have hz:=both (onK he.left h) (both (onK he.right.left h) (onK he.right.right h))
convert both hz ((Kn.wash.comp he).eq k) using1
ext x a
rw [Bool.eq_iff_iff]
simp only [publish, decide_eq_true_eq, Bool.and_eq_true]
rfl
lemmaasideK (h:Kn x ) (e:Kn k):Kn (fun w a=>side (x w a ) (k w a)):=by
proof · 5
lines
convert (((h.pred.div (Kn.cap h.succ (Kn.fix 2) e)).succ)) using1
ext w a; unfold side
by_cases he :2^(k w a) ≤ x w a+1
· rw [min_eq_right he]
rw [min_eq_left (by omega),Nat.div_eq_of_lt (by omega),Nat.div_eq_of_lt (by omega)]
lemmashootK(hr:Kn p ) (ht:Kn k ) (h:Kn x){f:PT α Stamp}(e:Kn f):
Kn (fun w a=>shoot (p w a ) (k w a ) (x w a ) (f w a)):=bytesK (mixK hr h e.right e.left) (asideK hr ht)
let z:=p.matter0 x
have he (n): z.s.H.child z.x0 n=p.w.p.M^n*p.P.first x:=by
induction n with
| zero=> change p.P.first x=_; simp
| succ n ih=> rw [Prize.child,ih]
unfold radix; change _+p.w.p.M*_=_
ring
exact (he _).symm
lemmanumbers (x) (f:ℕ→ℕ):
(↑(∑ i∈range (Print.pages (p.n x)),if p.qualify x i then f i else0):ℝ)=
∑ s∈ univ.filter (funs:Pool (p.n x)=> (p.matter0 x).polls s),(f (p.printid x s):ℝ) :=by
proof · 19
lines
classical
let n:=p.n x
let : Fact n.Prime:=p.primed x
letF i:= (↑(if p.qualify x i then f i else0):ℝ)
push_cast
calc
_ = ∑ i∈Print.spine n,F i :=by
rw [Print.spine,sum_filter]
refine sum_congr rfl fun i _=> ?_
unfold F qualify
by_cases h: Print.publish (p.n x) i=true
· simp [h,n]
simp [h,n]
_ = _:=by
rw [Print.columns (n:=n),sum_filter]
refine sum_congr rfl fun i hi=>?_
unfold F
change (↑(if p.qualify x (p.printid x i) then f (p.printid x i) else0):ℝ)=_
split <;> have ht:= p.verified x i <;> grind
lemmatotalK (f:PTℕℕ)(h:Kn f){α}[Wire α]: Kn (fun x (_:α)=> p.sumtop x (f x)):=by
proof · 16
lines
letg:PT (α ×ℕ×ℕ) ℕ:=fun x a=> a.2.2+
(if p.qualify x a.2.1then min 64 (f x a.2.1) else0)
havehg:Kn g:=Kn.next.right.add ((p.qualifyK.comp Kn.next.left).cond
((Kn.fix _).small (h.comp Kn.next.left)) (Kn.fix _))
have hp (x a j):forNat (fun k v=>g x (a,k,v)) 0 j=
∑ i∈range j, (if p.qualify x i then min 64 (f x i) else0):=by
induction j with
| zero=> simp [forNat]
| succ i ih=> rw [sum_range_succ,← ih]; rfl
haveht:Kn (fun x (_:α)=>Print.pages (p.n x)):=Print.pagesK p.nKn
simpa only [hp,sumtop] usingKn.stroll g _ (fun _ _=>0) _ hg ht (Kn.fix 0) (ht.times (Kn.fix 64)) (by
intro x a B he
rw [hp]
apply le_trans (b:=∑ i∈range B,(64:ℕ))
· exact sum_le_sum (fun i hi=>by split <;> omega)
· simpa usingNat.mul_le_mul_right 64 he)
constructor <;> intro h
· havehp:(↑t:ℝ)≤ ↑((1:ℚ)/3):=Rat.cast_le.mpr h
push_cast at hp; exact hp
havehp:(↑((2:ℚ)/3):ℝ) ≤ (t:ℝ):=Rat.cast_le.mpr h
push_cast at hp; exact hp
lemmareducePol_any (b g) (t: Z4) : reduceV m (pol b g t)=pol b g (reduceV m t) :=by
proof · 11
lines
cases b
· unfold pol; split
all_goals
unfold reduceV lower vmap
cases he:g.2with
| inl u=>
cases u with
| inl b=> rcases b with ⟨a,b⟩; cases a <;> simp
| inr b=>cases b <;> simp
| inr u=> rcases u with ⟨a,b⟩; cases a <;> cases b <;> simp
· exact reducePol g t
lemmazoom (g k w ) (s:Channel n):
walkstep n g k w (badge s)=badge (Variant k g w s):=by
proof · 4
lines
let a:=s.1.val; let b:=s.2havehe:change1 n g (ncard b) k w=ncard (act true g b+reduceV n (addin (side n k) w)):=by
rw [change1,redCast,reduce_add,readout,reducePol,reraise,act_formula]
exact Prod.ext (prints_any a false g) he
lemmafetching (k i:ℕ ) (g ) (s:Channel n):
fetch n k i g (badge s)=guessP k g (closeP k (↑i:ZMod n) s):=by
proof · 6
lines
let v:=vEval s (↑i:ZMod n)
havehe:mix n i (badge s).2 (badge s).1=ncard v:=(nadd ..).symm
rw [fetch,he]
haveht: reducep (ncard v) (side n k)=ncard (vshort k v):=by
simp only [reducep,ncard,vshort,vmap,ZMod.val_natCast]
rw [ht,readout]; rfl
lemmadropK {x:PT α ℤ} {m:PT α ℕ}(h:Kn x ) (e:Kn m):Kn (fun w a=> x w a/(m w a:ℕ)):=by
proof · 4
lines
convert e.cond_eq (Kn.fix 0) (Kn.fix 0) (h.chop e.pred) using1
ext w a; split
· next hz=> simp [show m w a=0from hz]
next hz=> simp [Nat.sub_add_cancel (show1≤ m w a by omega)]
lemmapickK {f:PT α Z4}(h:Kn f) {m:PT α ℕ}(e:Kn m):
Kn (fun w a=> vmap (funi:Fin11=>i.val) (guess (m w a ) (f w a))):=by
proof · 4
lines
have hp {s:PT α ℤ}(hs: Kn s):Kn (fun w a=>(chooseOne (m w a) (s w a)).val) :=
(Kn.fix 10).small (((Kn.fix 5).plusZ ((dropK hs e).negZ)).topNat)
exact ((hp h.left.left).tuple (hp h.left.right)).tuple
((hp h.right.left).tuple (hp h.right.right))
lemmafetchK0 {p k z:PT α ℕ}{f:PT α Stamp}(h:Kn f ) (g:Gen ) (hp:Kn p ) (hk:Kn k ) (hz:Kn z):
Kn (fun x a=>vmap (funi:Fin11=>i.val)
(fetch (p x a ) (k x a) (z x a) g (f x a))):=by
proof · 5
lines
have he:= asideK hp hk
let u (x a):=mix (p x a ) (z x a) ((f x a).2) ((f x a).1)
haveht:Kn u:= mixK hp hz h.right h.left
have hv := quads ht _ (Kn.next.mod (he.comp Kn.first))
exact pickK (polK (zdK hv) true g) he
lemmafetchK {p k z:PT α ℕ}{f:PT α Stamp}(h:Kn f ) (g:Gen ) (hp:Kn p ) (hk:Kn k ) (hz:Kn z ) (v):
Kn (fun x a=>decide (fetch (p x a ) (k x a ) (z x a) g (f x a)=v)):=by
proof · 11
lines
let glyph (v:W):=enc (vmap (funi:Fin11=>i.val) v)
havehe : Function.Injective glyph:=by
intro a b hx
have hp:=congrArg (fun n=>(dec n:Page)) hx; unfold glyph at hp
simp [vmap,Prod.ext_iff] at *
exact ⟨⟨Fin.ext hp.1.1,Fin.ext hp.1.2⟩,Fin.ext hp.2.1,Fin.ext hp.2.2⟩
let s x a:=fetch (p x a ) (k x a ) (z x a) g (f x a)
convert (Kn.wash.comp (fetchK0 h g hp hk hz)).eq (Kn.fix (glyph v)) using1
ext x a
change decide (s x a=v)=decide (glyph (s x a)=glyph v)
simp [he.eq_iff]
if v.1.1thenmatch v.1.2with
| .inl i=> (walkstep n i k v.2 s.1,s.2)
| .inr (.inl i)=> (s.1,walkstep n i j v.2 s.2.1,s.2.2)
| .inr (.inr (.inl i))=> (s.1,s.2.1,bare n i s.2.2)
| _=>s
else s
lemmalandlord (v:Token)(k j x y:ℕ)(s:Env n 0):
v.2=winner k j (↑x:ZMod n) (↑y:ZMod n) v.1 s ↔
checkS v n k j x (issued s)=true∧ checkD v n k j y (issued s)=true:=by
proof · 2
lines
rcases s with ⟨s,t,u,w⟩; rcases v with ⟨⟨b,i|i|i|i⟩,v⟩ <;>
cases b <;> simp [issued,winner,checkS,checkD,fetching,eq_comm]
lemmaS_K(v:Token):
Kn (fun (_:Word)(a:Bundle)=>checkS v a.1.1 a.1.2.1 a.1.2.2 a.2.1 a.2.2):=by
proof · 3
lines
rcases v with ⟨⟨b,i|i|i|i⟩,v⟩ <;> cases b
all_goals first| exact Kn.fix _ |
exact fetchK Kn.next.right.left i Kn.first.left Kn.first.right.left Kn.next.left v
lemmaD_K(v:Token):
Kn (fun (_:Word)(a:Bundle)=>checkD v a.1.1 a.1.2.1 a.1.2.2 a.2.1 a.2.2):=by
proof · 2
lines
rcases v with ⟨⟨b,i|i|i|i⟩,v⟩ <;> cases b <;> first| exact Kn.fix _ |
exact fetchK Kn.next.right.right.left i Kn.first.left Kn.first.right.right Kn.next.left v
lemmamintK {α β} [Wire α][Wire β](f:Token→PT α β) (h:∀ v,Kn (f v))
(k:PT α ℕ)(hp:Kn k):Kn (fun x a=> f (mark (k x a)) x a):=by
proof · 26
lines
let u(v:Fin rad):= v.val
letm:Fin rad := ⟨0,rad_pos⟩
classical
have he (s: ℕ):
Kn (fun x a=>let n:= (k x a)%rad
if n < s then f (mark n) x a else f (mark 0) x a):=by
induction s with
| zero=> simpa using h (mark 0)
| succ s ih =>
convert ((hp.mod (Kn.fix rad)).cond_eq (Kn.fix s) (h (mark s)) ih) using1
ext x a
dsimp only
generalize k x a % rad=n
by_cases he:n=s
· subst s
rw [ite_eq_left (by omega),ite_eq_left rfl]
rw [ite_eq_right he]
by_cases ht:n<s
· rw [ite_eq_left (by omega),ite_eq_left ht]
rw [ite_eq_right (by omega),ite_eq_right ht]
have ht (v):v%rad<rad:=Nat.mod_lt v rad_pos
convert he rad using1
ext x a
dsimp only
rw [ite_eq_left (ht _)]
simp only [mark,Nat.mod_mod]
lemmaemblem (v:Token→ℝ):
∑ i ∈ range rad, v (mark i)= ∑i:Token,v i:=by
proof · 4
lines
rw [←Fin.sum_univ_eq_sum_range (fun i => v (mark i))]
exact Fintype.sum_equiv number _ _ (fun i=>byhavehp: mark (i:Fin rad).val=number i := congrArg number (Fin.ext (Nat.mod_eq_of_lt i.isLt))
simp only [hp])
let f (v:Token ) (x:Word ) (a:Guide×MapState):=
tossR b v x (a.1.1,a.1.2,a.2.2.2)
have hp(v):Kn (f v):= (tossed b v).comp (Kn.first.left.tuple
(Kn.first.right.tuple Kn.next.right.right))
have he:=mintK f hp _ Kn.next.left
exact (Kn.next.left.div (Kn.fix rad)).tuple ((both Kn.next.right.left he.left).tuple he.right)
defscoreQ (b:Bool ) (k j x:ℕ) :
{l:ℕ}→PathsAtom l →PathsRoller l→Env n 0→Bool
body · 4
lines
| 0,_,_,_=>true
| _+1,(t,a),(v,w),s=>
(if b then checkS (t,v) n k j x (issued s) else checkD (t,v) n k j x (issued s)) &&
scoreQ b k j x a w (rol k j (d:=0 ) (w:=0) le_rfl t v s)
lemmawellQ (k j x y:ℕ){l:ℕ}(a:PathsAtom l ) (b:PathsRoller l ) (s:Env n 0):
live k j (↑x:ZMod n) (↑y:ZMod n) (d:=0 ) (w:=0) le_rfl a b s=true↔
scoreQ true k j x a b s=true∧ scoreQ false k j y a b s=true:=by
proof · 13
lines
induction l generalizing s with
| zero=> simp [live,scoreQ]
| succ l ih=>
cases a with | mk t a=>
cases b with | mk v b=>
unfold live scoreQ
letu:Token:=(t,v)
have hx:= landlord u k j x y s
dsimp only [u] at hx
simp only [Bool.and_eq_true,ite_true,Bool.false_eq_true,ite_false]
split
· next hz=>have hp:=hx.1 hz; simp [hp,ih]
next hz=> simp; grind
theoremflowed (b:Bool ) (k j i l c:ℕ ) (x:Word ) (s:Env n 0 ) (v:Bool) :
spin b x (((n,k,j),i),(c,v,issued s),l) =
letP:=queue l c
proof · 32
lines
(c/rad^l, v && scoreQ b k j i P.1P.2 s,
issued (go k j (d:=0 ) (w:=0) le_rfl P.1P.2 s)) :=byletq:Guide:=((n,k,j),i)
letp:Lap:=(q,(c,v,issued s),l)
letM:=capz p
let f (z:ℕ):= min M (enc (goon b x (q,dec z)))
have he(l':ℕ ) (c':ℕ ) (hv:c'≤c ) (v':Bool ) (s':Env n 0):
forNat (fun _=> f) (enc ((c',v',issued s'):MapState)) l' =
letP:=queue l' c'
enc ((c'/rad^l',v'&&scoreQ b k j i P.1P.2 s',
issued (go k j (d:=0 ) (w:=0) le_rfl P.1P.2 s')):MapState):=by
induction l' generalizing c' v' s' with
| zero=> simp [forNat,go,scoreQ]
| succ l' ih=>let c0:=c'/rad
haveht:c0≤c:=le_trans (Nat.div_le_self ..) hv
let u:=mark c'
let s0:=rol k j (d:=0 ) (w:=0) le_rfl u.1 u.2 s'
let b0:=v' && (tossR b u x (q.1,q.2,issued s')).1havehh:f (enc ((c',v',issued s'):MapState))=enc ((c0,b0,issued s0):MapState):=by
dsimp only [f]
rw [dec_round]; unfold goon
change min M (enc ((c0,b0,arch u n k j (issued s')):MapState))=_
rw [rose]; exact min_eq_right (limits ht s0 b0 v)
rw [forNat_cons,hh,ih c0 ht]
simp only [c0,b0,q,s0,u, queue, tossR,scoreQ,go,Equiv.trans_apply,Nat.div_div_eq_div_mul,
pow_succ',Bool.and_assoc]
unfold spin
change dec (forNat _ (min M _) _)=_
rw [min_eq_right (limits ..),he l c le_rfl]
· dsimp only; simp only [Wire.eq]
exact le_rfl
lemmastepK {α} [Wire α]{n k j l c :PT α ℕ}{s:PT α Issue}
(hn:Kn n ) (hk:Kn k ) (hj:Kn j ) (hl:Kn l ) (hc:Kn c ) (hs:Kn s):
Kn (fun x a=>stepout (n x a ) (k x a ) (j x a ) (l x a ) (c x a ) (s x a)) :=
lemmatouchedK {α} [Wire α]{n k j i l c:PT α ℕ}{s:PT α Issue}
(b ) (hn:Kn n ) (hk:Kn k ) (hj:Kn j ) (hi:Kn i ) (hl:Kn l ) (hc:Kn c ) (hs:Kn s):
Kn (fun x a=> touched b (n x a ) (k x a ) (j x a ) (i x a ) (l x a ) (c x a ) (s x a)):=
lemmaexactHit (k j x y l a:ℕ ) (s:Env n 0):
live k j (↑x:ZMod n) (↑y:ZMod n) (d:=0 ) (w:=0) le_rfl (queue l a).1 (queue l a).2 s=true↔
touched true n k j x l a (issued s)=true∧ touched false n k j y l a (issued s)=true:=by
proof · 1
line
simp only [touched,flowed, Bool.true_and]; exact wellQ k j x y ..